summaryrefslogtreecommitdiff
path: root/test/stdio
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2015-12-09 08:05:10 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2015-12-17 20:35:19 +0100
commit219b69d72e878094f3ce03a9e70719709a9b4c43 (patch)
treec79c264c6e76d470e88ff57491ba3bf13c8aef46 /test/stdio
parent2e116b2eeea5f47ca26458b1962783baced2784c (diff)
libc/stdio: Rework custom streams interface similar to glibc.
Save 20 bytes per FILE structure, avoid indirect call for read/write/seek/close operations for normal streams. Additionally, custom streams has fileno = -2 now, like in glibc. bloat-o-meter report (UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y): function old new delta fopencookie 69 131 +62 ftello64 233 260 +27 fseeko64 298 319 +21 fclose 423 442 +19 .rodata 16696 16708 +12 fileno_unlocked 53 45 -8 __ns_name_pack 859 851 -8 vswscanf 184 144 -40 vdprintf 231 187 -44 vsscanf 210 151 -59 vswprintf 269 201 -68 vsnprintf 249 181 -68 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/7 up/down: 141/-295) Total: -154 bytes Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
Diffstat (limited to 'test/stdio')
-rw-r--r--test/stdio/Makefile.in4
-rw-r--r--test/stdio/tst-fmemopen.c53
2 files changed, 57 insertions, 0 deletions
diff --git a/test/stdio/Makefile.in b/test/stdio/Makefile.in
index 0bfbd1362..14b5f19b9 100644
--- a/test/stdio/Makefile.in
+++ b/test/stdio/Makefile.in
@@ -2,3 +2,7 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
DODIFF_64bit := 1
+
+ifeq ($(UCLIBC_HAS_GLIBC_CUSTOM_STREAMS),)
+TESTS_DISABLED += tst-fmemopen
+endif
diff --git a/test/stdio/tst-fmemopen.c b/test/stdio/tst-fmemopen.c
new file mode 100644
index 000000000..384faa1c9
--- /dev/null
+++ b/test/stdio/tst-fmemopen.c
@@ -0,0 +1,53 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char *text_input = "1 23 43";
+
+static const char *good_answer = "1 529 1849 ";
+
+
+static int
+do_test (void)
+{
+ FILE *out, *in;
+ int v, s;
+ size_t size;
+ char *ptr;
+
+ in = fmemopen(text_input, strlen(text_input), "r");
+ if (in == NULL) {
+ perror("fmemopen");
+ return 1;
+ }
+
+ out = open_memstream(&ptr, &size);
+ if (out == NULL) {
+ perror("open_memstream");
+ return 1;
+ }
+
+ for (;;) {
+ s = fscanf(in, "%d", &v);
+ if (s <= 0)
+ break;
+
+ s = fprintf(out, "%d ", v * v);
+ if (s == -1) {
+ puts("fprintf failed");
+ exit(1);
+ }
+ }
+ fclose(in);
+ fclose(out);
+
+ if (size != strlen(good_answer) || strcmp(good_answer, ptr) != 0) {
+ printf("failed: size=%zu; ptr=%s\n", size, ptr);
+ exit(1);
+ }
+ free(ptr);
+ exit(0);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"