about summary refs log tree commit diff
path: root/REORG.TODO/libio/tst_wprintf2.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
committerZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
commit5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch)
tree4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/libio/tst_wprintf2.c
parent199fc19d3aaaf57944ef036e15904febe877fc93 (diff)
downloadglibc-zack/build-layout-experiment.tar.gz
glibc-zack/build-layout-experiment.tar.xz
glibc-zack/build-layout-experiment.zip
Prepare for radical source tree reorganization. zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage
directory, REORG.TODO, except for files that will certainly still
exist in their current form at top level when we're done (COPYING,
COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which
are moved to the new directory OldChangeLogs, instead), and the
generated file INSTALL (which is just deleted; in the new order, there
will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/libio/tst_wprintf2.c')
-rw-r--r--REORG.TODO/libio/tst_wprintf2.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/REORG.TODO/libio/tst_wprintf2.c b/REORG.TODO/libio/tst_wprintf2.c
new file mode 100644
index 0000000000..dfff70f1f9
--- /dev/null
+++ b/REORG.TODO/libio/tst_wprintf2.c
@@ -0,0 +1,104 @@
+/* Test case by Yoshito Kawada <KAWADA@jp.ibm.com>.  */
+#include <errno.h>
+#include <error.h>
+#include <fcntl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <wchar.h>
+
+int
+main (int argc, char *argv[])
+{
+  int a = 3;
+  int fd;
+  char name[] = "/tmp/wprintf.out.XXXXXX";
+  FILE *fp;
+  char buf[100];
+  size_t len;
+  int res = 0;
+
+  fd = mkstemp (name);
+  if (fd == -1)
+    error (EXIT_FAILURE, errno, "cannot open temporary file");
+
+  unlink (name);
+
+  setlocale (LC_ALL, "en_US.UTF-8");
+
+  fp = fdopen (dup (fd), "w");
+  if (fp == NULL)
+    error (EXIT_FAILURE, errno, "fdopen(,\"w\")");
+
+  fwprintf (fp, L"test start");
+  fwprintf (fp, L" int %d\n", a);
+
+  /* String with precision.  */
+  fwprintf (fp, L"1[%6.3s]\n", argv[1]);
+
+  fclose (fp);
+
+  fp = fdopen (dup (fd), "a");
+  if (fp == NULL)
+    error (EXIT_FAILURE, errno, "fdopen(,\"a\")");
+
+  setvbuf (fp, NULL, _IONBF, 0);
+
+  /* fwprintf to unbuffered stream.   */
+  fwprintf (fp, L"hello.\n");
+
+  fclose (fp);
+
+
+  /* Now read it back in.  This time using multibyte functions.  */
+  lseek (fd, SEEK_SET, 0);
+  fp = fdopen (fd, "r");
+  if (fp == NULL)
+    error (EXIT_FAILURE, errno, "fdopen(,\"r\")");
+
+  if (fgets (buf, sizeof buf, fp) != buf)
+    error (EXIT_FAILURE, errno, "first fgets");
+  len = strlen (buf);
+  if (buf[len - 1] == '\n')
+    --len;
+  else
+    {
+      puts ("newline missing after first line");
+      res = 1;
+    }
+  printf ("1st line: \"%.*s\" -> %s\n", (int) len, buf,
+	  strncmp (buf, "test start int 3", len) == 0 ? "OK" : "FAIL");
+  res |= strncmp (buf, "test start int 3", len) != 0;
+
+  if (fgets (buf, sizeof buf, fp) != buf)
+    error (EXIT_FAILURE, errno, "second fgets");
+  len = strlen (buf);
+  if (buf[len - 1] == '\n')
+    --len;
+  else
+    {
+      puts ("newline missing after second line");
+      res = 1;
+    }
+  printf ("2nd line: \"%.*s\" -> %s\n", (int) len, buf,
+	  strncmp (buf, "1[   Som]", len) == 0 ? "OK" : "FAIL");
+  res |= strncmp (buf, "1[   Som]", len) != 0;
+
+  if (fgets (buf, sizeof buf, fp) != buf)
+    error (EXIT_FAILURE, errno, "third fgets");
+  len = strlen (buf);
+  if (buf[len - 1] == '\n')
+    --len;
+  else
+    {
+      puts ("newline missing after third line");
+      res = 1;
+    }
+  printf ("3rd line: \"%.*s\" -> %s\n", (int) len, buf,
+	  strncmp (buf, "hello.", len) == 0 ? "OK" : "FAIL");
+  res |= strncmp (buf, "hello.", len) != 0;
+
+  return res;
+}