From 2625ca90abe3246f6d3240d59d32f1843afc9651 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 2 Jul 2007 01:34:46 +0000 Subject: [PATCH] Formatted output functions for Unicode strings. --- ChangeLog | 205 +++++++ MODULES.html.sh | 64 +++ lib/unistdio.h | 258 +++++++++ lib/unistdio/u-asnprintf.h | 29 + lib/unistdio/u-asprintf.h | 29 + lib/unistdio/u-printf-args.c | 24 + lib/unistdio/u-printf-args.h | 29 + lib/unistdio/u-printf-parse.h | 29 + lib/unistdio/u-snprintf.h | 29 + lib/unistdio/u-sprintf.h | 29 + lib/unistdio/u-vasprintf.h | 42 ++ lib/unistdio/u-vsnprintf.h | 59 +++ lib/unistdio/u-vsprintf.h | 65 +++ lib/unistdio/u16-asnprintf.c | 30 ++ lib/unistdio/u16-asprintf.c | 30 ++ lib/unistdio/u16-printf-parse.c | 28 + lib/unistdio/u16-snprintf.c | 30 ++ lib/unistdio/u16-sprintf.c | 30 ++ lib/unistdio/u16-u16-asnprintf.c | 30 ++ lib/unistdio/u16-u16-asprintf.c | 30 ++ lib/unistdio/u16-u16-snprintf.c | 30 ++ lib/unistdio/u16-u16-sprintf.c | 30 ++ lib/unistdio/u16-u16-vasnprintf.c | 51 ++ lib/unistdio/u16-u16-vasprintf.c | 32 ++ lib/unistdio/u16-u16-vsnprintf.c | 35 ++ lib/unistdio/u16-u16-vsprintf.c | 34 ++ lib/unistdio/u16-vasnprintf.c | 52 ++ lib/unistdio/u16-vasprintf.c | 32 ++ lib/unistdio/u16-vsnprintf.c | 35 ++ lib/unistdio/u16-vsprintf.c | 34 ++ lib/unistdio/u32-asnprintf.c | 30 ++ lib/unistdio/u32-asprintf.c | 30 ++ lib/unistdio/u32-printf-parse.c | 28 + lib/unistdio/u32-snprintf.c | 30 ++ lib/unistdio/u32-sprintf.c | 30 ++ lib/unistdio/u32-u32-asnprintf.c | 30 ++ lib/unistdio/u32-u32-asprintf.c | 30 ++ lib/unistdio/u32-u32-snprintf.c | 30 ++ lib/unistdio/u32-u32-sprintf.c | 30 ++ lib/unistdio/u32-u32-vasnprintf.c | 51 ++ lib/unistdio/u32-u32-vasprintf.c | 32 ++ lib/unistdio/u32-u32-vsnprintf.c | 35 ++ lib/unistdio/u32-u32-vsprintf.c | 34 ++ lib/unistdio/u32-vasnprintf.c | 52 ++ lib/unistdio/u32-vasprintf.c | 32 ++ lib/unistdio/u32-vsnprintf.c | 35 ++ lib/unistdio/u32-vsprintf.c | 34 ++ lib/unistdio/u8-asnprintf.c | 30 ++ lib/unistdio/u8-asprintf.c | 30 ++ lib/unistdio/u8-printf-parse.c | 28 + lib/unistdio/u8-snprintf.c | 30 ++ lib/unistdio/u8-sprintf.c | 30 ++ lib/unistdio/u8-u8-asnprintf.c | 30 ++ lib/unistdio/u8-u8-asprintf.c | 30 ++ lib/unistdio/u8-u8-snprintf.c | 30 ++ lib/unistdio/u8-u8-sprintf.c | 30 ++ lib/unistdio/u8-u8-vasnprintf.c | 51 ++ lib/unistdio/u8-u8-vasprintf.c | 32 ++ lib/unistdio/u8-u8-vsnprintf.c | 35 ++ lib/unistdio/u8-u8-vsprintf.c | 34 ++ lib/unistdio/u8-vasnprintf.c | 52 ++ lib/unistdio/u8-vasprintf.c | 32 ++ lib/unistdio/u8-vsnprintf.c | 35 ++ lib/unistdio/u8-vsprintf.c | 34 ++ lib/unistdio/ulc-asnprintf.c | 30 ++ lib/unistdio/ulc-asprintf.c | 30 ++ lib/unistdio/ulc-fprintf.c | 80 +++ lib/unistdio/ulc-printf-parse.c | 29 + lib/unistdio/ulc-snprintf.c | 30 ++ lib/unistdio/ulc-sprintf.c | 30 ++ lib/unistdio/ulc-vasnprintf.c | 48 ++ lib/unistdio/ulc-vasprintf.c | 32 ++ lib/unistdio/ulc-vfprintf.c | 77 +++ lib/unistdio/ulc-vsnprintf.c | 35 ++ lib/unistdio/ulc-vsprintf.c | 34 ++ modules/unistdio/base | 22 + modules/unistdio/u-printf-args | 28 + modules/unistdio/u16-asnprintf | 26 + modules/unistdio/u16-asnprintf-tests | 14 + modules/unistdio/u16-asprintf | 25 + modules/unistdio/u16-printf-parse | 30 ++ modules/unistdio/u16-snprintf | 25 + modules/unistdio/u16-sprintf | 25 + modules/unistdio/u16-u16-asnprintf | 26 + modules/unistdio/u16-u16-asprintf | 25 + modules/unistdio/u16-u16-snprintf | 25 + modules/unistdio/u16-u16-sprintf | 25 + modules/unistdio/u16-u16-vasnprintf | 59 +++ modules/unistdio/u16-u16-vasprintf | 25 + modules/unistdio/u16-u16-vsnprintf | 26 + modules/unistdio/u16-u16-vsprintf | 26 + modules/unistdio/u16-vasnprintf | 59 +++ modules/unistdio/u16-vasnprintf-tests | 31 ++ modules/unistdio/u16-vasprintf | 25 + modules/unistdio/u16-vasprintf-tests | 13 + modules/unistdio/u16-vsnprintf | 26 + modules/unistdio/u16-vsnprintf-tests | 14 + modules/unistdio/u16-vsprintf | 26 + modules/unistdio/u16-vsprintf-tests | 14 + modules/unistdio/u32-asnprintf | 26 + modules/unistdio/u32-asnprintf-tests | 14 + modules/unistdio/u32-asprintf | 25 + modules/unistdio/u32-printf-parse | 30 ++ modules/unistdio/u32-snprintf | 25 + modules/unistdio/u32-sprintf | 25 + modules/unistdio/u32-u32-asnprintf | 26 + modules/unistdio/u32-u32-asprintf | 25 + modules/unistdio/u32-u32-snprintf | 25 + modules/unistdio/u32-u32-sprintf | 25 + modules/unistdio/u32-u32-vasnprintf | 59 +++ modules/unistdio/u32-u32-vasprintf | 25 + modules/unistdio/u32-u32-vsnprintf | 26 + modules/unistdio/u32-u32-vsprintf | 26 + modules/unistdio/u32-vasnprintf | 59 +++ modules/unistdio/u32-vasnprintf-tests | 31 ++ modules/unistdio/u32-vasprintf | 25 + modules/unistdio/u32-vasprintf-tests | 13 + modules/unistdio/u32-vsnprintf | 26 + modules/unistdio/u32-vsnprintf-tests | 14 + modules/unistdio/u32-vsprintf | 26 + modules/unistdio/u32-vsprintf-tests | 14 + modules/unistdio/u8-asnprintf | 26 + modules/unistdio/u8-asnprintf-tests | 14 + modules/unistdio/u8-asprintf | 25 + modules/unistdio/u8-printf-parse | 30 ++ modules/unistdio/u8-snprintf | 25 + modules/unistdio/u8-sprintf | 25 + modules/unistdio/u8-u8-asnprintf | 26 + modules/unistdio/u8-u8-asprintf | 25 + modules/unistdio/u8-u8-snprintf | 25 + modules/unistdio/u8-u8-sprintf | 25 + modules/unistdio/u8-u8-vasnprintf | 59 +++ modules/unistdio/u8-u8-vasprintf | 25 + modules/unistdio/u8-u8-vsnprintf | 26 + modules/unistdio/u8-u8-vsprintf | 26 + modules/unistdio/u8-vasnprintf | 59 +++ modules/unistdio/u8-vasnprintf-tests | 31 ++ modules/unistdio/u8-vasprintf | 25 + modules/unistdio/u8-vasprintf-tests | 13 + modules/unistdio/u8-vsnprintf | 26 + modules/unistdio/u8-vsnprintf-tests | 14 + modules/unistdio/u8-vsprintf | 26 + modules/unistdio/u8-vsprintf-tests | 14 + modules/unistdio/ulc-asnprintf | 26 + modules/unistdio/ulc-asnprintf-tests | 14 + modules/unistdio/ulc-asprintf | 25 + modules/unistdio/ulc-fprintf | 25 + modules/unistdio/ulc-printf-parse | 31 ++ modules/unistdio/ulc-snprintf | 25 + modules/unistdio/ulc-sprintf | 25 + modules/unistdio/ulc-vasnprintf | 57 ++ modules/unistdio/ulc-vasnprintf-tests | 27 + modules/unistdio/ulc-vasprintf | 25 + modules/unistdio/ulc-vasprintf-tests | 13 + modules/unistdio/ulc-vfprintf | 25 + modules/unistdio/ulc-vsnprintf | 25 + modules/unistdio/ulc-vsnprintf-tests | 14 + modules/unistdio/ulc-vsprintf | 26 + modules/unistdio/ulc-vsprintf-tests | 14 + tests/unistdio/test-u16-asnprintf1.c | 59 +++ tests/unistdio/test-u16-asnprintf1.h | 61 +++ tests/unistdio/test-u16-printf1.h | 942 +++++++++++++++++++++++++++++++++ tests/unistdio/test-u16-vasnprintf1.c | 88 +++ tests/unistdio/test-u16-vasnprintf2.c | 132 +++++ tests/unistdio/test-u16-vasnprintf2.sh | 21 + tests/unistdio/test-u16-vasnprintf3.c | 132 +++++ tests/unistdio/test-u16-vasnprintf3.sh | 21 + tests/unistdio/test-u16-vasprintf1.c | 75 +++ tests/unistdio/test-u16-vsnprintf1.c | 80 +++ tests/unistdio/test-u16-vsprintf1.c | 80 +++ tests/unistdio/test-u32-asnprintf1.c | 59 +++ tests/unistdio/test-u32-asnprintf1.h | 61 +++ tests/unistdio/test-u32-printf1.h | 942 +++++++++++++++++++++++++++++++++ tests/unistdio/test-u32-vasnprintf1.c | 88 +++ tests/unistdio/test-u32-vasnprintf2.c | 132 +++++ tests/unistdio/test-u32-vasnprintf2.sh | 21 + tests/unistdio/test-u32-vasnprintf3.c | 132 +++++ tests/unistdio/test-u32-vasnprintf3.sh | 21 + tests/unistdio/test-u32-vasprintf1.c | 75 +++ tests/unistdio/test-u32-vsnprintf1.c | 80 +++ tests/unistdio/test-u32-vsprintf1.c | 80 +++ tests/unistdio/test-u8-asnprintf1.c | 59 +++ tests/unistdio/test-u8-asnprintf1.h | 58 ++ tests/unistdio/test-u8-printf1.h | 705 ++++++++++++++++++++++++ tests/unistdio/test-u8-vasnprintf1.c | 88 +++ tests/unistdio/test-u8-vasnprintf2.c | 122 +++++ tests/unistdio/test-u8-vasnprintf2.sh | 21 + tests/unistdio/test-u8-vasnprintf3.c | 122 +++++ tests/unistdio/test-u8-vasnprintf3.sh | 21 + tests/unistdio/test-u8-vasprintf1.c | 75 +++ tests/unistdio/test-u8-vsnprintf1.c | 80 +++ tests/unistdio/test-u8-vsprintf1.c | 80 +++ tests/unistdio/test-ulc-asnprintf1.c | 56 ++ tests/unistdio/test-ulc-asnprintf1.h | 55 ++ tests/unistdio/test-ulc-printf1.h | 499 +++++++++++++++++ tests/unistdio/test-ulc-vasnprintf1.c | 85 +++ tests/unistdio/test-ulc-vasnprintf2.c | 258 +++++++++ tests/unistdio/test-ulc-vasnprintf2.sh | 21 + tests/unistdio/test-ulc-vasnprintf3.c | 246 +++++++++ tests/unistdio/test-ulc-vasnprintf3.sh | 21 + tests/unistdio/test-ulc-vasprintf1.c | 72 +++ tests/unistdio/test-ulc-vsnprintf1.c | 73 +++ tests/unistdio/test-ulc-vsprintf1.c | 73 +++ 203 files changed, 11554 insertions(+) create mode 100644 lib/unistdio.h create mode 100644 lib/unistdio/u-asnprintf.h create mode 100644 lib/unistdio/u-asprintf.h create mode 100644 lib/unistdio/u-printf-args.c create mode 100644 lib/unistdio/u-printf-args.h create mode 100644 lib/unistdio/u-printf-parse.h create mode 100644 lib/unistdio/u-snprintf.h create mode 100644 lib/unistdio/u-sprintf.h create mode 100644 lib/unistdio/u-vasprintf.h create mode 100644 lib/unistdio/u-vsnprintf.h create mode 100644 lib/unistdio/u-vsprintf.h create mode 100644 lib/unistdio/u16-asnprintf.c create mode 100644 lib/unistdio/u16-asprintf.c create mode 100644 lib/unistdio/u16-printf-parse.c create mode 100644 lib/unistdio/u16-snprintf.c create mode 100644 lib/unistdio/u16-sprintf.c create mode 100644 lib/unistdio/u16-u16-asnprintf.c create mode 100644 lib/unistdio/u16-u16-asprintf.c create mode 100644 lib/unistdio/u16-u16-snprintf.c create mode 100644 lib/unistdio/u16-u16-sprintf.c create mode 100644 lib/unistdio/u16-u16-vasnprintf.c create mode 100644 lib/unistdio/u16-u16-vasprintf.c create mode 100644 lib/unistdio/u16-u16-vsnprintf.c create mode 100644 lib/unistdio/u16-u16-vsprintf.c create mode 100644 lib/unistdio/u16-vasnprintf.c create mode 100644 lib/unistdio/u16-vasprintf.c create mode 100644 lib/unistdio/u16-vsnprintf.c create mode 100644 lib/unistdio/u16-vsprintf.c create mode 100644 lib/unistdio/u32-asnprintf.c create mode 100644 lib/unistdio/u32-asprintf.c create mode 100644 lib/unistdio/u32-printf-parse.c create mode 100644 lib/unistdio/u32-snprintf.c create mode 100644 lib/unistdio/u32-sprintf.c create mode 100644 lib/unistdio/u32-u32-asnprintf.c create mode 100644 lib/unistdio/u32-u32-asprintf.c create mode 100644 lib/unistdio/u32-u32-snprintf.c create mode 100644 lib/unistdio/u32-u32-sprintf.c create mode 100644 lib/unistdio/u32-u32-vasnprintf.c create mode 100644 lib/unistdio/u32-u32-vasprintf.c create mode 100644 lib/unistdio/u32-u32-vsnprintf.c create mode 100644 lib/unistdio/u32-u32-vsprintf.c create mode 100644 lib/unistdio/u32-vasnprintf.c create mode 100644 lib/unistdio/u32-vasprintf.c create mode 100644 lib/unistdio/u32-vsnprintf.c create mode 100644 lib/unistdio/u32-vsprintf.c create mode 100644 lib/unistdio/u8-asnprintf.c create mode 100644 lib/unistdio/u8-asprintf.c create mode 100644 lib/unistdio/u8-printf-parse.c create mode 100644 lib/unistdio/u8-snprintf.c create mode 100644 lib/unistdio/u8-sprintf.c create mode 100644 lib/unistdio/u8-u8-asnprintf.c create mode 100644 lib/unistdio/u8-u8-asprintf.c create mode 100644 lib/unistdio/u8-u8-snprintf.c create mode 100644 lib/unistdio/u8-u8-sprintf.c create mode 100644 lib/unistdio/u8-u8-vasnprintf.c create mode 100644 lib/unistdio/u8-u8-vasprintf.c create mode 100644 lib/unistdio/u8-u8-vsnprintf.c create mode 100644 lib/unistdio/u8-u8-vsprintf.c create mode 100644 lib/unistdio/u8-vasnprintf.c create mode 100644 lib/unistdio/u8-vasprintf.c create mode 100644 lib/unistdio/u8-vsnprintf.c create mode 100644 lib/unistdio/u8-vsprintf.c create mode 100644 lib/unistdio/ulc-asnprintf.c create mode 100644 lib/unistdio/ulc-asprintf.c create mode 100644 lib/unistdio/ulc-fprintf.c create mode 100644 lib/unistdio/ulc-printf-parse.c create mode 100644 lib/unistdio/ulc-snprintf.c create mode 100644 lib/unistdio/ulc-sprintf.c create mode 100644 lib/unistdio/ulc-vasnprintf.c create mode 100644 lib/unistdio/ulc-vasprintf.c create mode 100644 lib/unistdio/ulc-vfprintf.c create mode 100644 lib/unistdio/ulc-vsnprintf.c create mode 100644 lib/unistdio/ulc-vsprintf.c create mode 100644 modules/unistdio/base create mode 100644 modules/unistdio/u-printf-args create mode 100644 modules/unistdio/u16-asnprintf create mode 100644 modules/unistdio/u16-asnprintf-tests create mode 100644 modules/unistdio/u16-asprintf create mode 100644 modules/unistdio/u16-printf-parse create mode 100644 modules/unistdio/u16-snprintf create mode 100644 modules/unistdio/u16-sprintf create mode 100644 modules/unistdio/u16-u16-asnprintf create mode 100644 modules/unistdio/u16-u16-asprintf create mode 100644 modules/unistdio/u16-u16-snprintf create mode 100644 modules/unistdio/u16-u16-sprintf create mode 100644 modules/unistdio/u16-u16-vasnprintf create mode 100644 modules/unistdio/u16-u16-vasprintf create mode 100644 modules/unistdio/u16-u16-vsnprintf create mode 100644 modules/unistdio/u16-u16-vsprintf create mode 100644 modules/unistdio/u16-vasnprintf create mode 100644 modules/unistdio/u16-vasnprintf-tests create mode 100644 modules/unistdio/u16-vasprintf create mode 100644 modules/unistdio/u16-vasprintf-tests create mode 100644 modules/unistdio/u16-vsnprintf create mode 100644 modules/unistdio/u16-vsnprintf-tests create mode 100644 modules/unistdio/u16-vsprintf create mode 100644 modules/unistdio/u16-vsprintf-tests create mode 100644 modules/unistdio/u32-asnprintf create mode 100644 modules/unistdio/u32-asnprintf-tests create mode 100644 modules/unistdio/u32-asprintf create mode 100644 modules/unistdio/u32-printf-parse create mode 100644 modules/unistdio/u32-snprintf create mode 100644 modules/unistdio/u32-sprintf create mode 100644 modules/unistdio/u32-u32-asnprintf create mode 100644 modules/unistdio/u32-u32-asprintf create mode 100644 modules/unistdio/u32-u32-snprintf create mode 100644 modules/unistdio/u32-u32-sprintf create mode 100644 modules/unistdio/u32-u32-vasnprintf create mode 100644 modules/unistdio/u32-u32-vasprintf create mode 100644 modules/unistdio/u32-u32-vsnprintf create mode 100644 modules/unistdio/u32-u32-vsprintf create mode 100644 modules/unistdio/u32-vasnprintf create mode 100644 modules/unistdio/u32-vasnprintf-tests create mode 100644 modules/unistdio/u32-vasprintf create mode 100644 modules/unistdio/u32-vasprintf-tests create mode 100644 modules/unistdio/u32-vsnprintf create mode 100644 modules/unistdio/u32-vsnprintf-tests create mode 100644 modules/unistdio/u32-vsprintf create mode 100644 modules/unistdio/u32-vsprintf-tests create mode 100644 modules/unistdio/u8-asnprintf create mode 100644 modules/unistdio/u8-asnprintf-tests create mode 100644 modules/unistdio/u8-asprintf create mode 100644 modules/unistdio/u8-printf-parse create mode 100644 modules/unistdio/u8-snprintf create mode 100644 modules/unistdio/u8-sprintf create mode 100644 modules/unistdio/u8-u8-asnprintf create mode 100644 modules/unistdio/u8-u8-asprintf create mode 100644 modules/unistdio/u8-u8-snprintf create mode 100644 modules/unistdio/u8-u8-sprintf create mode 100644 modules/unistdio/u8-u8-vasnprintf create mode 100644 modules/unistdio/u8-u8-vasprintf create mode 100644 modules/unistdio/u8-u8-vsnprintf create mode 100644 modules/unistdio/u8-u8-vsprintf create mode 100644 modules/unistdio/u8-vasnprintf create mode 100644 modules/unistdio/u8-vasnprintf-tests create mode 100644 modules/unistdio/u8-vasprintf create mode 100644 modules/unistdio/u8-vasprintf-tests create mode 100644 modules/unistdio/u8-vsnprintf create mode 100644 modules/unistdio/u8-vsnprintf-tests create mode 100644 modules/unistdio/u8-vsprintf create mode 100644 modules/unistdio/u8-vsprintf-tests create mode 100644 modules/unistdio/ulc-asnprintf create mode 100644 modules/unistdio/ulc-asnprintf-tests create mode 100644 modules/unistdio/ulc-asprintf create mode 100644 modules/unistdio/ulc-fprintf create mode 100644 modules/unistdio/ulc-printf-parse create mode 100644 modules/unistdio/ulc-snprintf create mode 100644 modules/unistdio/ulc-sprintf create mode 100644 modules/unistdio/ulc-vasnprintf create mode 100644 modules/unistdio/ulc-vasnprintf-tests create mode 100644 modules/unistdio/ulc-vasprintf create mode 100644 modules/unistdio/ulc-vasprintf-tests create mode 100644 modules/unistdio/ulc-vfprintf create mode 100644 modules/unistdio/ulc-vsnprintf create mode 100644 modules/unistdio/ulc-vsnprintf-tests create mode 100644 modules/unistdio/ulc-vsprintf create mode 100644 modules/unistdio/ulc-vsprintf-tests create mode 100644 tests/unistdio/test-u16-asnprintf1.c create mode 100644 tests/unistdio/test-u16-asnprintf1.h create mode 100644 tests/unistdio/test-u16-printf1.h create mode 100644 tests/unistdio/test-u16-vasnprintf1.c create mode 100644 tests/unistdio/test-u16-vasnprintf2.c create mode 100755 tests/unistdio/test-u16-vasnprintf2.sh create mode 100644 tests/unistdio/test-u16-vasnprintf3.c create mode 100755 tests/unistdio/test-u16-vasnprintf3.sh create mode 100644 tests/unistdio/test-u16-vasprintf1.c create mode 100644 tests/unistdio/test-u16-vsnprintf1.c create mode 100644 tests/unistdio/test-u16-vsprintf1.c create mode 100644 tests/unistdio/test-u32-asnprintf1.c create mode 100644 tests/unistdio/test-u32-asnprintf1.h create mode 100644 tests/unistdio/test-u32-printf1.h create mode 100644 tests/unistdio/test-u32-vasnprintf1.c create mode 100644 tests/unistdio/test-u32-vasnprintf2.c create mode 100755 tests/unistdio/test-u32-vasnprintf2.sh create mode 100644 tests/unistdio/test-u32-vasnprintf3.c create mode 100755 tests/unistdio/test-u32-vasnprintf3.sh create mode 100644 tests/unistdio/test-u32-vasprintf1.c create mode 100644 tests/unistdio/test-u32-vsnprintf1.c create mode 100644 tests/unistdio/test-u32-vsprintf1.c create mode 100644 tests/unistdio/test-u8-asnprintf1.c create mode 100644 tests/unistdio/test-u8-asnprintf1.h create mode 100644 tests/unistdio/test-u8-printf1.h create mode 100644 tests/unistdio/test-u8-vasnprintf1.c create mode 100644 tests/unistdio/test-u8-vasnprintf2.c create mode 100755 tests/unistdio/test-u8-vasnprintf2.sh create mode 100644 tests/unistdio/test-u8-vasnprintf3.c create mode 100755 tests/unistdio/test-u8-vasnprintf3.sh create mode 100644 tests/unistdio/test-u8-vasprintf1.c create mode 100644 tests/unistdio/test-u8-vsnprintf1.c create mode 100644 tests/unistdio/test-u8-vsprintf1.c create mode 100644 tests/unistdio/test-ulc-asnprintf1.c create mode 100644 tests/unistdio/test-ulc-asnprintf1.h create mode 100644 tests/unistdio/test-ulc-printf1.h create mode 100644 tests/unistdio/test-ulc-vasnprintf1.c create mode 100644 tests/unistdio/test-ulc-vasnprintf2.c create mode 100755 tests/unistdio/test-ulc-vasnprintf2.sh create mode 100644 tests/unistdio/test-ulc-vasnprintf3.c create mode 100755 tests/unistdio/test-ulc-vasnprintf3.sh create mode 100644 tests/unistdio/test-ulc-vasprintf1.c create mode 100644 tests/unistdio/test-ulc-vsnprintf1.c create mode 100644 tests/unistdio/test-ulc-vsprintf1.c diff --git a/ChangeLog b/ChangeLog index dc954fb67..0152979eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,210 @@ 2007-07-01 Bruno Haible + * lib/unistdio.h: New file. + * lib/unistdio/u-asnprintf.h: New file. + * lib/unistdio/u-asprintf.h: New file. + * lib/unistdio/u-printf-args.c: New file. + * lib/unistdio/u-printf-args.h: New file. + * lib/unistdio/u-printf-parse.h: New file. + * lib/unistdio/u-snprintf.h: New file. + * lib/unistdio/u-sprintf.h: New file. + * lib/unistdio/u-vasprintf.h: New file. + * lib/unistdio/u-vsnprintf.h: New file. + * lib/unistdio/u-vsprintf.h: New file. + * lib/unistdio/ulc-asnprintf.c: New file. + * lib/unistdio/ulc-asprintf.c: New file. + * lib/unistdio/ulc-fprintf.c: New file, based on lib/fprintf.c. + * lib/unistdio/ulc-printf-parse.c: New file. + * lib/unistdio/ulc-snprintf.c: New file. + * lib/unistdio/ulc-sprintf.c: New file. + * lib/unistdio/ulc-vasnprintf.c: New file. + * lib/unistdio/ulc-vasprintf.c: New file. + * lib/unistdio/ulc-vfprintf.c: New file, based on lib/vfprintf.c. + * lib/unistdio/ulc-vsnprintf.c: New file. + * lib/unistdio/ulc-vsprintf.c: New file. + * lib/unistdio/u8-asnprintf.c: New file. + * lib/unistdio/u8-asprintf.c: New file. + * lib/unistdio/u8-printf-parse.c: New file. + * lib/unistdio/u8-snprintf.c: New file. + * lib/unistdio/u8-sprintf.c: New file. + * lib/unistdio/u8-vasnprintf.c: New file. + * lib/unistdio/u8-vasprintf.c: New file. + * lib/unistdio/u8-vsnprintf.c: New file. + * lib/unistdio/u8-vsprintf.c: New file. + * lib/unistdio/u8-u8-asnprintf.c: New file. + * lib/unistdio/u8-u8-asprintf.c: New file. + * lib/unistdio/u8-u8-snprintf.c: New file. + * lib/unistdio/u8-u8-sprintf.c: New file. + * lib/unistdio/u8-u8-vasnprintf.c: New file. + * lib/unistdio/u8-u8-vasprintf.c: New file. + * lib/unistdio/u8-u8-vsnprintf.c: New file. + * lib/unistdio/u8-u8-vsprintf.c: New file. + * lib/unistdio/u16-asnprintf.c: New file. + * lib/unistdio/u16-asprintf.c: New file. + * lib/unistdio/u16-printf-parse.c: New file. + * lib/unistdio/u16-snprintf.c: New file. + * lib/unistdio/u16-sprintf.c: New file. + * lib/unistdio/u16-vasnprintf.c: New file. + * lib/unistdio/u16-vasprintf.c: New file. + * lib/unistdio/u16-vsnprintf.c: New file. + * lib/unistdio/u16-vsprintf.c: New file. + * lib/unistdio/u16-u16-asnprintf.c: New file. + * lib/unistdio/u16-u16-asprintf.c: New file. + * lib/unistdio/u16-u16-snprintf.c: New file. + * lib/unistdio/u16-u16-sprintf.c: New file. + * lib/unistdio/u16-u16-vasnprintf.c: New file. + * lib/unistdio/u16-u16-vasprintf.c: New file. + * lib/unistdio/u16-u16-vsnprintf.c: New file. + * lib/unistdio/u16-u16-vsprintf.c: New file. + * lib/unistdio/u32-asnprintf.c: New file. + * lib/unistdio/u32-asprintf.c: New file. + * lib/unistdio/u32-printf-parse.c: New file. + * lib/unistdio/u32-snprintf.c: New file. + * lib/unistdio/u32-sprintf.c: New file. + * lib/unistdio/u32-vasnprintf.c: New file. + * lib/unistdio/u32-vasprintf.c: New file. + * lib/unistdio/u32-vsnprintf.c: New file. + * lib/unistdio/u32-vsprintf.c: New file. + * lib/unistdio/u32-u32-asnprintf.c: New file. + * lib/unistdio/u32-u32-asprintf.c: New file. + * lib/unistdio/u32-u32-snprintf.c: New file. + * lib/unistdio/u32-u32-sprintf.c: New file. + * lib/unistdio/u32-u32-vasnprintf.c: New file. + * lib/unistdio/u32-u32-vasprintf.c: New file. + * lib/unistdio/u32-u32-vsnprintf.c: New file. + * lib/unistdio/u32-u32-vsprintf.c: New file. + * tests/unistdio/test-ulc-asnprintf1.c: New file. + * tests/unistdio/test-ulc-asnprintf1.h: New file. + * tests/unistdio/test-ulc-printf1.h: New file. + * tests/unistdio/test-ulc-vasnprintf1.c: New file. + * tests/unistdio/test-ulc-vasnprintf2.c: New file. + * tests/unistdio/test-ulc-vasnprintf2.sh: New file. + * tests/unistdio/test-ulc-vasnprintf3.c: New file. + * tests/unistdio/test-ulc-vasnprintf3.sh: New file. + * tests/unistdio/test-ulc-vasprintf1.c: New file. + * tests/unistdio/test-ulc-vsnprintf1.c: New file. + * tests/unistdio/test-ulc-vsprintf1.c: New file. + * tests/unistdio/test-u8-asnprintf1.c: New file. + * tests/unistdio/test-u8-asnprintf1.h: New file. + * tests/unistdio/test-u8-printf1.h: New file. + * tests/unistdio/test-u8-vasnprintf1.c: New file. + * tests/unistdio/test-u8-vasnprintf2.c: New file. + * tests/unistdio/test-u8-vasnprintf2.sh: New file. + * tests/unistdio/test-u8-vasnprintf3.c: New file. + * tests/unistdio/test-u8-vasnprintf3.sh: New file. + * tests/unistdio/test-u8-vasprintf1.c: New file. + * tests/unistdio/test-u8-vsnprintf1.c: New file. + * tests/unistdio/test-u8-vsprintf1.c: New file. + * tests/unistdio/test-u16-asnprintf1.c: New file. + * tests/unistdio/test-u16-asnprintf1.h: New file. + * tests/unistdio/test-u16-printf1.h: New file. + * tests/unistdio/test-u16-vasnprintf1.c: New file. + * tests/unistdio/test-u16-vasnprintf2.c: New file. + * tests/unistdio/test-u16-vasnprintf2.sh: New file. + * tests/unistdio/test-u16-vasnprintf3.c: New file. + * tests/unistdio/test-u16-vasnprintf3.sh: New file. + * tests/unistdio/test-u16-vasprintf1.c: New file. + * tests/unistdio/test-u16-vsnprintf1.c: New file. + * tests/unistdio/test-u16-vsprintf1.c: New file. + * tests/unistdio/test-u32-asnprintf1.c: New file. + * tests/unistdio/test-u32-asnprintf1.h: New file. + * tests/unistdio/test-u32-printf1.h: New file. + * tests/unistdio/test-u32-vasnprintf1.c: New file. + * tests/unistdio/test-u32-vasnprintf2.c: New file. + * tests/unistdio/test-u32-vasnprintf2.sh: New file. + * tests/unistdio/test-u32-vasnprintf3.c: New file. + * tests/unistdio/test-u32-vasnprintf3.sh: New file. + * tests/unistdio/test-u32-vasprintf1.c: New file. + * tests/unistdio/test-u32-vsnprintf1.c: New file. + * tests/unistdio/test-u32-vsprintf1.c: New file. + * modules/unistdio/base: New file. + * modules/unistdio/u-printf-args: New file. + * modules/unistdio/ulc-asnprintf: New file. + * modules/unistdio/ulc-asprintf: New file. + * modules/unistdio/ulc-fprintf: New file. + * modules/unistdio/ulc-printf-parse: New file. + * modules/unistdio/ulc-snprintf: New file. + * modules/unistdio/ulc-sprintf: New file. + * modules/unistdio/ulc-vasnprintf: New file. + * modules/unistdio/ulc-vasprintf: New file. + * modules/unistdio/ulc-vfprintf: New file. + * modules/unistdio/ulc-vsnprintf: New file. + * modules/unistdio/ulc-vsprintf: New file. + * modules/unistdio/u8-asnprintf: New file. + * modules/unistdio/u8-asprintf: New file. + * modules/unistdio/u8-printf-parse: New file. + * modules/unistdio/u8-snprintf: New file. + * modules/unistdio/u8-sprintf: New file. + * modules/unistdio/u8-vasnprintf: New file. + * modules/unistdio/u8-vasprintf: New file. + * modules/unistdio/u8-vsnprintf: New file. + * modules/unistdio/u8-vsprintf: New file. + * modules/unistdio/u8-u8-asnprintf: New file. + * modules/unistdio/u8-u8-asprintf: New file. + * modules/unistdio/u8-u8-snprintf: New file. + * modules/unistdio/u8-u8-sprintf: New file. + * modules/unistdio/u8-u8-vasnprintf: New file. + * modules/unistdio/u8-u8-vasprintf: New file. + * modules/unistdio/u8-u8-vsnprintf: New file. + * modules/unistdio/u8-u8-vsprintf: New file. + * modules/unistdio/u16-asnprintf: New file. + * modules/unistdio/u16-asprintf: New file. + * modules/unistdio/u16-printf-parse: New file. + * modules/unistdio/u16-snprintf: New file. + * modules/unistdio/u16-sprintf: New file. + * modules/unistdio/u16-vasnprintf: New file. + * modules/unistdio/u16-vasprintf: New file. + * modules/unistdio/u16-vsnprintf: New file. + * modules/unistdio/u16-vsprintf: New file. + * modules/unistdio/u16-u16-asnprintf: New file. + * modules/unistdio/u16-u16-asprintf: New file. + * modules/unistdio/u16-u16-snprintf: New file. + * modules/unistdio/u16-u16-sprintf: New file. + * modules/unistdio/u16-u16-vasnprintf: New file. + * modules/unistdio/u16-u16-vasprintf: New file. + * modules/unistdio/u16-u16-vsnprintf: New file. + * modules/unistdio/u16-u16-vsprintf: New file. + * modules/unistdio/u32-asnprintf: New file. + * modules/unistdio/u32-asprintf: New file. + * modules/unistdio/u32-printf-parse: New file. + * modules/unistdio/u32-snprintf: New file. + * modules/unistdio/u32-sprintf: New file. + * modules/unistdio/u32-vasnprintf: New file. + * modules/unistdio/u32-vasprintf: New file. + * modules/unistdio/u32-vsnprintf: New file. + * modules/unistdio/u32-vsprintf: New file. + * modules/unistdio/u32-u32-asnprintf: New file. + * modules/unistdio/u32-u32-asprintf: New file. + * modules/unistdio/u32-u32-snprintf: New file. + * modules/unistdio/u32-u32-sprintf: New file. + * modules/unistdio/u32-u32-vasnprintf: New file. + * modules/unistdio/u32-u32-vasprintf: New file. + * modules/unistdio/u32-u32-vsnprintf: New file. + * modules/unistdio/u32-u32-vsprintf: New file. + * modules/unistdio/ulc-asnprintf-tests: New file. + * modules/unistdio/ulc-vasnprintf-tests: New file. + * modules/unistdio/ulc-vasprintf-tests: New file. + * modules/unistdio/ulc-vsnprintf-tests: New file. + * modules/unistdio/ulc-vsprintf-tests: New file. + * modules/unistdio/u8-asnprintf-tests: New file. + * modules/unistdio/u8-vasnprintf-tests: New file. + * modules/unistdio/u8-vasprintf-tests: New file. + * modules/unistdio/u8-vsnprintf-tests: New file. + * modules/unistdio/u8-vsprintf-tests: New file. + * modules/unistdio/u16-asnprintf-tests: New file. + * modules/unistdio/u16-vasnprintf-tests: New file. + * modules/unistdio/u16-vasprintf-tests: New file. + * modules/unistdio/u16-vsnprintf-tests: New file. + * modules/unistdio/u16-vsprintf-tests: New file. + * modules/unistdio/u32-asnprintf-tests: New file. + * modules/unistdio/u32-vasnprintf-tests: New file. + * modules/unistdio/u32-vasprintf-tests: New file. + * modules/unistdio/u32-vsnprintf-tests: New file. + * modules/unistdio/u32-vsprintf-tests: New file. + * MODULES.html.sh (Unicode string functions): Add the new modules. + +2007-07-01 Bruno Haible + * lib/sprintf.c (sprintf): Limit the available length estimation, to avoid address wraparound. * lib/vsprintf.c (vsprintf): Likewise. diff --git a/MODULES.html.sh b/MODULES.html.sh index 1721e7309..fd1e64389 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2439,6 +2439,70 @@ func_all_modules () func_module uniconv/u8-strconv-to-locale func_module uniconv/u16-strconv-to-locale func_module uniconv/u32-strconv-to-locale + func_module unistdio/base + func_module unistdio/u-printf-args + func_module unistdio/ulc-asnprintf + func_module unistdio/ulc-asprintf + func_module unistdio/ulc-fprintf + func_module unistdio/ulc-printf-parse + func_module unistdio/ulc-snprintf + func_module unistdio/ulc-sprintf + func_module unistdio/ulc-vasnprintf + func_module unistdio/ulc-vasprintf + func_module unistdio/ulc-vfprintf + func_module unistdio/ulc-vsnprintf + func_module unistdio/ulc-vsprintf + func_module unistdio/u8-asnprintf + func_module unistdio/u8-asprintf + func_module unistdio/u8-printf-parse + func_module unistdio/u8-snprintf + func_module unistdio/u8-sprintf + func_module unistdio/u8-vasnprintf + func_module unistdio/u8-vasprintf + func_module unistdio/u8-vsnprintf + func_module unistdio/u8-vsprintf + func_module unistdio/u8-u8-asnprintf + func_module unistdio/u8-u8-asprintf + func_module unistdio/u8-u8-snprintf + func_module unistdio/u8-u8-sprintf + func_module unistdio/u8-u8-vasnprintf + func_module unistdio/u8-u8-vasprintf + func_module unistdio/u8-u8-vsnprintf + func_module unistdio/u8-u8-vsprintf + func_module unistdio/u16-asnprintf + func_module unistdio/u16-asprintf + func_module unistdio/u16-printf-parse + func_module unistdio/u16-snprintf + func_module unistdio/u16-sprintf + func_module unistdio/u16-vasnprintf + func_module unistdio/u16-vasprintf + func_module unistdio/u16-vsnprintf + func_module unistdio/u16-vsprintf + func_module unistdio/u16-u16-asnprintf + func_module unistdio/u16-u16-asprintf + func_module unistdio/u16-u16-snprintf + func_module unistdio/u16-u16-sprintf + func_module unistdio/u16-u16-vasnprintf + func_module unistdio/u16-u16-vasprintf + func_module unistdio/u16-u16-vsnprintf + func_module unistdio/u16-u16-vsprintf + func_module unistdio/u32-asnprintf + func_module unistdio/u32-asprintf + func_module unistdio/u32-printf-parse + func_module unistdio/u32-snprintf + func_module unistdio/u32-sprintf + func_module unistdio/u32-vasnprintf + func_module unistdio/u32-vasprintf + func_module unistdio/u32-vsnprintf + func_module unistdio/u32-vsprintf + func_module unistdio/u32-u32-asnprintf + func_module unistdio/u32-u32-asprintf + func_module unistdio/u32-u32-snprintf + func_module unistdio/u32-u32-sprintf + func_module unistdio/u32-u32-vasnprintf + func_module unistdio/u32-u32-vasprintf + func_module unistdio/u32-u32-vsnprintf + func_module unistdio/u32-u32-vsprintf func_end_table element="Executing programs" diff --git a/lib/unistdio.h b/lib/unistdio.h new file mode 100644 index 000000000..574688e72 --- /dev/null +++ b/lib/unistdio.h @@ -0,0 +1,258 @@ +/* Elementary Unicode string functions. + Copyright (C) 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _UNISTDIO_H +#define _UNISTDIO_H + +#include "unitypes.h" + +/* Get size_t. */ +#include + +/* Get FILE. */ +#include + +/* Get va_list. */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* These work like the printf function family. + In the format string: + The format directive 'U' takes an UTF-8 string (const uint8_t *). + The format directive 'lU' takes an UTF-16 string (const uint16_t *). + The format directive 'llU' takes an UTF-32 string (const uint32_t *). + + The prefix (ulc_, u8_, u16_, u16_) indicates the type of the resulting + string. The prefix 'ulc' stands for "locale encoded". + + An infix 'v' indicates that a va_list is passed instead of multiple + arguments. + + The functions *sprintf have a 'buf' argument that is assumed to be large + enough. (DANGEROUS! Overflowing the buffer will crash the program.) + The functions *snprintf have a 'buf' argument that is assumed to be 'size' + units large. (DANGEROUS! The resulting string might be truncated in the + middle of a multibyte character.) + The functions *asprintf have a 'resultp' argument. The result will be + freshly allocated and stored in *resultp. + The functions *asnprintf have a (resultbuf, lengthp) argument pair. If + resultbuf is not NULL and the result fits into *lengthp units, it is put + in resultbuf, and resultbuf is returned. Otherwise, a freshly allocated + string is returned. In both cases, *lengthp is set to the length (number + of units) of the returned string. In case of error, NULL is returned and + errno is set. + */ + +/* ASCII format string, result in locale dependent encoded 'char *'. */ +extern int + ulc_sprintf (char *buf, + const char *format, ...); +extern int + ulc_snprintf (char *buf, size_t size, + const char *format, ...); +extern int + ulc_asprintf (char **resultp, + const char *format, ...); +extern char * + ulc_asnprintf (char *resultbuf, size_t *lengthp, + const char *format, ...); +extern int + ulc_vsprintf (char *buf, + const char *format, va_list ap); +extern int + ulc_vsnprintf (char *buf, size_t size, + const char *format, va_list ap); +extern int + ulc_vasprintf (char **resultp, + const char *format, va_list ap); +extern char * + ulc_vasnprintf (char *resultbuf, size_t *lengthp, + const char *format, va_list ap); + +/* ASCII format string, result in UTF-8 format. */ +extern int + u8_sprintf (uint8_t *buf, + const char *format, ...); +extern int + u8_snprintf (uint8_t *buf, size_t size, + const char *format, ...); +extern int + u8_asprintf (uint8_t **resultp, + const char *format, ...); +extern uint8_t * + u8_asnprintf (uint8_t *resultbuf, size_t *lengthp, + const char *format, ...); +extern int + u8_vsprintf (uint8_t *buf, + const char *format, va_list ap); +extern int + u8_vsnprintf (uint8_t *buf, size_t size, + const char *format, va_list ap); +extern int + u8_vasprintf (uint8_t **resultp, + const char *format, va_list ap); +extern uint8_t * + u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp, + const char *format, va_list ap); + +/* UTF-8 format string, result in UTF-8 format. */ +extern int + u8_u8_sprintf (uint8_t *buf, + const uint8_t *format, ...); +extern int + u8_u8_snprintf (uint8_t *buf, size_t size, + const uint8_t *format, ...); +extern int + u8_u8_asprintf (uint8_t **resultp, + const uint8_t *format, ...); +extern uint8_t * + u8_u8_asnprintf (uint8_t *resultbuf, size_t *lengthp, + const uint8_t *format, ...); +extern int + u8_u8_vsprintf (uint8_t *buf, + const uint8_t *format, va_list ap); +extern int + u8_u8_vsnprintf (uint8_t *buf, size_t size, + const uint8_t *format, va_list ap); +extern int + u8_u8_vasprintf (uint8_t **resultp, + const uint8_t *format, va_list ap); +extern uint8_t * + u8_u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp, + const uint8_t *format, va_list ap); + +/* ASCII format string, result in UTF-16 format. */ +extern int + u16_sprintf (uint16_t *buf, + const char *format, ...); +extern int + u16_snprintf (uint16_t *buf, size_t size, + const char *format, ...); +extern int + u16_asprintf (uint16_t **resultp, + const char *format, ...); +extern uint16_t * + u16_asnprintf (uint16_t *resultbuf, size_t *lengthp, + const char *format, ...); +extern int + u16_vsprintf (uint16_t *buf, + const char *format, va_list ap); +extern int + u16_vsnprintf (uint16_t *buf, size_t size, + const char *format, va_list ap); +extern int + u16_vasprintf (uint16_t **resultp, + const char *format, va_list ap); +extern uint16_t * + u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp, + const char *format, va_list ap); + +/* UTF-16 format string, result in UTF-16 format. */ +extern int + u16_u16_sprintf (uint16_t *buf, + const uint16_t *format, ...); +extern int + u16_u16_snprintf (uint16_t *buf, size_t size, + const uint16_t *format, ...); +extern int + u16_u16_asprintf (uint16_t **resultp, + const uint16_t *format, ...); +extern uint16_t * + u16_u16_asnprintf (uint16_t *resultbuf, size_t *lengthp, + const uint16_t *format, ...); +extern int + u16_u16_vsprintf (uint16_t *buf, + const uint16_t *format, va_list ap); +extern int + u16_u16_vsnprintf (uint16_t *buf, size_t size, + const uint16_t *format, va_list ap); +extern int + u16_u16_vasprintf (uint16_t **resultp, + const uint16_t *format, va_list ap); +extern uint16_t * + u16_u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp, + const uint16_t *format, va_list ap); + +/* ASCII format string, result in UTF-32 format. */ +extern int + u32_sprintf (uint32_t *buf, + const char *format, ...); +extern int + u32_snprintf (uint32_t *buf, size_t size, + const char *format, ...); +extern int + u32_asprintf (uint32_t **resultp, + const char *format, ...); +extern uint32_t * + u32_asnprintf (uint32_t *resultbuf, size_t *lengthp, + const char *format, ...); +extern int + u32_vsprintf (uint32_t *buf, + const char *format, va_list ap); +extern int + u32_vsnprintf (uint32_t *buf, size_t size, + const char *format, va_list ap); +extern int + u32_vasprintf (uint32_t **resultp, + const char *format, va_list ap); +extern uint32_t * + u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp, + const char *format, va_list ap); + +/* UTF-32 format string, result in UTF-32 format. */ +extern int + u32_u32_sprintf (uint32_t *buf, + const uint32_t *format, ...); +extern int + u32_u32_snprintf (uint32_t *buf, size_t size, + const uint32_t *format, ...); +extern int + u32_u32_asprintf (uint32_t **resultp, + const uint32_t *format, ...); +extern uint32_t * + u32_u32_asnprintf (uint32_t *resultbuf, size_t *lengthp, + const uint32_t *format, ...); +extern int + u32_u32_vsprintf (uint32_t *buf, + const uint32_t *format, va_list ap); +extern int + u32_u32_vsnprintf (uint32_t *buf, size_t size, + const uint32_t *format, va_list ap); +extern int + u32_u32_vasprintf (uint32_t **resultp, + const uint32_t *format, va_list ap); +extern uint32_t * + u32_u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp, + const uint32_t *format, va_list ap); + +/* ASCII format string, output to FILE in locale dependent encoding. */ +extern int + ulc_fprintf (FILE *stream, + const char *format, ...); +extern int + ulc_vfprintf (FILE *stream, + const char *format, va_list ap); + +#ifdef __cplusplus +} +#endif + +#endif /* _UNISTDIO_H */ diff --git a/lib/unistdio/u-asnprintf.h b/lib/unistdio/u-asnprintf.h new file mode 100644 index 000000000..8f5e0d7e0 --- /dev/null +++ b/lib/unistdio/u-asnprintf.h @@ -0,0 +1,29 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +DCHAR_T * +ASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, const FCHAR_T *format, ...) +{ + va_list args; + DCHAR_T *result; + + va_start (args, format); + result = VASNPRINTF (resultbuf, lengthp, format, args); + va_end (args); + return result; +} diff --git a/lib/unistdio/u-asprintf.h b/lib/unistdio/u-asprintf.h new file mode 100644 index 000000000..2a5d44525 --- /dev/null +++ b/lib/unistdio/u-asprintf.h @@ -0,0 +1,29 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +int +ASPRINTF (DCHAR_T **resultp, const FCHAR_T *format, ...) +{ + va_list args; + int result; + + va_start (args, format); + result = VASPRINTF (resultp, format, args); + va_end (args); + return result; +} diff --git a/lib/unistdio/u-printf-args.c b/lib/unistdio/u-printf-args.c new file mode 100644 index 000000000..b4898df73 --- /dev/null +++ b/lib/unistdio/u-printf-args.c @@ -0,0 +1,24 @@ +/* Decomposed printf argument list. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio/u-printf-args.h" + +#include "printf-args.c" diff --git a/lib/unistdio/u-printf-args.h b/lib/unistdio/u-printf-args.h new file mode 100644 index 000000000..f648e8001 --- /dev/null +++ b/lib/unistdio/u-printf-args.h @@ -0,0 +1,29 @@ +/* Decomposed printf argument list. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _U_PRINTF_ARGS_H +#define _U_PRINTF_ARGS_H + +#include "unitypes.h" + +/* Parametrization of printf-args.h. */ +#define ENABLE_UNISTDIO 1 +#define PRINTF_FETCHARGS u_printf_fetchargs +#include "printf-args.h" + +#endif /* _U_PRINTF_ARGS_H */ diff --git a/lib/unistdio/u-printf-parse.h b/lib/unistdio/u-printf-parse.h new file mode 100644 index 000000000..bb020645a --- /dev/null +++ b/lib/unistdio/u-printf-parse.h @@ -0,0 +1,29 @@ +/* Parse printf format string. + Copyright (C) 1999, 2002, 2005, 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _U_PRINTF_PARSE_H +#define _U_PRINTF_PARSE_H + +#include "unistdio/u-printf-args.h" + +/* Parametrization of printf-parse.h. */ +#undef ENABLE_UNISTDIO +#define ENABLE_UNISTDIO 1 +#include "printf-parse.h" + +#endif /* _U_PRINTF_PARSE_H */ diff --git a/lib/unistdio/u-snprintf.h b/lib/unistdio/u-snprintf.h new file mode 100644 index 000000000..d5bea19b2 --- /dev/null +++ b/lib/unistdio/u-snprintf.h @@ -0,0 +1,29 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +int +SNPRINTF (DCHAR_T *buf, size_t size, const FCHAR_T *format, ...) +{ + va_list args; + int result; + + va_start (args, format); + result = VSNPRINTF (buf, size, format, args); + va_end (args); + return result; +} diff --git a/lib/unistdio/u-sprintf.h b/lib/unistdio/u-sprintf.h new file mode 100644 index 000000000..8cc268141 --- /dev/null +++ b/lib/unistdio/u-sprintf.h @@ -0,0 +1,29 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +int +SPRINTF (DCHAR_T *buf, const FCHAR_T *format, ...) +{ + va_list args; + int result; + + va_start (args, format); + result = VSPRINTF (buf, format, args); + va_end (args); + return result; +} diff --git a/lib/unistdio/u-vasprintf.h b/lib/unistdio/u-vasprintf.h new file mode 100644 index 000000000..22ca03e7e --- /dev/null +++ b/lib/unistdio/u-vasprintf.h @@ -0,0 +1,42 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +int +VASPRINTF (DCHAR_T **resultp, const FCHAR_T *format, va_list args) +{ + size_t length; + DCHAR_T *result = VASNPRINTF (NULL, &length, format, args); + if (result == NULL) + return -1; + + if (length > INT_MAX) + { + free (result); + errno = EOVERFLOW; + return -1; + } + + *resultp = result; + /* Return the number of resulting units, excluding the trailing NUL. */ + return length; +} diff --git a/lib/unistdio/u-vsnprintf.h b/lib/unistdio/u-vsnprintf.h new file mode 100644 index 000000000..d7c62155e --- /dev/null +++ b/lib/unistdio/u-vsnprintf.h @@ -0,0 +1,59 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +int +VSNPRINTF (DCHAR_T *buf, size_t size, const FCHAR_T *format, va_list args) +{ + size_t length; + DCHAR_T *result; + + if (size == 0) + buf = NULL; + else + length = size; + result = VASNPRINTF (buf, &length, format, args); + if (result == NULL) + return -1; + + if (result != buf) + { + if (size != 0) + { + /* The result did not fit into the buffer. Copy the initial segment + into the buffer, truncating it if necessary. */ + size_t n = (length < size ? length : size - 1); + DCHAR_CPY (buf, result, n); + buf[n] = '\0'; + } + free (result); + } + + if (length > INT_MAX) + { + errno = EOVERFLOW; + return -1; + } + + /* Return the number of resulting units, excluding the trailing NUL. */ + return length; +} diff --git a/lib/unistdio/u-vsprintf.h b/lib/unistdio/u-vsprintf.h new file mode 100644 index 000000000..acb84b877 --- /dev/null +++ b/lib/unistdio/u-vsprintf.h @@ -0,0 +1,65 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif + +int +VSPRINTF (DCHAR_T *buf, const FCHAR_T *format, va_list args) +{ + /* Pass an infinite length. But note that *vasnprintf may fail if the buffer + argument is larger than INT_MAX (if that fits into a 'size_t' at all). + Also note that glibc's iconv fails with E2BIG when we pass a length that + is so large that buf + length wraps around, i.e. + (uintptr_t) (buf + length) < (uintptr_t) buf. */ + size_t length; + DCHAR_T *result; + + /* Set length = min (SIZE_MAX, INT_MAX, - (uintptr_t) buf - 1). */ + length = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX); + if (length > (~ (uintptr_t) buf) / sizeof (DCHAR_T)) + length = (~ (uintptr_t) buf) / sizeof (DCHAR_T); + + result = VASNPRINTF (buf, &length, format, args); + if (result == NULL) + return -1; + + /* The infinite buffer size guarantees that the result is not malloc()ed. */ + if (result != buf) + { + /* length is near SIZE_MAX. */ + free (result); + errno = EOVERFLOW; + return -1; + } + + if (length > INT_MAX) + { + errno = EOVERFLOW; + return -1; + } + + /* Return the number of resulting units, excluding the trailing NUL. */ + return length; +} diff --git a/lib/unistdio/u16-asnprintf.c b/lib/unistdio/u16-asnprintf.c new file mode 100644 index 000000000..9e32c7541 --- /dev/null +++ b/lib/unistdio/u16-asnprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASNPRINTF u16_asnprintf +#define VASNPRINTF u16_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint16_t +#include "u-asnprintf.h" diff --git a/lib/unistdio/u16-asprintf.c b/lib/unistdio/u16-asprintf.c new file mode 100644 index 000000000..22c69aec9 --- /dev/null +++ b/lib/unistdio/u16-asprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASPRINTF u16_asprintf +#define VASPRINTF u16_vasprintf +#define FCHAR_T char +#define DCHAR_T uint16_t +#include "u-asprintf.h" diff --git a/lib/unistdio/u16-printf-parse.c b/lib/unistdio/u16-printf-parse.c new file mode 100644 index 000000000..37af0e876 --- /dev/null +++ b/lib/unistdio/u16-printf-parse.c @@ -0,0 +1,28 @@ +/* Formatted output to strings. + Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio/u-printf-parse.h" + +#define PRINTF_PARSE u16_printf_parse +#define CHAR_T uint16_t +#define DIRECTIVE u16_directive +#define DIRECTIVES u16_directives +#include "printf-parse.c" diff --git a/lib/unistdio/u16-snprintf.c b/lib/unistdio/u16-snprintf.c new file mode 100644 index 000000000..6f929f0cb --- /dev/null +++ b/lib/unistdio/u16-snprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SNPRINTF u16_snprintf +#define VSNPRINTF u16_vsnprintf +#define FCHAR_T char +#define DCHAR_T uint16_t +#include "u-snprintf.h" diff --git a/lib/unistdio/u16-sprintf.c b/lib/unistdio/u16-sprintf.c new file mode 100644 index 000000000..1e703571c --- /dev/null +++ b/lib/unistdio/u16-sprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SPRINTF u16_sprintf +#define VSPRINTF u16_vsprintf +#define FCHAR_T char +#define DCHAR_T uint16_t +#include "u-sprintf.h" diff --git a/lib/unistdio/u16-u16-asnprintf.c b/lib/unistdio/u16-u16-asnprintf.c new file mode 100644 index 000000000..a7402351f --- /dev/null +++ b/lib/unistdio/u16-u16-asnprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASNPRINTF u16_u16_asnprintf +#define VASNPRINTF u16_u16_vasnprintf +#define FCHAR_T uint16_t +#define DCHAR_T uint16_t +#include "u-asnprintf.h" diff --git a/lib/unistdio/u16-u16-asprintf.c b/lib/unistdio/u16-u16-asprintf.c new file mode 100644 index 000000000..5b7e8a11c --- /dev/null +++ b/lib/unistdio/u16-u16-asprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASPRINTF u16_u16_asprintf +#define VASPRINTF u16_u16_vasprintf +#define FCHAR_T uint16_t +#define DCHAR_T uint16_t +#include "u-asprintf.h" diff --git a/lib/unistdio/u16-u16-snprintf.c b/lib/unistdio/u16-u16-snprintf.c new file mode 100644 index 000000000..ac6852e0c --- /dev/null +++ b/lib/unistdio/u16-u16-snprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SNPRINTF u16_u16_snprintf +#define VSNPRINTF u16_u16_vsnprintf +#define FCHAR_T uint16_t +#define DCHAR_T uint16_t +#include "u-snprintf.h" diff --git a/lib/unistdio/u16-u16-sprintf.c b/lib/unistdio/u16-u16-sprintf.c new file mode 100644 index 000000000..bf50f4898 --- /dev/null +++ b/lib/unistdio/u16-u16-sprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SPRINTF u16_u16_sprintf +#define VSPRINTF u16_u16_vsprintf +#define FCHAR_T uint16_t +#define DCHAR_T uint16_t +#include "u-sprintf.h" diff --git a/lib/unistdio/u16-u16-vasnprintf.c b/lib/unistdio/u16-u16-vasnprintf.c new file mode 100644 index 000000000..3f30cab80 --- /dev/null +++ b/lib/unistdio/u16-u16-vasnprintf.c @@ -0,0 +1,51 @@ +/* Formatted output to UTF-16 strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#include + +/* Specification. */ +#include "unistdio.h" + +#include "uniconv.h" +#include "unistr.h" +#include "unistdio/u-printf-parse.h" + +#define VASNPRINTF u16_u16_vasnprintf +#define FCHAR_T uint16_t +#define DIRECTIVE u16_directive +#define DIRECTIVES u16_directives +#define PRINTF_PARSE u16_printf_parse +#define DCHAR_T uint16_t +#define DCHAR_T_IS_UINT16_T 1 +#define DCHAR_CPY u16_cpy +#define DCHAR_SET u16_set +#define DCHAR_MBSNLEN u16_mbsnlen +#define DCHAR_IS_UINT16_T 1 +#define U8_TO_DCHAR u8_to_u16 +#define U32_TO_DCHAR u32_to_u16 +#define DCHAR_CONV_FROM_ENCODING u16_conv_from_encoding +#define TCHAR_T char +#include "vasnprintf.c" diff --git a/lib/unistdio/u16-u16-vasprintf.c b/lib/unistdio/u16-u16-vasprintf.c new file mode 100644 index 000000000..aff978eb0 --- /dev/null +++ b/lib/unistdio/u16-u16-vasprintf.c @@ -0,0 +1,32 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include + +#define VASPRINTF u16_u16_vasprintf +#define VASNPRINTF u16_u16_vasnprintf +#define FCHAR_T uint16_t +#define DCHAR_T uint16_t +#include "u-vasprintf.h" diff --git a/lib/unistdio/u16-u16-vsnprintf.c b/lib/unistdio/u16-u16-vsnprintf.c new file mode 100644 index 000000000..291dc9576 --- /dev/null +++ b/lib/unistdio/u16-u16-vsnprintf.c @@ -0,0 +1,35 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include "unistr.h" + +#define VSNPRINTF u16_u16_vsnprintf +#define VASNPRINTF u16_u16_vasnprintf +#define FCHAR_T uint16_t +#define DCHAR_T uint16_t +#define DCHAR_CPY u16_cpy +#include "u-vsnprintf.h" diff --git a/lib/unistdio/u16-u16-vsprintf.c b/lib/unistdio/u16-u16-vsprintf.c new file mode 100644 index 000000000..99843924e --- /dev/null +++ b/lib/unistdio/u16-u16-vsprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSPRINTF u16_u16_vsprintf +#define VASNPRINTF u16_u16_vasnprintf +#define FCHAR_T uint16_t +#define DCHAR_T uint16_t +#include "u-vsprintf.h" diff --git a/lib/unistdio/u16-vasnprintf.c b/lib/unistdio/u16-vasnprintf.c new file mode 100644 index 000000000..fcdbbb16e --- /dev/null +++ b/lib/unistdio/u16-vasnprintf.c @@ -0,0 +1,52 @@ +/* Formatted output to UTF-16 strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#include + +/* Specification. */ +#include "unistdio.h" + +#include "uniconv.h" +#include "unistr.h" +#include "unistdio/u-printf-parse.h" + +#define VASNPRINTF u16_vasnprintf +#define FCHAR_T char +#define DIRECTIVE char_directive +#define DIRECTIVES char_directives +#define ASCII_ONLY 1 +#define PRINTF_PARSE ulc_printf_parse +#define DCHAR_T uint16_t +#define DCHAR_T_IS_UINT16_T 1 +#define DCHAR_CPY u16_cpy +#define DCHAR_SET u16_set +#define DCHAR_MBSNLEN u16_mbsnlen +#define DCHAR_IS_UINT16_T 1 +#define U8_TO_DCHAR u8_to_u16 +#define U32_TO_DCHAR u32_to_u16 +#define DCHAR_CONV_FROM_ENCODING u16_conv_from_encoding +#define TCHAR_T char +#include "vasnprintf.c" diff --git a/lib/unistdio/u16-vasprintf.c b/lib/unistdio/u16-vasprintf.c new file mode 100644 index 000000000..a40eb9a8d --- /dev/null +++ b/lib/unistdio/u16-vasprintf.c @@ -0,0 +1,32 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include + +#define VASPRINTF u16_vasprintf +#define VASNPRINTF u16_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint16_t +#include "u-vasprintf.h" diff --git a/lib/unistdio/u16-vsnprintf.c b/lib/unistdio/u16-vsnprintf.c new file mode 100644 index 000000000..272416766 --- /dev/null +++ b/lib/unistdio/u16-vsnprintf.c @@ -0,0 +1,35 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include "unistr.h" + +#define VSNPRINTF u16_vsnprintf +#define VASNPRINTF u16_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint16_t +#define DCHAR_CPY u16_cpy +#include "u-vsnprintf.h" diff --git a/lib/unistdio/u16-vsprintf.c b/lib/unistdio/u16-vsprintf.c new file mode 100644 index 000000000..922ad2f17 --- /dev/null +++ b/lib/unistdio/u16-vsprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSPRINTF u16_vsprintf +#define VASNPRINTF u16_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint16_t +#include "u-vsprintf.h" diff --git a/lib/unistdio/u32-asnprintf.c b/lib/unistdio/u32-asnprintf.c new file mode 100644 index 000000000..8e19b5530 --- /dev/null +++ b/lib/unistdio/u32-asnprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASNPRINTF u32_asnprintf +#define VASNPRINTF u32_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint32_t +#include "u-asnprintf.h" diff --git a/lib/unistdio/u32-asprintf.c b/lib/unistdio/u32-asprintf.c new file mode 100644 index 000000000..d6bac1172 --- /dev/null +++ b/lib/unistdio/u32-asprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASPRINTF u32_asprintf +#define VASPRINTF u32_vasprintf +#define FCHAR_T char +#define DCHAR_T uint32_t +#include "u-asprintf.h" diff --git a/lib/unistdio/u32-printf-parse.c b/lib/unistdio/u32-printf-parse.c new file mode 100644 index 000000000..156a00f26 --- /dev/null +++ b/lib/unistdio/u32-printf-parse.c @@ -0,0 +1,28 @@ +/* Formatted output to strings. + Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio/u-printf-parse.h" + +#define PRINTF_PARSE u32_printf_parse +#define CHAR_T uint32_t +#define DIRECTIVE u32_directive +#define DIRECTIVES u32_directives +#include "printf-parse.c" diff --git a/lib/unistdio/u32-snprintf.c b/lib/unistdio/u32-snprintf.c new file mode 100644 index 000000000..84d77fefa --- /dev/null +++ b/lib/unistdio/u32-snprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SNPRINTF u32_snprintf +#define VSNPRINTF u32_vsnprintf +#define FCHAR_T char +#define DCHAR_T uint32_t +#include "u-snprintf.h" diff --git a/lib/unistdio/u32-sprintf.c b/lib/unistdio/u32-sprintf.c new file mode 100644 index 000000000..440b9a46f --- /dev/null +++ b/lib/unistdio/u32-sprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SPRINTF u32_sprintf +#define VSPRINTF u32_vsprintf +#define FCHAR_T char +#define DCHAR_T uint32_t +#include "u-sprintf.h" diff --git a/lib/unistdio/u32-u32-asnprintf.c b/lib/unistdio/u32-u32-asnprintf.c new file mode 100644 index 000000000..351207574 --- /dev/null +++ b/lib/unistdio/u32-u32-asnprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASNPRINTF u32_u32_asnprintf +#define VASNPRINTF u32_u32_vasnprintf +#define FCHAR_T uint32_t +#define DCHAR_T uint32_t +#include "u-asnprintf.h" diff --git a/lib/unistdio/u32-u32-asprintf.c b/lib/unistdio/u32-u32-asprintf.c new file mode 100644 index 000000000..31cf7589c --- /dev/null +++ b/lib/unistdio/u32-u32-asprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASPRINTF u32_u32_asprintf +#define VASPRINTF u32_u32_vasprintf +#define FCHAR_T uint32_t +#define DCHAR_T uint32_t +#include "u-asprintf.h" diff --git a/lib/unistdio/u32-u32-snprintf.c b/lib/unistdio/u32-u32-snprintf.c new file mode 100644 index 000000000..698c54e70 --- /dev/null +++ b/lib/unistdio/u32-u32-snprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SNPRINTF u32_u32_snprintf +#define VSNPRINTF u32_u32_vsnprintf +#define FCHAR_T uint32_t +#define DCHAR_T uint32_t +#include "u-snprintf.h" diff --git a/lib/unistdio/u32-u32-sprintf.c b/lib/unistdio/u32-u32-sprintf.c new file mode 100644 index 000000000..896badcdd --- /dev/null +++ b/lib/unistdio/u32-u32-sprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SPRINTF u32_u32_sprintf +#define VSPRINTF u32_u32_vsprintf +#define FCHAR_T uint32_t +#define DCHAR_T uint32_t +#include "u-sprintf.h" diff --git a/lib/unistdio/u32-u32-vasnprintf.c b/lib/unistdio/u32-u32-vasnprintf.c new file mode 100644 index 000000000..8a8c59f31 --- /dev/null +++ b/lib/unistdio/u32-u32-vasnprintf.c @@ -0,0 +1,51 @@ +/* Formatted output to UTF-32 strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#include + +/* Specification. */ +#include "unistdio.h" + +#include "uniconv.h" +#include "unistr.h" +#include "unistdio/u-printf-parse.h" + +#define VASNPRINTF u32_u32_vasnprintf +#define FCHAR_T uint32_t +#define DIRECTIVE u32_directive +#define DIRECTIVES u32_directives +#define PRINTF_PARSE u32_printf_parse +#define DCHAR_T uint32_t +#define DCHAR_T_IS_UINT32_T 1 +#define DCHAR_CPY u32_cpy +#define DCHAR_SET u32_set +#define DCHAR_MBSNLEN u32_mbsnlen +#define DCHAR_IS_UINT32_T 1 +#define U8_TO_DCHAR u8_to_u32 +#define U16_TO_DCHAR u16_to_u32 +#define DCHAR_CONV_FROM_ENCODING u32_conv_from_encoding +#define TCHAR_T char +#include "vasnprintf.c" diff --git a/lib/unistdio/u32-u32-vasprintf.c b/lib/unistdio/u32-u32-vasprintf.c new file mode 100644 index 000000000..d2f5616b2 --- /dev/null +++ b/lib/unistdio/u32-u32-vasprintf.c @@ -0,0 +1,32 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include + +#define VASPRINTF u32_u32_vasprintf +#define VASNPRINTF u32_u32_vasnprintf +#define FCHAR_T uint32_t +#define DCHAR_T uint32_t +#include "u-vasprintf.h" diff --git a/lib/unistdio/u32-u32-vsnprintf.c b/lib/unistdio/u32-u32-vsnprintf.c new file mode 100644 index 000000000..cef01c727 --- /dev/null +++ b/lib/unistdio/u32-u32-vsnprintf.c @@ -0,0 +1,35 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include "unistr.h" + +#define VSNPRINTF u32_u32_vsnprintf +#define VASNPRINTF u32_u32_vasnprintf +#define FCHAR_T uint32_t +#define DCHAR_T uint32_t +#define DCHAR_CPY u32_cpy +#include "u-vsnprintf.h" diff --git a/lib/unistdio/u32-u32-vsprintf.c b/lib/unistdio/u32-u32-vsprintf.c new file mode 100644 index 000000000..96b071c5e --- /dev/null +++ b/lib/unistdio/u32-u32-vsprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSPRINTF u32_u32_vsprintf +#define VASNPRINTF u32_u32_vasnprintf +#define FCHAR_T uint32_t +#define DCHAR_T uint32_t +#include "u-vsprintf.h" diff --git a/lib/unistdio/u32-vasnprintf.c b/lib/unistdio/u32-vasnprintf.c new file mode 100644 index 000000000..25bdb4e8a --- /dev/null +++ b/lib/unistdio/u32-vasnprintf.c @@ -0,0 +1,52 @@ +/* Formatted output to UTF-32 strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#include + +/* Specification. */ +#include "unistdio.h" + +#include "uniconv.h" +#include "unistr.h" +#include "unistdio/u-printf-parse.h" + +#define VASNPRINTF u32_vasnprintf +#define FCHAR_T char +#define DIRECTIVE char_directive +#define DIRECTIVES char_directives +#define ASCII_ONLY 1 +#define PRINTF_PARSE ulc_printf_parse +#define DCHAR_T uint32_t +#define DCHAR_T_IS_UINT32_T 1 +#define DCHAR_CPY u32_cpy +#define DCHAR_SET u32_set +#define DCHAR_MBSNLEN u32_mbsnlen +#define DCHAR_IS_UINT32_T 1 +#define U8_TO_DCHAR u8_to_u32 +#define U16_TO_DCHAR u16_to_u32 +#define DCHAR_CONV_FROM_ENCODING u32_conv_from_encoding +#define TCHAR_T char +#include "vasnprintf.c" diff --git a/lib/unistdio/u32-vasprintf.c b/lib/unistdio/u32-vasprintf.c new file mode 100644 index 000000000..f84d5e0b6 --- /dev/null +++ b/lib/unistdio/u32-vasprintf.c @@ -0,0 +1,32 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include + +#define VASPRINTF u32_vasprintf +#define VASNPRINTF u32_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint32_t +#include "u-vasprintf.h" diff --git a/lib/unistdio/u32-vsnprintf.c b/lib/unistdio/u32-vsnprintf.c new file mode 100644 index 000000000..025226532 --- /dev/null +++ b/lib/unistdio/u32-vsnprintf.c @@ -0,0 +1,35 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include "unistr.h" + +#define VSNPRINTF u32_vsnprintf +#define VASNPRINTF u32_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint32_t +#define DCHAR_CPY u32_cpy +#include "u-vsnprintf.h" diff --git a/lib/unistdio/u32-vsprintf.c b/lib/unistdio/u32-vsprintf.c new file mode 100644 index 000000000..923c8c625 --- /dev/null +++ b/lib/unistdio/u32-vsprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSPRINTF u32_vsprintf +#define VASNPRINTF u32_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint32_t +#include "u-vsprintf.h" diff --git a/lib/unistdio/u8-asnprintf.c b/lib/unistdio/u8-asnprintf.c new file mode 100644 index 000000000..8e4802c9d --- /dev/null +++ b/lib/unistdio/u8-asnprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASNPRINTF u8_asnprintf +#define VASNPRINTF u8_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint8_t +#include "u-asnprintf.h" diff --git a/lib/unistdio/u8-asprintf.c b/lib/unistdio/u8-asprintf.c new file mode 100644 index 000000000..3ee469117 --- /dev/null +++ b/lib/unistdio/u8-asprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASPRINTF u8_asprintf +#define VASPRINTF u8_vasprintf +#define FCHAR_T char +#define DCHAR_T uint8_t +#include "u-asprintf.h" diff --git a/lib/unistdio/u8-printf-parse.c b/lib/unistdio/u8-printf-parse.c new file mode 100644 index 000000000..606c20b41 --- /dev/null +++ b/lib/unistdio/u8-printf-parse.c @@ -0,0 +1,28 @@ +/* Formatted output to strings. + Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio/u-printf-parse.h" + +#define PRINTF_PARSE u8_printf_parse +#define CHAR_T uint8_t +#define DIRECTIVE u8_directive +#define DIRECTIVES u8_directives +#include "printf-parse.c" diff --git a/lib/unistdio/u8-snprintf.c b/lib/unistdio/u8-snprintf.c new file mode 100644 index 000000000..73913313d --- /dev/null +++ b/lib/unistdio/u8-snprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SNPRINTF u8_snprintf +#define VSNPRINTF u8_vsnprintf +#define FCHAR_T char +#define DCHAR_T uint8_t +#include "u-snprintf.h" diff --git a/lib/unistdio/u8-sprintf.c b/lib/unistdio/u8-sprintf.c new file mode 100644 index 000000000..e07895925 --- /dev/null +++ b/lib/unistdio/u8-sprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SPRINTF u8_sprintf +#define VSPRINTF u8_vsprintf +#define FCHAR_T char +#define DCHAR_T uint8_t +#include "u-sprintf.h" diff --git a/lib/unistdio/u8-u8-asnprintf.c b/lib/unistdio/u8-u8-asnprintf.c new file mode 100644 index 000000000..096cdc29f --- /dev/null +++ b/lib/unistdio/u8-u8-asnprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASNPRINTF u8_u8_asnprintf +#define VASNPRINTF u8_u8_vasnprintf +#define FCHAR_T uint8_t +#define DCHAR_T uint8_t +#include "u-asnprintf.h" diff --git a/lib/unistdio/u8-u8-asprintf.c b/lib/unistdio/u8-u8-asprintf.c new file mode 100644 index 000000000..55ae8557f --- /dev/null +++ b/lib/unistdio/u8-u8-asprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASPRINTF u8_u8_asprintf +#define VASPRINTF u8_u8_vasprintf +#define FCHAR_T uint8_t +#define DCHAR_T uint8_t +#include "u-asprintf.h" diff --git a/lib/unistdio/u8-u8-snprintf.c b/lib/unistdio/u8-u8-snprintf.c new file mode 100644 index 000000000..954654c88 --- /dev/null +++ b/lib/unistdio/u8-u8-snprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SNPRINTF u8_u8_snprintf +#define VSNPRINTF u8_u8_vsnprintf +#define FCHAR_T uint8_t +#define DCHAR_T uint8_t +#include "u-snprintf.h" diff --git a/lib/unistdio/u8-u8-sprintf.c b/lib/unistdio/u8-u8-sprintf.c new file mode 100644 index 000000000..7d655e20a --- /dev/null +++ b/lib/unistdio/u8-u8-sprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SPRINTF u8_u8_sprintf +#define VSPRINTF u8_u8_vsprintf +#define FCHAR_T uint8_t +#define DCHAR_T uint8_t +#include "u-sprintf.h" diff --git a/lib/unistdio/u8-u8-vasnprintf.c b/lib/unistdio/u8-u8-vasnprintf.c new file mode 100644 index 000000000..da5a99e07 --- /dev/null +++ b/lib/unistdio/u8-u8-vasnprintf.c @@ -0,0 +1,51 @@ +/* Formatted output to UTF-8 strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#include + +/* Specification. */ +#include "unistdio.h" + +#include "uniconv.h" +#include "unistr.h" +#include "unistdio/u-printf-parse.h" + +#define VASNPRINTF u8_u8_vasnprintf +#define FCHAR_T uint8_t +#define DIRECTIVE u8_directive +#define DIRECTIVES u8_directives +#define PRINTF_PARSE u8_printf_parse +#define DCHAR_T uint8_t +#define DCHAR_T_IS_UINT8_T 1 +#define DCHAR_CPY u8_cpy +#define DCHAR_SET u8_set +#define DCHAR_MBSNLEN u8_mbsnlen +#define DCHAR_IS_UINT8_T 1 +#define U16_TO_DCHAR u16_to_u8 +#define U32_TO_DCHAR u32_to_u8 +#define DCHAR_CONV_FROM_ENCODING u8_conv_from_encoding +#define TCHAR_T char +#include "vasnprintf.c" diff --git a/lib/unistdio/u8-u8-vasprintf.c b/lib/unistdio/u8-u8-vasprintf.c new file mode 100644 index 000000000..7ebc3c02e --- /dev/null +++ b/lib/unistdio/u8-u8-vasprintf.c @@ -0,0 +1,32 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include + +#define VASPRINTF u8_u8_vasprintf +#define VASNPRINTF u8_u8_vasnprintf +#define FCHAR_T uint8_t +#define DCHAR_T uint8_t +#include "u-vasprintf.h" diff --git a/lib/unistdio/u8-u8-vsnprintf.c b/lib/unistdio/u8-u8-vsnprintf.c new file mode 100644 index 000000000..94e0127b9 --- /dev/null +++ b/lib/unistdio/u8-u8-vsnprintf.c @@ -0,0 +1,35 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include "unistr.h" + +#define VSNPRINTF u8_u8_vsnprintf +#define VASNPRINTF u8_u8_vasnprintf +#define FCHAR_T uint8_t +#define DCHAR_T uint8_t +#define DCHAR_CPY u8_cpy +#include "u-vsnprintf.h" diff --git a/lib/unistdio/u8-u8-vsprintf.c b/lib/unistdio/u8-u8-vsprintf.c new file mode 100644 index 000000000..fbabcd0af --- /dev/null +++ b/lib/unistdio/u8-u8-vsprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSPRINTF u8_u8_vsprintf +#define VASNPRINTF u8_u8_vasnprintf +#define FCHAR_T uint8_t +#define DCHAR_T uint8_t +#include "u-vsprintf.h" diff --git a/lib/unistdio/u8-vasnprintf.c b/lib/unistdio/u8-vasnprintf.c new file mode 100644 index 000000000..f6dbca113 --- /dev/null +++ b/lib/unistdio/u8-vasnprintf.c @@ -0,0 +1,52 @@ +/* Formatted output to UTF-8 strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#include + +/* Specification. */ +#include "unistdio.h" + +#include "uniconv.h" +#include "unistr.h" +#include "unistdio/u-printf-parse.h" + +#define VASNPRINTF u8_vasnprintf +#define FCHAR_T char +#define DIRECTIVE char_directive +#define DIRECTIVES char_directives +#define ASCII_ONLY 1 +#define PRINTF_PARSE ulc_printf_parse +#define DCHAR_T uint8_t +#define DCHAR_T_IS_UINT8_T 1 +#define DCHAR_CPY u8_cpy +#define DCHAR_SET u8_set +#define DCHAR_MBSNLEN u8_mbsnlen +#define DCHAR_IS_UINT8_T 1 +#define U16_TO_DCHAR u16_to_u8 +#define U32_TO_DCHAR u32_to_u8 +#define DCHAR_CONV_FROM_ENCODING u8_conv_from_encoding +#define TCHAR_T char +#include "vasnprintf.c" diff --git a/lib/unistdio/u8-vasprintf.c b/lib/unistdio/u8-vasprintf.c new file mode 100644 index 000000000..9b8101c5b --- /dev/null +++ b/lib/unistdio/u8-vasprintf.c @@ -0,0 +1,32 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include + +#define VASPRINTF u8_vasprintf +#define VASNPRINTF u8_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint8_t +#include "u-vasprintf.h" diff --git a/lib/unistdio/u8-vsnprintf.c b/lib/unistdio/u8-vsnprintf.c new file mode 100644 index 000000000..cbeb11ae2 --- /dev/null +++ b/lib/unistdio/u8-vsnprintf.c @@ -0,0 +1,35 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include "unistr.h" + +#define VSNPRINTF u8_vsnprintf +#define VASNPRINTF u8_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint8_t +#define DCHAR_CPY u8_cpy +#include "u-vsnprintf.h" diff --git a/lib/unistdio/u8-vsprintf.c b/lib/unistdio/u8-vsprintf.c new file mode 100644 index 000000000..482a1bb87 --- /dev/null +++ b/lib/unistdio/u8-vsprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSPRINTF u8_vsprintf +#define VASNPRINTF u8_vasnprintf +#define FCHAR_T char +#define DCHAR_T uint8_t +#include "u-vsprintf.h" diff --git a/lib/unistdio/ulc-asnprintf.c b/lib/unistdio/ulc-asnprintf.c new file mode 100644 index 000000000..ccf752210 --- /dev/null +++ b/lib/unistdio/ulc-asnprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASNPRINTF ulc_asnprintf +#define VASNPRINTF ulc_vasnprintf +#define FCHAR_T char +#define DCHAR_T char +#include "u-asnprintf.h" diff --git a/lib/unistdio/ulc-asprintf.c b/lib/unistdio/ulc-asprintf.c new file mode 100644 index 000000000..6ea0c2e97 --- /dev/null +++ b/lib/unistdio/ulc-asprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define ASPRINTF ulc_asprintf +#define VASPRINTF ulc_vasprintf +#define FCHAR_T char +#define DCHAR_T char +#include "u-asprintf.h" diff --git a/lib/unistdio/ulc-fprintf.c b/lib/unistdio/ulc-fprintf.c new file mode 100644 index 000000000..c7d0ba6cf --- /dev/null +++ b/lib/unistdio/ulc-fprintf.c @@ -0,0 +1,80 @@ +/* Formatted output to a stream. + Copyright (C) 2004, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#include "fseterr.h" + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +/* Print formatted output to the stream FP. + Return string length of formatted string. On error, return a negative + value. */ +int +ulc_fprintf (FILE *fp, const char *format, ...) +{ + char buf[2000]; + char *output; + size_t len; + size_t lenbuf = sizeof (buf); + va_list args; + + va_start (args, format); + output = ulc_vasnprintf (buf, &lenbuf, format, args); + len = lenbuf; + va_end (args); + + if (!output) + { + fseterr (fp); + return -1; + } + + if (fwrite (output, 1, len, fp) < len) + { + if (output != buf) + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } + return -1; + } + + if (len > INT_MAX) + { + errno = EOVERFLOW; + fseterr (fp); + return -1; + } + + return len; +} diff --git a/lib/unistdio/ulc-printf-parse.c b/lib/unistdio/ulc-printf-parse.c new file mode 100644 index 000000000..ef2ecc4da --- /dev/null +++ b/lib/unistdio/ulc-printf-parse.c @@ -0,0 +1,29 @@ +/* Formatted output to strings. + Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio/u-printf-parse.h" + +#define PRINTF_PARSE ulc_printf_parse +#define CHAR_T char +#define CHAR_T_ONLY_ASCII 1 +#define DIRECTIVE char_directive +#define DIRECTIVES char_directives +#include "printf-parse.c" diff --git a/lib/unistdio/ulc-snprintf.c b/lib/unistdio/ulc-snprintf.c new file mode 100644 index 000000000..0df9d6c69 --- /dev/null +++ b/lib/unistdio/ulc-snprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SNPRINTF ulc_snprintf +#define VSNPRINTF ulc_vsnprintf +#define FCHAR_T char +#define DCHAR_T char +#include "u-snprintf.h" diff --git a/lib/unistdio/ulc-sprintf.c b/lib/unistdio/ulc-sprintf.c new file mode 100644 index 000000000..3a7bd00f4 --- /dev/null +++ b/lib/unistdio/ulc-sprintf.c @@ -0,0 +1,30 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include + +#define SPRINTF ulc_sprintf +#define VSPRINTF ulc_vsprintf +#define FCHAR_T char +#define DCHAR_T char +#include "u-sprintf.h" diff --git a/lib/unistdio/ulc-vasnprintf.c b/lib/unistdio/ulc-vasnprintf.c new file mode 100644 index 000000000..63dd3f11c --- /dev/null +++ b/lib/unistdio/ulc-vasnprintf.c @@ -0,0 +1,48 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#include +#include + +/* Specification. */ +#include "unistdio.h" + +#include "uniconv.h" +#include "unistr.h" +#include "unistdio/u-printf-parse.h" + +#define VASNPRINTF ulc_vasnprintf +#define FCHAR_T char +#define DIRECTIVE char_directive +#define DIRECTIVES char_directives +#define FCHAR_T_ONLY_ASCII 1 +#define PRINTF_PARSE ulc_printf_parse +#define DCHAR_T char +#define DCHAR_CPY memcpy +#define DCHAR_SET memset +#define DCHAR_MBSNLEN mbsnlen +#define TCHAR_T char +#define DCHAR_IS_TCHAR 1 +#include "vasnprintf.c" diff --git a/lib/unistdio/ulc-vasprintf.c b/lib/unistdio/ulc-vasprintf.c new file mode 100644 index 000000000..3e057882f --- /dev/null +++ b/lib/unistdio/ulc-vasprintf.c @@ -0,0 +1,32 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include + +#define VASPRINTF ulc_vasprintf +#define VASNPRINTF ulc_vasnprintf +#define FCHAR_T char +#define DCHAR_T char +#include "u-vasprintf.h" diff --git a/lib/unistdio/ulc-vfprintf.c b/lib/unistdio/ulc-vfprintf.c new file mode 100644 index 000000000..9e6a2a9b5 --- /dev/null +++ b/lib/unistdio/ulc-vfprintf.c @@ -0,0 +1,77 @@ +/* Formatted output to a stream. + Copyright (C) 2004, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#include "fseterr.h" + +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + +/* Print formatted output to the stream FP. + Return string length of formatted string. On error, return a negative + value. */ +int +ulc_vfprintf (FILE *fp, const char *format, va_list args) +{ + char buf[2000]; + char *output; + size_t len; + size_t lenbuf = sizeof (buf); + + output = ulc_vasnprintf (buf, &lenbuf, format, args); + len = lenbuf; + + if (!output) + { + fseterr (fp); + return -1; + } + + if (fwrite (output, 1, len, fp) < len) + { + if (output != buf) + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } + return -1; + } + + if (len > INT_MAX) + { + errno = EOVERFLOW; + fseterr (fp); + return -1; + } + + return len; +} diff --git a/lib/unistdio/ulc-vsnprintf.c b/lib/unistdio/ulc-vsnprintf.c new file mode 100644 index 000000000..5cfc68702 --- /dev/null +++ b/lib/unistdio/ulc-vsnprintf.c @@ -0,0 +1,35 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSNPRINTF ulc_vsnprintf +#define VASNPRINTF ulc_vasnprintf +#define FCHAR_T char +#define DCHAR_T char +#define DCHAR_CPY memcpy +#include "u-vsnprintf.h" diff --git a/lib/unistdio/ulc-vsprintf.c b/lib/unistdio/ulc-vsprintf.c new file mode 100644 index 000000000..e077bd526 --- /dev/null +++ b/lib/unistdio/ulc-vsprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include + +/* Specification. */ +#include "unistdio.h" + +#include +#include +#include +#include +#include + +#define VSPRINTF ulc_vsprintf +#define VASNPRINTF ulc_vasnprintf +#define FCHAR_T char +#define DCHAR_T char +#include "u-vsprintf.h" diff --git a/modules/unistdio/base b/modules/unistdio/base new file mode 100644 index 000000000..290712b96 --- /dev/null +++ b/modules/unistdio/base @@ -0,0 +1,22 @@ +Description: +Base layer for formatted output to strings. + +Files: +lib/unistdio.h + +Depends-on: +unitypes + +configure.ac: + +Makefile.am: + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u-printf-args b/modules/unistdio/u-printf-args new file mode 100644 index 000000000..02478e5ce --- /dev/null +++ b/modules/unistdio/u-printf-args @@ -0,0 +1,28 @@ +Description: +Fetching a printf argument list. + +Files: +lib/unistdio/u-printf-args.h +lib/unistdio/u-printf-args.c +lib/printf-args.h +lib/printf-args.c +m4/vasnprintf.m4 + +Depends-on: +unitypes + +configure.ac: +gl_PREREQ_PRINTF_ARGS + +Makefile.am: +lib_SOURCES += unistdio/u-printf-args.c + +Include: +"unistdio/u-printf-args.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-asnprintf b/modules/unistdio/u16-asnprintf new file mode 100644 index 000000000..78355ac76 --- /dev/null +++ b/modules/unistdio/u16-asnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-16 string, with automatic memory allocation and +bounded output size. + +Files: +lib/unistdio/u16-asnprintf.c +lib/unistdio/u-asnprintf.h + +Depends-on: +unistdio/base +unistdio/u16-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-asnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-asnprintf-tests b/modules/unistdio/u16-asnprintf-tests new file mode 100644 index 000000000..e0d0ae47f --- /dev/null +++ b/modules/unistdio/u16-asnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u16-asnprintf1.c +tests/unistdio/test-u16-asnprintf1.h +tests/unistdio/test-u16-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-u16-asnprintf1 +check_PROGRAMS += test-u16-asnprintf1 +test_u16_asnprintf1_SOURCES = unistdio/test-u16-asnprintf1.c +test_u16_asnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u16-asprintf b/modules/unistdio/u16-asprintf new file mode 100644 index 000000000..edb2448fe --- /dev/null +++ b/modules/unistdio/u16-asprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-16 string, with automatic memory allocation. + +Files: +lib/unistdio/u16-asprintf.c +lib/unistdio/u-asprintf.h + +Depends-on: +unistdio/base +unistdio/u16-vasprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-asprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-printf-parse b/modules/unistdio/u16-printf-parse new file mode 100644 index 000000000..d892a3877 --- /dev/null +++ b/modules/unistdio/u16-printf-parse @@ -0,0 +1,30 @@ +Description: +Parsing an UTF-16 format string. + +Files: +lib/unistdio/u-printf-parse.h +lib/unistdio/u16-printf-parse.c +lib/printf-parse.h +lib/printf-parse.c +m4/vasnprintf.m4 + +Depends-on: +unistdio/u-printf-args +stdint +xsize + +configure.ac: +gl_PREREQ_PRINTF_PARSE + +Makefile.am: +lib_SOURCES += unistdio/u16-printf-parse.c + +Include: +"unistdio/u-printf-parse.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-snprintf b/modules/unistdio/u16-snprintf new file mode 100644 index 000000000..214afe544 --- /dev/null +++ b/modules/unistdio/u16-snprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length UTF-16 string. + +Files: +lib/unistdio/u16-snprintf.c +lib/unistdio/u-snprintf.h + +Depends-on: +unistdio/base +unistdio/u16-vsnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-snprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-sprintf b/modules/unistdio/u16-sprintf new file mode 100644 index 000000000..cf6e06ad5 --- /dev/null +++ b/modules/unistdio/u16-sprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-16 string. + +Files: +lib/unistdio/u16-sprintf.c +lib/unistdio/u-sprintf.h + +Depends-on: +unistdio/base +unistdio/u16-sprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-sprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-asnprintf b/modules/unistdio/u16-u16-asnprintf new file mode 100644 index 000000000..d1230b04f --- /dev/null +++ b/modules/unistdio/u16-u16-asnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-16 string, with automatic memory allocation and +bounded output size. + +Files: +lib/unistdio/u16-u16-asnprintf.c +lib/unistdio/u-asnprintf.h + +Depends-on: +unistdio/base +unistdio/u16-u16-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-asnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-asprintf b/modules/unistdio/u16-u16-asprintf new file mode 100644 index 000000000..abd44ed73 --- /dev/null +++ b/modules/unistdio/u16-u16-asprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-16 string, with automatic memory allocation. + +Files: +lib/unistdio/u16-u16-asprintf.c +lib/unistdio/u-asprintf.h + +Depends-on: +unistdio/base +unistdio/u16-u16-vasprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-asprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-snprintf b/modules/unistdio/u16-u16-snprintf new file mode 100644 index 000000000..0d78a404f --- /dev/null +++ b/modules/unistdio/u16-u16-snprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length UTF-16 string. + +Files: +lib/unistdio/u16-u16-snprintf.c +lib/unistdio/u-snprintf.h + +Depends-on: +unistdio/base +unistdio/u16-u16-vsnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-snprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-sprintf b/modules/unistdio/u16-u16-sprintf new file mode 100644 index 000000000..546e11b1a --- /dev/null +++ b/modules/unistdio/u16-u16-sprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-16 string. + +Files: +lib/unistdio/u16-u16-sprintf.c +lib/unistdio/u-sprintf.h + +Depends-on: +unistdio/base +unistdio/u16-u16-sprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-sprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-vasnprintf b/modules/unistdio/u16-u16-vasnprintf new file mode 100644 index 000000000..9b378457a --- /dev/null +++ b/modules/unistdio/u16-u16-vasnprintf @@ -0,0 +1,59 @@ +Description: +Formatted output to UTF-16 strings. + +Files: +lib/unistdio/u16-u16-vasnprintf.c +lib/vasnprintf.c +m4/vasnprintf.m4 +m4/printf.m4 +m4/wchar_t.m4 +m4/wint_t.m4 +m4/longlong.m4 +m4/intmax_t.m4 +m4/stdint_h.m4 +m4/inttypes_h.m4 +m4/eoverflow.m4 + +Depends-on: +unistdio/base +unistdio/u16-printf-parse +unistdio/u-printf-args +uniconv/u16-conv-from-enc +unistr/u16-cpy +unistr/u16-set +unistr/u16-mbsnlen +unistr/u8-to-u16 +unistr/u32-to-u16 +unistr/u8-strlen +unistr/u8-strmblen +unistr/u16-strlen +unistr/u16-strmblen +unistr/u32-strlen +unistr/u32-strmblen +isnan-nolibm +isnanl-nolibm +frexpl-nolibm +printf-frexp +printf-frexpl +signbit +fpucw +printf-safe +alloca-opt +localcharset +xsize + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_EXTRAS + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-vasnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-vasprintf b/modules/unistdio/u16-u16-vasprintf new file mode 100644 index 000000000..75a2531cc --- /dev/null +++ b/modules/unistdio/u16-u16-vasprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-16 string, with automatic memory allocation. + +Files: +lib/unistdio/u16-u16-vasprintf.c +lib/unistdio/u-vasprintf.h + +Depends-on: +unistdio/base +unistdio/u16-u16-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-vasprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-vsnprintf b/modules/unistdio/u16-u16-vsnprintf new file mode 100644 index 000000000..63be193b3 --- /dev/null +++ b/modules/unistdio/u16-u16-vsnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a fixed-length UTF-16 string. + +Files: +lib/unistdio/u16-u16-vsnprintf.c +lib/unistdio/u-vsnprintf.h + +Depends-on: +unistdio/base +unistdio/u16-u16-vasnprintf +unistr/u16-cpy + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-vsnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-u16-vsprintf b/modules/unistdio/u16-u16-vsprintf new file mode 100644 index 000000000..c61498002 --- /dev/null +++ b/modules/unistdio/u16-u16-vsprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-16 string. + +Files: +lib/unistdio/u16-u16-vsprintf.c +lib/unistdio/u-vsprintf.h + +Depends-on: +unistdio/base +unistdio/u16-u16-vasnprintf +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-u16-vsprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-vasnprintf b/modules/unistdio/u16-vasnprintf new file mode 100644 index 000000000..c923a1e6e --- /dev/null +++ b/modules/unistdio/u16-vasnprintf @@ -0,0 +1,59 @@ +Description: +Formatted output to UTF-16 strings. + +Files: +lib/unistdio/u16-vasnprintf.c +lib/vasnprintf.c +m4/vasnprintf.m4 +m4/printf.m4 +m4/wchar_t.m4 +m4/wint_t.m4 +m4/longlong.m4 +m4/intmax_t.m4 +m4/stdint_h.m4 +m4/inttypes_h.m4 +m4/eoverflow.m4 + +Depends-on: +unistdio/base +unistdio/ulc-printf-parse +unistdio/u-printf-args +uniconv/u16-conv-from-enc +unistr/u16-cpy +unistr/u16-set +unistr/u16-mbsnlen +unistr/u8-to-u16 +unistr/u32-to-u16 +unistr/u8-strlen +unistr/u8-strmblen +unistr/u16-strlen +unistr/u16-strmblen +unistr/u32-strlen +unistr/u32-strmblen +isnan-nolibm +isnanl-nolibm +frexpl-nolibm +printf-frexp +printf-frexpl +signbit +fpucw +printf-safe +alloca-opt +localcharset +xsize + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_EXTRAS + +Makefile.am: +lib_SOURCES += unistdio/u16-vasnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-vasnprintf-tests b/modules/unistdio/u16-vasnprintf-tests new file mode 100644 index 000000000..2fa60baf1 --- /dev/null +++ b/modules/unistdio/u16-vasnprintf-tests @@ -0,0 +1,31 @@ +Files: +tests/unistdio/test-u16-vasnprintf1.c +tests/unistdio/test-u16-asnprintf1.h +tests/unistdio/test-u16-printf1.h +tests/unistdio/test-u16-vasnprintf2.sh +tests/unistdio/test-u16-vasnprintf2.c +tests/unistdio/test-u16-vasnprintf3.sh +tests/unistdio/test-u16-vasnprintf3.c +m4/locale-fr.m4 + +Depends-on: +unistr/u16-cmp +unistr/u16-cpy +unistr/u16-strcmp +unistr/u16-strlen + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 + +Makefile.am: +TESTS += test-u16-vasnprintf1 unistdio/test-u16-vasnprintf2.sh unistdio/test-u16-vasnprintf3.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' +check_PROGRAMS += test-u16-vasnprintf1 test-u16-vasnprintf2 test-u16-vasnprintf3 +test_u16_vasnprintf1_SOURCES = unistdio/test-u16-vasnprintf1.c +test_u16_vasnprintf1_LDADD = $(LDADD) @LIBICONV@ +test_u16_vasnprintf2_SOURCES = unistdio/test-u16-vasnprintf2.c +test_u16_vasnprintf2_LDADD = $(LDADD) @LIBICONV@ +test_u16_vasnprintf3_SOURCES = unistdio/test-u16-vasnprintf3.c +test_u16_vasnprintf3_LDADD = $(LDADD) @LIBICONV@ +EXTRA_DIST += unistdio/test-u16-vasnprintf2.sh unistdio/test-u16-vasnprintf3.sh diff --git a/modules/unistdio/u16-vasprintf b/modules/unistdio/u16-vasprintf new file mode 100644 index 000000000..f2195ff2e --- /dev/null +++ b/modules/unistdio/u16-vasprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-16 string, with automatic memory allocation. + +Files: +lib/unistdio/u16-vasprintf.c +lib/unistdio/u-vasprintf.h + +Depends-on: +unistdio/base +unistdio/u16-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-vasprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-vasprintf-tests b/modules/unistdio/u16-vasprintf-tests new file mode 100644 index 000000000..f50bb4f19 --- /dev/null +++ b/modules/unistdio/u16-vasprintf-tests @@ -0,0 +1,13 @@ +Files: +tests/unistdio/test-u16-vasprintf1.c +tests/unistdio/test-u16-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-u16-vasprintf1 +check_PROGRAMS += test-u16-vasprintf1 +test_u16_vasprintf1_SOURCES = unistdio/test-u16-vasprintf1.c +test_u16_vasprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u16-vsnprintf b/modules/unistdio/u16-vsnprintf new file mode 100644 index 000000000..241b7bd80 --- /dev/null +++ b/modules/unistdio/u16-vsnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a fixed-length UTF-16 string. + +Files: +lib/unistdio/u16-vsnprintf.c +lib/unistdio/u-vsnprintf.h + +Depends-on: +unistdio/base +unistdio/u16-vasnprintf +unistr/u16-cpy + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-vsnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-vsnprintf-tests b/modules/unistdio/u16-vsnprintf-tests new file mode 100644 index 000000000..9a84acc59 --- /dev/null +++ b/modules/unistdio/u16-vsnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u16-vsnprintf1.c +tests/unistdio/test-u16-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-u16-vsnprintf1 +check_PROGRAMS += test-u16-vsnprintf1 +test_u16_vsnprintf1_SOURCES = unistdio/test-u16-vsnprintf1.c +test_u16_vsnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u16-vsprintf b/modules/unistdio/u16-vsprintf new file mode 100644 index 000000000..5070ef7b1 --- /dev/null +++ b/modules/unistdio/u16-vsprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-16 string. + +Files: +lib/unistdio/u16-vsprintf.c +lib/unistdio/u-vsprintf.h + +Depends-on: +unistdio/base +unistdio/u16-vasnprintf +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u16-vsprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u16-vsprintf-tests b/modules/unistdio/u16-vsprintf-tests new file mode 100644 index 000000000..49ad38b26 --- /dev/null +++ b/modules/unistdio/u16-vsprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u16-vsprintf1.c +tests/unistdio/test-u16-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-u16-vsprintf1 +check_PROGRAMS += test-u16-vsprintf1 +test_u16_vsprintf1_SOURCES = unistdio/test-u16-vsprintf1.c +test_u16_vsprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u32-asnprintf b/modules/unistdio/u32-asnprintf new file mode 100644 index 000000000..ec9160519 --- /dev/null +++ b/modules/unistdio/u32-asnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-32 string, with automatic memory allocation and +bounded output size. + +Files: +lib/unistdio/u32-asnprintf.c +lib/unistdio/u-asnprintf.h + +Depends-on: +unistdio/base +unistdio/u32-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-asnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-asnprintf-tests b/modules/unistdio/u32-asnprintf-tests new file mode 100644 index 000000000..f82797684 --- /dev/null +++ b/modules/unistdio/u32-asnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u32-asnprintf1.c +tests/unistdio/test-u32-asnprintf1.h +tests/unistdio/test-u32-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-u32-asnprintf1 +check_PROGRAMS += test-u32-asnprintf1 +test_u32_asnprintf1_SOURCES = unistdio/test-u32-asnprintf1.c +test_u32_asnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u32-asprintf b/modules/unistdio/u32-asprintf new file mode 100644 index 000000000..5b251d12b --- /dev/null +++ b/modules/unistdio/u32-asprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-32 string, with automatic memory allocation. + +Files: +lib/unistdio/u32-asprintf.c +lib/unistdio/u-asprintf.h + +Depends-on: +unistdio/base +unistdio/u32-vasprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-asprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-printf-parse b/modules/unistdio/u32-printf-parse new file mode 100644 index 000000000..cd506d5b0 --- /dev/null +++ b/modules/unistdio/u32-printf-parse @@ -0,0 +1,30 @@ +Description: +Parsing an UTF-32 format string. + +Files: +lib/unistdio/u-printf-parse.h +lib/unistdio/u32-printf-parse.c +lib/printf-parse.h +lib/printf-parse.c +m4/vasnprintf.m4 + +Depends-on: +unistdio/u-printf-args +stdint +xsize + +configure.ac: +gl_PREREQ_PRINTF_PARSE + +Makefile.am: +lib_SOURCES += unistdio/u32-printf-parse.c + +Include: +"unistdio/u-printf-parse.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-snprintf b/modules/unistdio/u32-snprintf new file mode 100644 index 000000000..54c783d9c --- /dev/null +++ b/modules/unistdio/u32-snprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length UTF-32 string. + +Files: +lib/unistdio/u32-snprintf.c +lib/unistdio/u-snprintf.h + +Depends-on: +unistdio/base +unistdio/u32-vsnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-snprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-sprintf b/modules/unistdio/u32-sprintf new file mode 100644 index 000000000..d47258807 --- /dev/null +++ b/modules/unistdio/u32-sprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-32 string. + +Files: +lib/unistdio/u32-sprintf.c +lib/unistdio/u-sprintf.h + +Depends-on: +unistdio/base +unistdio/u32-sprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-sprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-asnprintf b/modules/unistdio/u32-u32-asnprintf new file mode 100644 index 000000000..4f8dfc6fc --- /dev/null +++ b/modules/unistdio/u32-u32-asnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-32 string, with automatic memory allocation and +bounded output size. + +Files: +lib/unistdio/u32-u32-asnprintf.c +lib/unistdio/u-asnprintf.h + +Depends-on: +unistdio/base +unistdio/u32-u32-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-asnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-asprintf b/modules/unistdio/u32-u32-asprintf new file mode 100644 index 000000000..4dc5bf8d2 --- /dev/null +++ b/modules/unistdio/u32-u32-asprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-32 string, with automatic memory allocation. + +Files: +lib/unistdio/u32-u32-asprintf.c +lib/unistdio/u-asprintf.h + +Depends-on: +unistdio/base +unistdio/u32-u32-vasprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-asprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-snprintf b/modules/unistdio/u32-u32-snprintf new file mode 100644 index 000000000..6c355c970 --- /dev/null +++ b/modules/unistdio/u32-u32-snprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length UTF-32 string. + +Files: +lib/unistdio/u32-u32-snprintf.c +lib/unistdio/u-snprintf.h + +Depends-on: +unistdio/base +unistdio/u32-u32-vsnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-snprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-sprintf b/modules/unistdio/u32-u32-sprintf new file mode 100644 index 000000000..ffa2d0229 --- /dev/null +++ b/modules/unistdio/u32-u32-sprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-32 string. + +Files: +lib/unistdio/u32-u32-sprintf.c +lib/unistdio/u-sprintf.h + +Depends-on: +unistdio/base +unistdio/u32-u32-sprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-sprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-vasnprintf b/modules/unistdio/u32-u32-vasnprintf new file mode 100644 index 000000000..cdeb3ba64 --- /dev/null +++ b/modules/unistdio/u32-u32-vasnprintf @@ -0,0 +1,59 @@ +Description: +Formatted output to UTF-32 strings. + +Files: +lib/unistdio/u32-u32-vasnprintf.c +lib/vasnprintf.c +m4/vasnprintf.m4 +m4/printf.m4 +m4/wchar_t.m4 +m4/wint_t.m4 +m4/longlong.m4 +m4/intmax_t.m4 +m4/stdint_h.m4 +m4/inttypes_h.m4 +m4/eoverflow.m4 + +Depends-on: +unistdio/base +unistdio/u32-printf-parse +unistdio/u-printf-args +uniconv/u32-conv-from-enc +unistr/u32-cpy +unistr/u32-set +unistr/u32-mbsnlen +unistr/u8-to-u32 +unistr/u16-to-u32 +unistr/u8-strlen +unistr/u8-strmblen +unistr/u16-strlen +unistr/u16-strmblen +unistr/u32-strlen +unistr/u32-strmblen +isnan-nolibm +isnanl-nolibm +frexpl-nolibm +printf-frexp +printf-frexpl +signbit +fpucw +printf-safe +alloca-opt +localcharset +xsize + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_EXTRAS + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-vasnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-vasprintf b/modules/unistdio/u32-u32-vasprintf new file mode 100644 index 000000000..53f7b6667 --- /dev/null +++ b/modules/unistdio/u32-u32-vasprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-32 string, with automatic memory allocation. + +Files: +lib/unistdio/u32-u32-vasprintf.c +lib/unistdio/u-vasprintf.h + +Depends-on: +unistdio/base +unistdio/u32-u32-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-vasprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-vsnprintf b/modules/unistdio/u32-u32-vsnprintf new file mode 100644 index 000000000..0958d1105 --- /dev/null +++ b/modules/unistdio/u32-u32-vsnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a fixed-length UTF-32 string. + +Files: +lib/unistdio/u32-u32-vsnprintf.c +lib/unistdio/u-vsnprintf.h + +Depends-on: +unistdio/base +unistdio/u32-u32-vasnprintf +unistr/u32-cpy + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-vsnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-u32-vsprintf b/modules/unistdio/u32-u32-vsprintf new file mode 100644 index 000000000..17860125a --- /dev/null +++ b/modules/unistdio/u32-u32-vsprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-32 string. + +Files: +lib/unistdio/u32-u32-vsprintf.c +lib/unistdio/u-vsprintf.h + +Depends-on: +unistdio/base +unistdio/u32-u32-vasnprintf +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-u32-vsprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-vasnprintf b/modules/unistdio/u32-vasnprintf new file mode 100644 index 000000000..188294ca4 --- /dev/null +++ b/modules/unistdio/u32-vasnprintf @@ -0,0 +1,59 @@ +Description: +Formatted output to UTF-32 strings. + +Files: +lib/unistdio/u32-vasnprintf.c +lib/vasnprintf.c +m4/vasnprintf.m4 +m4/printf.m4 +m4/wchar_t.m4 +m4/wint_t.m4 +m4/longlong.m4 +m4/intmax_t.m4 +m4/stdint_h.m4 +m4/inttypes_h.m4 +m4/eoverflow.m4 + +Depends-on: +unistdio/base +unistdio/ulc-printf-parse +unistdio/u-printf-args +uniconv/u32-conv-from-enc +unistr/u32-cpy +unistr/u32-set +unistr/u32-mbsnlen +unistr/u8-to-u32 +unistr/u16-to-u32 +unistr/u8-strlen +unistr/u8-strmblen +unistr/u16-strlen +unistr/u16-strmblen +unistr/u32-strlen +unistr/u32-strmblen +isnan-nolibm +isnanl-nolibm +frexpl-nolibm +printf-frexp +printf-frexpl +signbit +fpucw +printf-safe +alloca-opt +localcharset +xsize + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_EXTRAS + +Makefile.am: +lib_SOURCES += unistdio/u32-vasnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-vasnprintf-tests b/modules/unistdio/u32-vasnprintf-tests new file mode 100644 index 000000000..396d3c4ae --- /dev/null +++ b/modules/unistdio/u32-vasnprintf-tests @@ -0,0 +1,31 @@ +Files: +tests/unistdio/test-u32-vasnprintf1.c +tests/unistdio/test-u32-asnprintf1.h +tests/unistdio/test-u32-printf1.h +tests/unistdio/test-u32-vasnprintf2.sh +tests/unistdio/test-u32-vasnprintf2.c +tests/unistdio/test-u32-vasnprintf3.sh +tests/unistdio/test-u32-vasnprintf3.c +m4/locale-fr.m4 + +Depends-on: +unistr/u32-cmp +unistr/u32-cpy +unistr/u32-strcmp +unistr/u32-strlen + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 + +Makefile.am: +TESTS += test-u32-vasnprintf1 unistdio/test-u32-vasnprintf2.sh unistdio/test-u32-vasnprintf3.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' +check_PROGRAMS += test-u32-vasnprintf1 test-u32-vasnprintf2 test-u32-vasnprintf3 +test_u32_vasnprintf1_SOURCES = unistdio/test-u32-vasnprintf1.c +test_u32_vasnprintf1_LDADD = $(LDADD) @LIBICONV@ +test_u32_vasnprintf2_SOURCES = unistdio/test-u32-vasnprintf2.c +test_u32_vasnprintf2_LDADD = $(LDADD) @LIBICONV@ +test_u32_vasnprintf3_SOURCES = unistdio/test-u32-vasnprintf3.c +test_u32_vasnprintf3_LDADD = $(LDADD) @LIBICONV@ +EXTRA_DIST += unistdio/test-u32-vasnprintf2.sh unistdio/test-u32-vasnprintf3.sh diff --git a/modules/unistdio/u32-vasprintf b/modules/unistdio/u32-vasprintf new file mode 100644 index 000000000..cc5a7c0fd --- /dev/null +++ b/modules/unistdio/u32-vasprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-32 string, with automatic memory allocation. + +Files: +lib/unistdio/u32-vasprintf.c +lib/unistdio/u-vasprintf.h + +Depends-on: +unistdio/base +unistdio/u32-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-vasprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-vasprintf-tests b/modules/unistdio/u32-vasprintf-tests new file mode 100644 index 000000000..6d85b0f1f --- /dev/null +++ b/modules/unistdio/u32-vasprintf-tests @@ -0,0 +1,13 @@ +Files: +tests/unistdio/test-u32-vasprintf1.c +tests/unistdio/test-u32-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-u32-vasprintf1 +check_PROGRAMS += test-u32-vasprintf1 +test_u32_vasprintf1_SOURCES = unistdio/test-u32-vasprintf1.c +test_u32_vasprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u32-vsnprintf b/modules/unistdio/u32-vsnprintf new file mode 100644 index 000000000..88d347111 --- /dev/null +++ b/modules/unistdio/u32-vsnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a fixed-length UTF-32 string. + +Files: +lib/unistdio/u32-vsnprintf.c +lib/unistdio/u-vsnprintf.h + +Depends-on: +unistdio/base +unistdio/u32-vasnprintf +unistr/u32-cpy + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-vsnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-vsnprintf-tests b/modules/unistdio/u32-vsnprintf-tests new file mode 100644 index 000000000..e183f7535 --- /dev/null +++ b/modules/unistdio/u32-vsnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u32-vsnprintf1.c +tests/unistdio/test-u32-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-u32-vsnprintf1 +check_PROGRAMS += test-u32-vsnprintf1 +test_u32_vsnprintf1_SOURCES = unistdio/test-u32-vsnprintf1.c +test_u32_vsnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u32-vsprintf b/modules/unistdio/u32-vsprintf new file mode 100644 index 000000000..d6960883d --- /dev/null +++ b/modules/unistdio/u32-vsprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-32 string. + +Files: +lib/unistdio/u32-vsprintf.c +lib/unistdio/u-vsprintf.h + +Depends-on: +unistdio/base +unistdio/u32-vasnprintf +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u32-vsprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u32-vsprintf-tests b/modules/unistdio/u32-vsprintf-tests new file mode 100644 index 000000000..af1941e8f --- /dev/null +++ b/modules/unistdio/u32-vsprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u32-vsprintf1.c +tests/unistdio/test-u32-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-u32-vsprintf1 +check_PROGRAMS += test-u32-vsprintf1 +test_u32_vsprintf1_SOURCES = unistdio/test-u32-vsprintf1.c +test_u32_vsprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u8-asnprintf b/modules/unistdio/u8-asnprintf new file mode 100644 index 000000000..a0542488d --- /dev/null +++ b/modules/unistdio/u8-asnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-8 string, with automatic memory allocation and +bounded output size. + +Files: +lib/unistdio/u8-asnprintf.c +lib/unistdio/u-asnprintf.h + +Depends-on: +unistdio/base +unistdio/u8-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-asnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-asnprintf-tests b/modules/unistdio/u8-asnprintf-tests new file mode 100644 index 000000000..10afe9dde --- /dev/null +++ b/modules/unistdio/u8-asnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u8-asnprintf1.c +tests/unistdio/test-u8-asnprintf1.h +tests/unistdio/test-u8-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-u8-asnprintf1 +check_PROGRAMS += test-u8-asnprintf1 +test_u8_asnprintf1_SOURCES = unistdio/test-u8-asnprintf1.c +test_u8_asnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u8-asprintf b/modules/unistdio/u8-asprintf new file mode 100644 index 000000000..56f78a189 --- /dev/null +++ b/modules/unistdio/u8-asprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-8 string, with automatic memory allocation. + +Files: +lib/unistdio/u8-asprintf.c +lib/unistdio/u-asprintf.h + +Depends-on: +unistdio/base +unistdio/u8-vasprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-asprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-printf-parse b/modules/unistdio/u8-printf-parse new file mode 100644 index 000000000..52973b412 --- /dev/null +++ b/modules/unistdio/u8-printf-parse @@ -0,0 +1,30 @@ +Description: +Parsing an UTF-8 format string. + +Files: +lib/unistdio/u-printf-parse.h +lib/unistdio/u8-printf-parse.c +lib/printf-parse.h +lib/printf-parse.c +m4/vasnprintf.m4 + +Depends-on: +unistdio/u-printf-args +stdint +xsize + +configure.ac: +gl_PREREQ_PRINTF_PARSE + +Makefile.am: +lib_SOURCES += unistdio/u8-printf-parse.c + +Include: +"unistdio/u-printf-parse.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-snprintf b/modules/unistdio/u8-snprintf new file mode 100644 index 000000000..ee1fd7ab1 --- /dev/null +++ b/modules/unistdio/u8-snprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length UTF-8 string. + +Files: +lib/unistdio/u8-snprintf.c +lib/unistdio/u-snprintf.h + +Depends-on: +unistdio/base +unistdio/u8-vsnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-snprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-sprintf b/modules/unistdio/u8-sprintf new file mode 100644 index 000000000..628089634 --- /dev/null +++ b/modules/unistdio/u8-sprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-8 string. + +Files: +lib/unistdio/u8-sprintf.c +lib/unistdio/u-sprintf.h + +Depends-on: +unistdio/base +unistdio/u8-sprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-sprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-asnprintf b/modules/unistdio/u8-u8-asnprintf new file mode 100644 index 000000000..c8ddf9d80 --- /dev/null +++ b/modules/unistdio/u8-u8-asnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-8 string, with automatic memory allocation and +bounded output size. + +Files: +lib/unistdio/u8-u8-asnprintf.c +lib/unistdio/u-asnprintf.h + +Depends-on: +unistdio/base +unistdio/u8-u8-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-asnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-asprintf b/modules/unistdio/u8-u8-asprintf new file mode 100644 index 000000000..73289385d --- /dev/null +++ b/modules/unistdio/u8-u8-asprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-8 string, with automatic memory allocation. + +Files: +lib/unistdio/u8-u8-asprintf.c +lib/unistdio/u-asprintf.h + +Depends-on: +unistdio/base +unistdio/u8-u8-vasprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-asprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-snprintf b/modules/unistdio/u8-u8-snprintf new file mode 100644 index 000000000..de12c800d --- /dev/null +++ b/modules/unistdio/u8-u8-snprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length UTF-8 string. + +Files: +lib/unistdio/u8-u8-snprintf.c +lib/unistdio/u-snprintf.h + +Depends-on: +unistdio/base +unistdio/u8-u8-vsnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-snprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-sprintf b/modules/unistdio/u8-u8-sprintf new file mode 100644 index 000000000..464163785 --- /dev/null +++ b/modules/unistdio/u8-u8-sprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-8 string. + +Files: +lib/unistdio/u8-u8-sprintf.c +lib/unistdio/u-sprintf.h + +Depends-on: +unistdio/base +unistdio/u8-u8-sprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-sprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-vasnprintf b/modules/unistdio/u8-u8-vasnprintf new file mode 100644 index 000000000..ec1cedede --- /dev/null +++ b/modules/unistdio/u8-u8-vasnprintf @@ -0,0 +1,59 @@ +Description: +Formatted output to UTF-8 strings. + +Files: +lib/unistdio/u8-u8-vasnprintf.c +lib/vasnprintf.c +m4/vasnprintf.m4 +m4/printf.m4 +m4/wchar_t.m4 +m4/wint_t.m4 +m4/longlong.m4 +m4/intmax_t.m4 +m4/stdint_h.m4 +m4/inttypes_h.m4 +m4/eoverflow.m4 + +Depends-on: +unistdio/base +unistdio/u8-printf-parse +unistdio/u-printf-args +uniconv/u8-conv-from-enc +unistr/u8-cpy +unistr/u8-set +unistr/u8-mbsnlen +unistr/u16-to-u8 +unistr/u32-to-u8 +unistr/u8-strlen +unistr/u8-strmblen +unistr/u16-strlen +unistr/u16-strmblen +unistr/u32-strlen +unistr/u32-strmblen +isnan-nolibm +isnanl-nolibm +frexpl-nolibm +printf-frexp +printf-frexpl +signbit +fpucw +printf-safe +alloca-opt +localcharset +xsize + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_EXTRAS + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-vasnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-vasprintf b/modules/unistdio/u8-u8-vasprintf new file mode 100644 index 000000000..750dddb98 --- /dev/null +++ b/modules/unistdio/u8-u8-vasprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-8 string, with automatic memory allocation. + +Files: +lib/unistdio/u8-u8-vasprintf.c +lib/unistdio/u-vasprintf.h + +Depends-on: +unistdio/base +unistdio/u8-u8-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-vasprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-vsnprintf b/modules/unistdio/u8-u8-vsnprintf new file mode 100644 index 000000000..459c9bb93 --- /dev/null +++ b/modules/unistdio/u8-u8-vsnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a fixed-length UTF-8 string. + +Files: +lib/unistdio/u8-u8-vsnprintf.c +lib/unistdio/u-vsnprintf.h + +Depends-on: +unistdio/base +unistdio/u8-u8-vasnprintf +unistr/u8-cpy + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-vsnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-u8-vsprintf b/modules/unistdio/u8-u8-vsprintf new file mode 100644 index 000000000..53bab92d8 --- /dev/null +++ b/modules/unistdio/u8-u8-vsprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-8 string. + +Files: +lib/unistdio/u8-u8-vsprintf.c +lib/unistdio/u-vsprintf.h + +Depends-on: +unistdio/base +unistdio/u8-u8-vasnprintf +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-u8-vsprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-vasnprintf b/modules/unistdio/u8-vasnprintf new file mode 100644 index 000000000..3d89771a3 --- /dev/null +++ b/modules/unistdio/u8-vasnprintf @@ -0,0 +1,59 @@ +Description: +Formatted output to UTF-8 strings. + +Files: +lib/unistdio/u8-vasnprintf.c +lib/vasnprintf.c +m4/vasnprintf.m4 +m4/printf.m4 +m4/wchar_t.m4 +m4/wint_t.m4 +m4/longlong.m4 +m4/intmax_t.m4 +m4/stdint_h.m4 +m4/inttypes_h.m4 +m4/eoverflow.m4 + +Depends-on: +unistdio/base +unistdio/ulc-printf-parse +unistdio/u-printf-args +uniconv/u8-conv-from-enc +unistr/u8-cpy +unistr/u8-set +unistr/u8-mbsnlen +unistr/u16-to-u8 +unistr/u32-to-u8 +unistr/u8-strlen +unistr/u8-strmblen +unistr/u16-strlen +unistr/u16-strmblen +unistr/u32-strlen +unistr/u32-strmblen +isnan-nolibm +isnanl-nolibm +frexpl-nolibm +printf-frexp +printf-frexpl +signbit +fpucw +printf-safe +alloca-opt +localcharset +xsize + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_EXTRAS + +Makefile.am: +lib_SOURCES += unistdio/u8-vasnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-vasnprintf-tests b/modules/unistdio/u8-vasnprintf-tests new file mode 100644 index 000000000..45425336b --- /dev/null +++ b/modules/unistdio/u8-vasnprintf-tests @@ -0,0 +1,31 @@ +Files: +tests/unistdio/test-u8-vasnprintf1.c +tests/unistdio/test-u8-asnprintf1.h +tests/unistdio/test-u8-printf1.h +tests/unistdio/test-u8-vasnprintf2.sh +tests/unistdio/test-u8-vasnprintf2.c +tests/unistdio/test-u8-vasnprintf3.sh +tests/unistdio/test-u8-vasnprintf3.c +m4/locale-fr.m4 + +Depends-on: +unistr/u8-cmp +unistr/u8-cpy +unistr/u8-strcmp +unistr/u8-strlen + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 + +Makefile.am: +TESTS += test-u8-vasnprintf1 unistdio/test-u8-vasnprintf2.sh unistdio/test-u8-vasnprintf3.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' +check_PROGRAMS += test-u8-vasnprintf1 test-u8-vasnprintf2 test-u8-vasnprintf3 +test_u8_vasnprintf1_SOURCES = unistdio/test-u8-vasnprintf1.c +test_u8_vasnprintf1_LDADD = $(LDADD) @LIBICONV@ +test_u8_vasnprintf2_SOURCES = unistdio/test-u8-vasnprintf2.c +test_u8_vasnprintf2_LDADD = $(LDADD) @LIBICONV@ +test_u8_vasnprintf3_SOURCES = unistdio/test-u8-vasnprintf3.c +test_u8_vasnprintf3_LDADD = $(LDADD) @LIBICONV@ +EXTRA_DIST += unistdio/test-u8-vasnprintf2.sh unistdio/test-u8-vasnprintf3.sh diff --git a/modules/unistdio/u8-vasprintf b/modules/unistdio/u8-vasprintf new file mode 100644 index 000000000..7785eabf9 --- /dev/null +++ b/modules/unistdio/u8-vasprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to an UTF-8 string, with automatic memory allocation. + +Files: +lib/unistdio/u8-vasprintf.c +lib/unistdio/u-vasprintf.h + +Depends-on: +unistdio/base +unistdio/u8-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-vasprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-vasprintf-tests b/modules/unistdio/u8-vasprintf-tests new file mode 100644 index 000000000..a9490b4a4 --- /dev/null +++ b/modules/unistdio/u8-vasprintf-tests @@ -0,0 +1,13 @@ +Files: +tests/unistdio/test-u8-vasprintf1.c +tests/unistdio/test-u8-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-u8-vasprintf1 +check_PROGRAMS += test-u8-vasprintf1 +test_u8_vasprintf1_SOURCES = unistdio/test-u8-vasprintf1.c +test_u8_vasprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u8-vsnprintf b/modules/unistdio/u8-vsnprintf new file mode 100644 index 000000000..1a4f05f89 --- /dev/null +++ b/modules/unistdio/u8-vsnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a fixed-length UTF-8 string. + +Files: +lib/unistdio/u8-vsnprintf.c +lib/unistdio/u-vsnprintf.h + +Depends-on: +unistdio/base +unistdio/u8-vasnprintf +unistr/u8-cpy + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-vsnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-vsnprintf-tests b/modules/unistdio/u8-vsnprintf-tests new file mode 100644 index 000000000..b8c7c0bbc --- /dev/null +++ b/modules/unistdio/u8-vsnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u8-vsnprintf1.c +tests/unistdio/test-u8-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-u8-vsnprintf1 +check_PROGRAMS += test-u8-vsnprintf1 +test_u8_vsnprintf1_SOURCES = unistdio/test-u8-vsnprintf1.c +test_u8_vsnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/u8-vsprintf b/modules/unistdio/u8-vsprintf new file mode 100644 index 000000000..99d76a506 --- /dev/null +++ b/modules/unistdio/u8-vsprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to an UTF-8 string. + +Files: +lib/unistdio/u8-vsprintf.c +lib/unistdio/u-vsprintf.h + +Depends-on: +unistdio/base +unistdio/u8-vasnprintf +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/u8-vsprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/u8-vsprintf-tests b/modules/unistdio/u8-vsprintf-tests new file mode 100644 index 000000000..28794c276 --- /dev/null +++ b/modules/unistdio/u8-vsprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-u8-vsprintf1.c +tests/unistdio/test-u8-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-u8-vsprintf1 +check_PROGRAMS += test-u8-vsprintf1 +test_u8_vsprintf1_SOURCES = unistdio/test-u8-vsprintf1.c +test_u8_vsprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/ulc-asnprintf b/modules/unistdio/ulc-asnprintf new file mode 100644 index 000000000..921c572c0 --- /dev/null +++ b/modules/unistdio/ulc-asnprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a string, with automatic memory allocation and bounded +output size. + +Files: +lib/unistdio/ulc-asnprintf.c +lib/unistdio/u-asnprintf.h + +Depends-on: +unistdio/base +unistdio/ulc-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-asnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-asnprintf-tests b/modules/unistdio/ulc-asnprintf-tests new file mode 100644 index 000000000..2588a7ffc --- /dev/null +++ b/modules/unistdio/ulc-asnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-ulc-asnprintf1.c +tests/unistdio/test-ulc-asnprintf1.h +tests/unistdio/test-ulc-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-ulc-asnprintf1 +check_PROGRAMS += test-ulc-asnprintf1 +test_ulc_asnprintf1_SOURCES = unistdio/test-ulc-asnprintf1.c +test_ulc_asnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/ulc-asprintf b/modules/unistdio/ulc-asprintf new file mode 100644 index 000000000..587436b0c --- /dev/null +++ b/modules/unistdio/ulc-asprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a string, with automatic memory allocation. + +Files: +lib/unistdio/ulc-asprintf.c +lib/unistdio/u-asprintf.h + +Depends-on: +unistdio/base +unistdio/ulc-vasprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-asprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-fprintf b/modules/unistdio/ulc-fprintf new file mode 100644 index 000000000..cdbaf37af --- /dev/null +++ b/modules/unistdio/ulc-fprintf @@ -0,0 +1,25 @@ +Description: +Print formatted output to a stream. + +Files: +lib/unistdio/ulc-fprintf.c + +Depends-on: +unistdio/base +unistdio/ulc-vasnprintf +fseterr + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-fprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-printf-parse b/modules/unistdio/ulc-printf-parse new file mode 100644 index 000000000..ba45d0535 --- /dev/null +++ b/modules/unistdio/ulc-printf-parse @@ -0,0 +1,31 @@ +Description: +Parsing an ASCII format string. + +Files: +lib/unistdio/u-printf-parse.h +lib/unistdio/ulc-printf-parse.c +lib/printf-parse.h +lib/printf-parse.c +m4/vasnprintf.m4 + +Depends-on: +unistdio/u-printf-args +stdint +xsize +c-ctype + +configure.ac: +gl_PREREQ_PRINTF_PARSE + +Makefile.am: +lib_SOURCES += unistdio/ulc-printf-parse.c + +Include: +"unistdio/u-printf-parse.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-snprintf b/modules/unistdio/ulc-snprintf new file mode 100644 index 000000000..0a56b7917 --- /dev/null +++ b/modules/unistdio/ulc-snprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length string. + +Files: +lib/unistdio/ulc-snprintf.c +lib/unistdio/u-snprintf.h + +Depends-on: +unistdio/base +unistdio/ulc-vsnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-snprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-sprintf b/modules/unistdio/ulc-sprintf new file mode 100644 index 000000000..99fdb1b8c --- /dev/null +++ b/modules/unistdio/ulc-sprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a string. + +Files: +lib/unistdio/ulc-sprintf.c +lib/unistdio/u-sprintf.h + +Depends-on: +unistdio/base +unistdio/ulc-sprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-sprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-vasnprintf b/modules/unistdio/ulc-vasnprintf new file mode 100644 index 000000000..7136a1d13 --- /dev/null +++ b/modules/unistdio/ulc-vasnprintf @@ -0,0 +1,57 @@ +Description: +Formatted output to strings. + +Files: +lib/unistdio/ulc-vasnprintf.c +lib/vasnprintf.c +m4/vasnprintf.m4 +m4/printf.m4 +m4/wchar_t.m4 +m4/wint_t.m4 +m4/longlong.m4 +m4/intmax_t.m4 +m4/stdint_h.m4 +m4/inttypes_h.m4 +m4/eoverflow.m4 + +Depends-on: +unistdio/base +unistdio/ulc-printf-parse +unistdio/u-printf-args +uniconv/u8-conv-to-enc +uniconv/u16-conv-to-enc +uniconv/u32-conv-to-enc +unistr/u8-strlen +unistr/u8-strmblen +unistr/u16-strlen +unistr/u16-strmblen +unistr/u32-strlen +unistr/u32-strmblen +mbsnlen +isnan-nolibm +isnanl-nolibm +frexpl-nolibm +printf-frexp +printf-frexpl +signbit +fpucw +printf-safe +alloca-opt +localcharset +xsize + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_EXTRAS + +Makefile.am: +lib_SOURCES += unistdio/ulc-vasnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-vasnprintf-tests b/modules/unistdio/ulc-vasnprintf-tests new file mode 100644 index 000000000..eacc3e1ac --- /dev/null +++ b/modules/unistdio/ulc-vasnprintf-tests @@ -0,0 +1,27 @@ +Files: +tests/unistdio/test-ulc-vasnprintf1.c +tests/unistdio/test-ulc-asnprintf1.h +tests/unistdio/test-ulc-printf1.h +tests/unistdio/test-ulc-vasnprintf2.sh +tests/unistdio/test-ulc-vasnprintf2.c +tests/unistdio/test-ulc-vasnprintf3.sh +tests/unistdio/test-ulc-vasnprintf3.c +m4/locale-fr.m4 + +Depends-on: + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 + +Makefile.am: +TESTS += test-ulc-vasnprintf1 unistdio/test-ulc-vasnprintf2.sh unistdio/test-ulc-vasnprintf3.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' +check_PROGRAMS += test-ulc-vasnprintf1 test-ulc-vasnprintf2 test-ulc-vasnprintf3 +test_ulc_vasnprintf1_SOURCES = unistdio/test-ulc-vasnprintf1.c +test_ulc_vasnprintf1_LDADD = $(LDADD) @LIBICONV@ +test_ulc_vasnprintf2_SOURCES = unistdio/test-ulc-vasnprintf2.c +test_ulc_vasnprintf2_LDADD = $(LDADD) @LIBICONV@ +test_ulc_vasnprintf3_SOURCES = unistdio/test-ulc-vasnprintf3.c +test_ulc_vasnprintf3_LDADD = $(LDADD) @LIBICONV@ +EXTRA_DIST += unistdio/test-ulc-vasnprintf2.sh unistdio/test-ulc-vasnprintf3.sh diff --git a/modules/unistdio/ulc-vasprintf b/modules/unistdio/ulc-vasprintf new file mode 100644 index 000000000..8264dd70b --- /dev/null +++ b/modules/unistdio/ulc-vasprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a string, with automatic memory allocation. + +Files: +lib/unistdio/ulc-vasprintf.c +lib/unistdio/u-vasprintf.h + +Depends-on: +unistdio/base +unistdio/ulc-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-vasprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-vasprintf-tests b/modules/unistdio/ulc-vasprintf-tests new file mode 100644 index 000000000..d006624de --- /dev/null +++ b/modules/unistdio/ulc-vasprintf-tests @@ -0,0 +1,13 @@ +Files: +tests/unistdio/test-ulc-vasprintf1.c +tests/unistdio/test-ulc-printf1.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-ulc-vasprintf1 +check_PROGRAMS += test-ulc-vasprintf1 +test_ulc_vasprintf1_SOURCES = unistdio/test-ulc-vasprintf1.c +test_ulc_vasprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/ulc-vfprintf b/modules/unistdio/ulc-vfprintf new file mode 100644 index 000000000..0b5fef688 --- /dev/null +++ b/modules/unistdio/ulc-vfprintf @@ -0,0 +1,25 @@ +Description: +Print formatted output to a stream. + +Files: +lib/unistdio/ulc-vfprintf.c + +Depends-on: +unistdio/base +unistdio/ulc-vasnprintf +fseterr + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-vfprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-vsnprintf b/modules/unistdio/ulc-vsnprintf new file mode 100644 index 000000000..e3c868671 --- /dev/null +++ b/modules/unistdio/ulc-vsnprintf @@ -0,0 +1,25 @@ +Description: +Formatted output to a fixed-length string. + +Files: +lib/unistdio/ulc-vsnprintf.c +lib/unistdio/u-vsnprintf.h + +Depends-on: +unistdio/base +unistdio/ulc-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-vsnprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-vsnprintf-tests b/modules/unistdio/ulc-vsnprintf-tests new file mode 100644 index 000000000..e609035a5 --- /dev/null +++ b/modules/unistdio/ulc-vsnprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-ulc-vsnprintf1.c +tests/unistdio/test-ulc-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-ulc-vsnprintf1 +check_PROGRAMS += test-ulc-vsnprintf1 +test_ulc_vsnprintf1_SOURCES = unistdio/test-ulc-vsnprintf1.c +test_ulc_vsnprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/modules/unistdio/ulc-vsprintf b/modules/unistdio/ulc-vsprintf new file mode 100644 index 000000000..0138787ed --- /dev/null +++ b/modules/unistdio/ulc-vsprintf @@ -0,0 +1,26 @@ +Description: +Formatted output to a string. + +Files: +lib/unistdio/ulc-vsprintf.c +lib/unistdio/u-vsprintf.h + +Depends-on: +unistdio/base +unistdio/ulc-vasnprintf +stdint + +configure.ac: + +Makefile.am: +lib_SOURCES += unistdio/ulc-vsprintf.c + +Include: +"unistdio.h" + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistdio/ulc-vsprintf-tests b/modules/unistdio/ulc-vsprintf-tests new file mode 100644 index 000000000..123d1df01 --- /dev/null +++ b/modules/unistdio/ulc-vsprintf-tests @@ -0,0 +1,14 @@ +Files: +tests/unistdio/test-ulc-vsprintf1.c +tests/unistdio/test-ulc-printf1.h + +Depends-on: +xalloc + +configure.ac: + +Makefile.am: +TESTS += test-ulc-vsprintf1 +check_PROGRAMS += test-ulc-vsprintf1 +test_ulc_vsprintf1_SOURCES = unistdio/test-ulc-vsprintf1.c +test_ulc_vsprintf1_LDADD = $(LDADD) @LIBICONV@ diff --git a/tests/unistdio/test-u16-asnprintf1.c b/tests/unistdio/test-u16-asnprintf1.c new file mode 100644 index 000000000..4ef585469 --- /dev/null +++ b/tests/unistdio/test-u16-asnprintf1.c @@ -0,0 +1,59 @@ +/* Test of u16_asnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u16-asnprintf1.h" + +static void +test_asnprintf () +{ + test_function (u16_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + test_asnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u16-asnprintf1.h b/tests/unistdio/test-u16-asnprintf1.h new file mode 100644 index 000000000..5a219d66c --- /dev/null +++ b/tests/unistdio/test-u16-asnprintf1.h @@ -0,0 +1,61 @@ +/* Test of u16_[v]asnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, ...)) +{ + uint16_t buf[8]; + int size; + + /* Test return value convention. */ + + for (size = 0; size <= 8; size++) + { + size_t length = size; + uint16_t *result = my_asnprintf (NULL, &length, "%d", 12345); + static const uint16_t expected[] = + { '1', '2', '3', '4', '5', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == 5); + free (result); + } + + for (size = 0; size <= 8; size++) + { + static const uint16_t initializer[] = + { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F', 0 }; + static const uint16_t expected[] = + { '1', '2', '3', '4', '5', 0 }; + size_t length; + uint16_t *result; + + u16_cpy (buf, initializer, 8); + length = size; + result = my_asnprintf (buf, &length, "%d", 12345); + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == 5); + if (size < 6) + ASSERT (result != buf); + ASSERT (u16_cmp (buf + size, initializer + size, 8 - size) == 0); + if (result != buf) + free (result); + } +} diff --git a/tests/unistdio/test-u16-printf1.h b/tests/unistdio/test-u16-printf1.h new file mode 100644 index 000000000..ee6449e9a --- /dev/null +++ b/tests/unistdio/test-u16-printf1.h @@ -0,0 +1,942 @@ +/* Test of u16_v[a]s[n]printf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) +{ + /* Test support of size specifiers as in C99. */ + + { + uint16_t *result = + my_xasprintf ("%ju %d", (uintmax_t) 12345671, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', '4', '5', '6', '7', '1', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { + uint16_t *result = + my_xasprintf ("%zu %d", (size_t) 12345672, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', '4', '5', '6', '7', '2', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { + uint16_t *result = + my_xasprintf ("%tu %d", (ptrdiff_t) 12345673, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', '4', '5', '6', '7', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { + uint16_t *result = + my_xasprintf ("%Lg %d", (long double) 1.5, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Hello"; + { + uint16_t *result = + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint16_t *result = + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint16_t *result = + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + uint16_t *result = + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint16_t *result = + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint16_t *result = + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + uint16_t *result = + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint16_t *result = + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint16_t *result = + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + } + + /* Test the support of the 's' conversion specifier for strings. */ + + { + uint16_t *result = + my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* FLAG_LEFT. */ + uint16_t *result = + my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* FLAG_ZERO: no effect. */ + uint16_t *result = + my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%a %d", 3.1416015625, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10a %d", 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Small precision. */ + uint16_t *result = + my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint16_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint16_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Large precision. */ + uint16_t *result = + my_xasprintf ("%.50a %d", 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint16_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint16_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1', + ' ', '3', '3', 0 + }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0', + ' ', '3', '3', 0 + }; + static const uint16_t expected3[] = + { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1', + ' ', '3', '3', 0 + }; + static const uint16_t expected4[] = + { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', + '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10La %d", 1.75L, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Small precision. */ + uint16_t *result = + my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint16_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint16_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Large precision. */ + uint16_t *result = + my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint16_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint16_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%f %d", 12.75, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10f %d", 1.75, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%Lf %d", 12.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10Lf %d", 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%F %d", 12.75, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.F %d", 1234.0, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%LF %d", 12.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.LF %d", 1234.0L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %e format directive. */ + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%e %d", 12.75, 33, 44, 55); + static const uint16_t expected1[] = + { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', + '0', '1', ' ', '3', '3', 0 + }; + static const uint16_t expected2[] = + { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', + '0', '0', '1', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%15e %d", 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + static const uint16_t expected2[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', + 'e', '+', '0', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); + static const uint16_t expected1[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%Le %d", 12.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', + '0', '1', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); + static const uint16_t expected[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %g format directive. */ + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%g %d", 12.75, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10g %d", 1.75, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); + static const uint16_t expected1[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + + { /* A positive number. */ + uint16_t *result = + my_xasprintf ("%Lg %d", 12.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint16_t *result = + my_xasprintf ("%10Lg %d", 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint16_t *result = + my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); + static const uint16_t expected[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %n format directive. */ + + { + int count = -1; + uint16_t *result = + my_xasprintf ("%d %n", 123, &count, 33, 44, 55); + static const uint16_t expected[] = + { '1', '2', '3', ' ', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (count == 4); + free (result); + } + + /* Test the support of the POSIX/XSI format strings with positions. */ + + { + uint16_t *result = + my_xasprintf ("%2$d %1$d", 33, 55); + static const uint16_t expected[] = + { '5', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the grouping flag. */ + + { + uint16_t *result = + my_xasprintf ("%'d %d", 1234567, 99); + ASSERT (result != NULL); + ASSERT (result[u16_strlen (result) - 1] == '9'); + free (result); + } + + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ + { + uint16_t *result = + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint16_t *result = + my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint16_t *result = + my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint16_t *result = + my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint16_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + uint16_t *result = + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint16_t *result = + my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint16_t *result = + my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint16_t *result = + my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint32_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + uint16_t *result = + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint16_t *result = + my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint16_t *result = + my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint16_t *result = + my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + } + + /* Test non-ASCII characters in the format string. */ + + { + uint16_t *result = + my_xasprintf ("\304rger", 33, 44, 55); + ASSERT (result == NULL && errno == EINVAL); + } +} diff --git a/tests/unistdio/test-u16-vasnprintf1.c b/tests/unistdio/test-u16-vasnprintf1.c new file mode 100644 index 000000000..6f016dfae --- /dev/null +++ b/tests/unistdio/test-u16-vasnprintf1.c @@ -0,0 +1,88 @@ +/* Test of u16_vasnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u16-asnprintf1.h" +#include "test-u16-printf1.h" + +static uint16_t * +my_asnprintf (uint16_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint16_t *ret; + + va_start (args, format); + ret = u16_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static uint16_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + size_t length; + uint16_t *ret; + + va_start (args, format); + ret = u16_vasnprintf (NULL, &length, format, args); + va_end (args); + if (ret != NULL) + ASSERT (length == u16_strlen (ret)); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u16-vasnprintf2.c b/tests/unistdio/test-u16-vasnprintf2.c new file mode 100644 index 000000000..8797c8255 --- /dev/null +++ b/tests/unistdio/test-u16-vasnprintf2.c @@ -0,0 +1,132 @@ +/* Test of u16_vasnprintf() function in an ISO-8859-1 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, ...)) +{ + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\304rger"; /* Ärger */ + { + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + } +} + +static uint16_t * +my_asnprintf (uint16_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint16_t *ret; + + va_start (args, format); + ret = u16_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u16-vasnprintf2.sh b/tests/unistdio/test-u16-vasnprintf2.sh new file mode 100755 index 000000000..418b8aace --- /dev/null +++ b/tests/unistdio/test-u16-vasnprintf2.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a traditional french locale is installed. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR != none; then + testlocale=$LOCALE_FR +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-u16-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-u16-vasnprintf2${EXEEXT} diff --git a/tests/unistdio/test-u16-vasnprintf3.c b/tests/unistdio/test-u16-vasnprintf3.c new file mode 100644 index 000000000..0d6ab7490 --- /dev/null +++ b/tests/unistdio/test-u16-vasnprintf3.c @@ -0,0 +1,132 @@ +/* Test of u16_vasnprintf() function in an UTF-8 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, ...)) +{ + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\303\204rger"; /* Ärger */ + { + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + } +} + +static uint16_t * +my_asnprintf (uint16_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint16_t *ret; + + va_start (args, format); + ret = u16_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u16-vasnprintf3.sh b/tests/unistdio/test-u16-vasnprintf3.sh new file mode 100755 index 000000000..57488c067 --- /dev/null +++ b/tests/unistdio/test-u16-vasnprintf3.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a french Unicode locale is installed. +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR_UTF8 != none; then + testlocale=$LOCALE_FR_UTF8 +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no french Unicode locale is installed" + else + echo "Skipping test: no french Unicode locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-u16-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-u16-vasnprintf3${EXEEXT} diff --git a/tests/unistdio/test-u16-vasprintf1.c b/tests/unistdio/test-u16-vasprintf1.c new file mode 100644 index 000000000..7c2095240 --- /dev/null +++ b/tests/unistdio/test-u16-vasprintf1.c @@ -0,0 +1,75 @@ +/* Test of u16_vasprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u16-printf1.h" + +static uint16_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint16_t *result; + int retval; + + va_start (args, format); + retval = u16_vasprintf (&result, format, args); + va_end (args); + if (retval < 0) + return NULL; + ASSERT (result != NULL); + return result; +} + +static void +test_vasprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasprintf (); + return 0; +} diff --git a/tests/unistdio/test-u16-vsnprintf1.c b/tests/unistdio/test-u16-vsnprintf1.c new file mode 100644 index 000000000..6081a7832 --- /dev/null +++ b/tests/unistdio/test-u16-vsnprintf1.c @@ -0,0 +1,80 @@ +/* Test of u16_vsnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u16-printf1.h" + +static uint16_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint16_t buf[1000]; + int retval; + size_t length; + uint16_t *result; + + va_start (args, format); + retval = u16_vsnprintf (buf, sizeof (buf), format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (buf)) + return NULL; + length = u16_strlen (buf); + result = XNMALLOC (length + 1, uint16_t); + u16_cpy (result, buf, length + 1); + return result; +} + +static void +test_vsnprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u16-vsprintf1.c b/tests/unistdio/test-u16-vsprintf1.c new file mode 100644 index 000000000..4ebe51e44 --- /dev/null +++ b/tests/unistdio/test-u16-vsprintf1.c @@ -0,0 +1,80 @@ +/* Test of u16_vsprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u16-printf1.h" + +static uint16_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint16_t buf[1000]; + int retval; + size_t length; + uint16_t *result; + + va_start (args, format); + retval = u16_vsprintf (buf, format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (buf)) + return NULL; + length = u16_strlen (buf); + result = XNMALLOC (length + 1, uint16_t); + u16_cpy (result, buf, length + 1); + return result; +} + +static void +test_vsprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsprintf (); + return 0; +} diff --git a/tests/unistdio/test-u32-asnprintf1.c b/tests/unistdio/test-u32-asnprintf1.c new file mode 100644 index 000000000..cb55cdd73 --- /dev/null +++ b/tests/unistdio/test-u32-asnprintf1.c @@ -0,0 +1,59 @@ +/* Test of u32_asnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u32-asnprintf1.h" + +static void +test_asnprintf () +{ + test_function (u32_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + test_asnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u32-asnprintf1.h b/tests/unistdio/test-u32-asnprintf1.h new file mode 100644 index 000000000..7329e1314 --- /dev/null +++ b/tests/unistdio/test-u32-asnprintf1.h @@ -0,0 +1,61 @@ +/* Test of u32_[v]asnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, ...)) +{ + uint32_t buf[8]; + int size; + + /* Test return value convention. */ + + for (size = 0; size <= 8; size++) + { + size_t length = size; + uint32_t *result = my_asnprintf (NULL, &length, "%d", 12345); + static const uint32_t expected[] = + { '1', '2', '3', '4', '5', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == 5); + free (result); + } + + for (size = 0; size <= 8; size++) + { + static const uint32_t initializer[] = + { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F', 0 }; + static const uint32_t expected[] = + { '1', '2', '3', '4', '5', 0 }; + size_t length; + uint32_t *result; + + u32_cpy (buf, initializer, 8); + length = size; + result = my_asnprintf (buf, &length, "%d", 12345); + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == 5); + if (size < 6) + ASSERT (result != buf); + ASSERT (u32_cmp (buf + size, initializer + size, 8 - size) == 0); + if (result != buf) + free (result); + } +} diff --git a/tests/unistdio/test-u32-printf1.h b/tests/unistdio/test-u32-printf1.h new file mode 100644 index 000000000..0c9cb0935 --- /dev/null +++ b/tests/unistdio/test-u32-printf1.h @@ -0,0 +1,942 @@ +/* Test of u32_v[a]s[n]printf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) +{ + /* Test support of size specifiers as in C99. */ + + { + uint32_t *result = + my_xasprintf ("%ju %d", (uintmax_t) 12345671, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', '4', '5', '6', '7', '1', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { + uint32_t *result = + my_xasprintf ("%zu %d", (size_t) 12345672, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', '4', '5', '6', '7', '2', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { + uint32_t *result = + my_xasprintf ("%tu %d", (ptrdiff_t) 12345673, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', '4', '5', '6', '7', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { + uint32_t *result = + my_xasprintf ("%Lg %d", (long double) 1.5, 33, 44, 55); + static const uint32_t expected[] = + { '1', '.', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Hello"; + { + uint32_t *result = + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint32_t *result = + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint32_t *result = + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + uint32_t *result = + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint32_t *result = + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint32_t *result = + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + uint32_t *result = + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint32_t *result = + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint32_t *result = + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + } + + /* Test the support of the 's' conversion specifier for strings. */ + + { + uint32_t *result = + my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55); + static const uint32_t expected[] = + { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55); + static const uint32_t expected[] = + { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* FLAG_LEFT. */ + uint32_t *result = + my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); + static const uint32_t expected[] = + { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* FLAG_ZERO: no effect. */ + uint32_t *result = + my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55); + static const uint32_t expected[] = + { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%a %d", 3.1416015625, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint32_t expected3[] = + { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint32_t expected4[] = + { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10a %d", 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint32_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint32_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Small precision. */ + uint32_t *result = + my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint32_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint32_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Large precision. */ + uint32_t *result = + my_xasprintf ("%.50a %d", 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint32_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint32_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1', + ' ', '3', '3', 0 + }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0', + ' ', '3', '3', 0 + }; + static const uint32_t expected3[] = + { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1', + ' ', '3', '3', 0 + }; + static const uint32_t expected4[] = + { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', + '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10La %d", 1.75L, 33, 44, 55); + static const uint32_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint32_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint32_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Small precision. */ + uint32_t *result = + my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint32_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint32_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + { /* Large precision. */ + uint32_t *result = + my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55); + static const uint32_t expected1[] = + { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 + }; + static const uint32_t expected2[] = + { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 + }; + static const uint32_t expected3[] = + { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 + }; + static const uint32_t expected4[] = + { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); + free (result); + } + + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%f %d", 12.75, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10f %d", 1.75, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%Lf %d", 12.75L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10Lf %d", 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%F %d", 12.75, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.F %d", 1234.0, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%LF %d", 12.75L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.LF %d", 1234.0L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', '4', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %e format directive. */ + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%e %d", 12.75, 33, 44, 55); + static const uint32_t expected1[] = + { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', + '0', '1', ' ', '3', '3', 0 + }; + static const uint32_t expected2[] = + { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', + '0', '0', '1', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%15e %d", 1.75, 33, 44, 55); + static const uint32_t expected1[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + static const uint32_t expected2[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', + 'e', '+', '0', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); + static const uint32_t expected1[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0); + free (result); + } + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%Le %d", 12.75L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', + '0', '1', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); + static const uint32_t expected[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %g format directive. */ + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%g %d", 12.75, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10g %d", 1.75, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); + static const uint32_t expected1[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + static const uint32_t expected2[] = + { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected1) == 0 + || u32_strcmp (result, expected2) == 0); + free (result); + } + + { /* A positive number. */ + uint32_t *result = + my_xasprintf ("%Lg %d", 12.75L, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint32_t *result = + my_xasprintf ("%10Lg %d", 1.75L, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint32_t *result = + my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); + static const uint32_t expected[] = + { '1', 'e', '+', '0', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %n format directive. */ + + { + int count = -1; + uint32_t *result = + my_xasprintf ("%d %n", 123, &count, 33, 44, 55); + static const uint32_t expected[] = + { '1', '2', '3', ' ', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (count == 4); + free (result); + } + + /* Test the support of the POSIX/XSI format strings with positions. */ + + { + uint32_t *result = + my_xasprintf ("%2$d %1$d", 33, 55); + static const uint32_t expected[] = + { '5', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the grouping flag. */ + + { + uint32_t *result = + my_xasprintf ("%'d %d", 1234567, 99); + ASSERT (result != NULL); + ASSERT (result[u32_strlen (result) - 1] == '9'); + free (result); + } + + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ + { + uint32_t *result = + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint32_t *result = + my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint32_t *result = + my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint32_t *result = + my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint16_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + uint32_t *result = + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint32_t *result = + my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint32_t *result = + my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint32_t *result = + my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint32_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + uint32_t *result = + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint32_t *result = + my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint32_t *result = + my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint32_t *result = + my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + free (result); + } + } + + /* Test non-ASCII characters in the format string. */ + + { + uint32_t *result = + my_xasprintf ("\304rger", 33, 44, 55); + ASSERT (result == NULL && errno == EINVAL); + } +} diff --git a/tests/unistdio/test-u32-vasnprintf1.c b/tests/unistdio/test-u32-vasnprintf1.c new file mode 100644 index 000000000..f3af07256 --- /dev/null +++ b/tests/unistdio/test-u32-vasnprintf1.c @@ -0,0 +1,88 @@ +/* Test of u32_vasnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u32-asnprintf1.h" +#include "test-u32-printf1.h" + +static uint32_t * +my_asnprintf (uint32_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint32_t *ret; + + va_start (args, format); + ret = u32_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static uint32_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + size_t length; + uint32_t *ret; + + va_start (args, format); + ret = u32_vasnprintf (NULL, &length, format, args); + va_end (args); + if (ret != NULL) + ASSERT (length == u32_strlen (ret)); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u32-vasnprintf2.c b/tests/unistdio/test-u32-vasnprintf2.c new file mode 100644 index 000000000..7d13968d6 --- /dev/null +++ b/tests/unistdio/test-u32-vasnprintf2.c @@ -0,0 +1,132 @@ +/* Test of u32_vasnprintf() function in an ISO-8859-1 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, ...)) +{ + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\304rger"; /* Ärger */ + { + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + } +} + +static uint32_t * +my_asnprintf (uint32_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint32_t *ret; + + va_start (args, format); + ret = u32_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u32-vasnprintf2.sh b/tests/unistdio/test-u32-vasnprintf2.sh new file mode 100755 index 000000000..ae39dd487 --- /dev/null +++ b/tests/unistdio/test-u32-vasnprintf2.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a traditional french locale is installed. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR != none; then + testlocale=$LOCALE_FR +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-u32-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-u32-vasnprintf2${EXEEXT} diff --git a/tests/unistdio/test-u32-vasnprintf3.c b/tests/unistdio/test-u32-vasnprintf3.c new file mode 100644 index 000000000..5ed52920f --- /dev/null +++ b/tests/unistdio/test-u32-vasnprintf3.c @@ -0,0 +1,132 @@ +/* Test of u32_vasnprintf() function in an UTF-8 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, ...)) +{ + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\303\204rger"; /* Ärger */ + { + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + uint32_t *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + static const uint32_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u32_strcmp (result, expected) == 0); + ASSERT (length == u32_strlen (result)); + free (result); + } + } +} + +static uint32_t * +my_asnprintf (uint32_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint32_t *ret; + + va_start (args, format); + ret = u32_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u32-vasnprintf3.sh b/tests/unistdio/test-u32-vasnprintf3.sh new file mode 100755 index 000000000..d2c311701 --- /dev/null +++ b/tests/unistdio/test-u32-vasnprintf3.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a french Unicode locale is installed. +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR_UTF8 != none; then + testlocale=$LOCALE_FR_UTF8 +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no french Unicode locale is installed" + else + echo "Skipping test: no french Unicode locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-u32-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-u32-vasnprintf3${EXEEXT} diff --git a/tests/unistdio/test-u32-vasprintf1.c b/tests/unistdio/test-u32-vasprintf1.c new file mode 100644 index 000000000..9d83a21c4 --- /dev/null +++ b/tests/unistdio/test-u32-vasprintf1.c @@ -0,0 +1,75 @@ +/* Test of u32_vasprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u32-printf1.h" + +static uint32_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint32_t *result; + int retval; + + va_start (args, format); + retval = u32_vasprintf (&result, format, args); + va_end (args); + if (retval < 0) + return NULL; + ASSERT (result != NULL); + return result; +} + +static void +test_vasprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasprintf (); + return 0; +} diff --git a/tests/unistdio/test-u32-vsnprintf1.c b/tests/unistdio/test-u32-vsnprintf1.c new file mode 100644 index 000000000..615c5096c --- /dev/null +++ b/tests/unistdio/test-u32-vsnprintf1.c @@ -0,0 +1,80 @@ +/* Test of u32_vsnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u32-printf1.h" + +static uint32_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint32_t buf[1000]; + int retval; + size_t length; + uint32_t *result; + + va_start (args, format); + retval = u32_vsnprintf (buf, sizeof (buf), format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (buf)) + return NULL; + length = u32_strlen (buf); + result = XNMALLOC (length + 1, uint32_t); + u32_cpy (result, buf, length + 1); + return result; +} + +static void +test_vsnprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u32-vsprintf1.c b/tests/unistdio/test-u32-vsprintf1.c new file mode 100644 index 000000000..8ae833100 --- /dev/null +++ b/tests/unistdio/test-u32-vsprintf1.c @@ -0,0 +1,80 @@ +/* Test of u32_vsprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u32-printf1.h" + +static uint32_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint32_t buf[1000]; + int retval; + size_t length; + uint32_t *result; + + va_start (args, format); + retval = u32_vsprintf (buf, format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (buf)) + return NULL; + length = u32_strlen (buf); + result = XNMALLOC (length + 1, uint32_t); + u32_cpy (result, buf, length + 1); + return result; +} + +static void +test_vsprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsprintf (); + return 0; +} diff --git a/tests/unistdio/test-u8-asnprintf1.c b/tests/unistdio/test-u8-asnprintf1.c new file mode 100644 index 000000000..81e32e6e4 --- /dev/null +++ b/tests/unistdio/test-u8-asnprintf1.c @@ -0,0 +1,59 @@ +/* Test of u8_asnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u8-asnprintf1.h" + +static void +test_asnprintf () +{ + test_function (u8_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + test_asnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u8-asnprintf1.h b/tests/unistdio/test-u8-asnprintf1.h new file mode 100644 index 000000000..dbb6f785a --- /dev/null +++ b/tests/unistdio/test-u8-asnprintf1.h @@ -0,0 +1,58 @@ +/* Test of u8_[v]asnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...)) +{ + uint8_t buf[8]; + int size; + + /* Test return value convention. */ + + for (size = 0; size <= 8; size++) + { + size_t length = size; + uint8_t *result = my_asnprintf (NULL, &length, "%d", 12345); + static const uint8_t expected[] = "12345"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == 5); + free (result); + } + + for (size = 0; size <= 8; size++) + { + static const uint8_t initializer[] = "DEADBEEF"; + static const uint8_t expected[] = "12345"; + size_t length; + uint8_t *result; + + u8_cpy (buf, initializer, 8); + length = size; + result = my_asnprintf (buf, &length, "%d", 12345); + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == 5); + if (size < 6) + ASSERT (result != buf); + ASSERT (u8_cmp (buf + size, initializer + size, 8 - size) == 0); + if (result != buf) + free (result); + } +} diff --git a/tests/unistdio/test-u8-printf1.h b/tests/unistdio/test-u8-printf1.h new file mode 100644 index 000000000..95154ff52 --- /dev/null +++ b/tests/unistdio/test-u8-printf1.h @@ -0,0 +1,705 @@ +/* Test of u8_v[a]s[n]printf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) +{ + /* Test support of size specifiers as in C99. */ + + { + uint8_t *result = + my_xasprintf ("%ju %d", (uintmax_t) 12345671, 33, 44, 55); + static const uint8_t expected[] = "12345671 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { + uint8_t *result = + my_xasprintf ("%zu %d", (size_t) 12345672, 33, 44, 55); + static const uint8_t expected[] = "12345672 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { + uint8_t *result = + my_xasprintf ("%tu %d", (ptrdiff_t) 12345673, 33, 44, 55); + static const uint8_t expected[] = "12345673 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { + uint8_t *result = + my_xasprintf ("%Lg %d", (long double) 1.5, 33, 44, 55); + static const uint8_t expected[] = "1.5 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Hello"; + { + uint8_t *result = + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint8_t *result = + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint8_t *result = + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + uint8_t *result = + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint8_t *result = + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint8_t *result = + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + uint8_t *result = + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint8_t *result = + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint8_t *result = + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Hello 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + } + + /* Test the support of the 's' conversion specifier for strings. */ + + { + uint8_t *result = + my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55); + static const uint8_t expected[] = "Mr. Ronald Reagan 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55); + static const uint8_t expected[] = "Mr. Ronald Reagan 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* FLAG_LEFT. */ + uint8_t *result = + my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); + static const uint8_t expected[] = "Mr. Ronald Reagan 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* FLAG_ZERO: no effect. */ + uint8_t *result = + my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55); + static const uint8_t expected[] = "Mr. Ronald Reagan 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%a %d", 3.1416015625, 33, 44, 55); + static const uint8_t expected1[] = "0x1.922p+1 33"; + static const uint8_t expected2[] = "0x3.244p+0 33"; + static const uint8_t expected3[] = "0x6.488p-1 33"; + static const uint8_t expected4[] = "0xc.91p-2 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10a %d", 1.75, 33, 44, 55); + static const uint8_t expected1[] = " 0x1.cp+0 33"; + static const uint8_t expected2[] = " 0x3.8p-1 33"; + static const uint8_t expected3[] = " 0x7p-2 33"; + static const uint8_t expected4[] = " 0xep-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Small precision. */ + uint8_t *result = + my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); + static const uint8_t expected1[] = "0x1.c000000000p+0 33"; + static const uint8_t expected2[] = "0x3.8000000000p-1 33"; + static const uint8_t expected3[] = "0x7.0000000000p-2 33"; + static const uint8_t expected4[] = "0xe.0000000000p-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Large precision. */ + uint8_t *result = + my_xasprintf ("%.50a %d", 1.75, 33, 44, 55); + static const uint8_t expected1[] = "0x1.c0000000000000000000000000000000000000000000000000p+0 33"; + static const uint8_t expected2[] = "0x3.80000000000000000000000000000000000000000000000000p-1 33"; + static const uint8_t expected3[] = "0x7.00000000000000000000000000000000000000000000000000p-2 33"; + static const uint8_t expected4[] = "0xe.00000000000000000000000000000000000000000000000000p-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55); + static const uint8_t expected1[] = "0x1.922p+1 33"; + static const uint8_t expected2[] = "0x3.244p+0 33"; + static const uint8_t expected3[] = "0x6.488p-1 33"; + static const uint8_t expected4[] = "0xc.91p-2 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10La %d", 1.75L, 33, 44, 55); + static const uint8_t expected1[] = " 0x1.cp+0 33"; + static const uint8_t expected2[] = " 0x3.8p-1 33"; + static const uint8_t expected3[] = " 0x7p-2 33"; + static const uint8_t expected4[] = " 0xep-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Small precision. */ + uint8_t *result = + my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); + static const uint8_t expected1[] = "0x1.c000000000p+0 33"; + static const uint8_t expected2[] = "0x3.8000000000p-1 33"; + static const uint8_t expected3[] = "0x7.0000000000p-2 33"; + static const uint8_t expected4[] = "0xe.0000000000p-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + { /* Large precision. */ + uint8_t *result = + my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55); + static const uint8_t expected1[] = "0x1.c0000000000000000000000000000000000000000000000000p+0 33"; + static const uint8_t expected2[] = "0x3.80000000000000000000000000000000000000000000000000p-1 33"; + static const uint8_t expected3[] = "0x7.00000000000000000000000000000000000000000000000000p-2 33"; + static const uint8_t expected4[] = "0xe.00000000000000000000000000000000000000000000000000p-3 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); + free (result); + } + + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%f %d", 12.75, 33, 44, 55); + static const uint8_t expected[] = "12.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10f %d", 1.75, 33, 44, 55); + static const uint8_t expected[] = " 1.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); + static const uint8_t expected[] = "1234 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%Lf %d", 12.75L, 33, 44, 55); + static const uint8_t expected[] = "12.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10Lf %d", 1.75L, 33, 44, 55); + static const uint8_t expected[] = " 1.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); + static const uint8_t expected[] = "1234 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%F %d", 12.75, 33, 44, 55); + static const uint8_t expected[] = "12.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.F %d", 1234.0, 33, 44, 55); + static const uint8_t expected[] = "1234 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%LF %d", 12.75L, 33, 44, 55); + static const uint8_t expected[] = "12.750000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.LF %d", 1234.0L, 33, 44, 55); + static const uint8_t expected[] = "1234 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %e format directive. */ + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%e %d", 12.75, 33, 44, 55); + static const uint8_t expected1[] = "1.275000e+01 33"; + static const uint8_t expected2[] = "1.275000e+001 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%15e %d", 1.75, 33, 44, 55); + static const uint8_t expected1[] = " 1.750000e+00 33"; + static const uint8_t expected2[] = " 1.750000e+000 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); + static const uint8_t expected1[] = "1e+03 33"; + static const uint8_t expected2[] = "1e+003 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0); + free (result); + } + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%Le %d", 12.75L, 33, 44, 55); + static const uint8_t expected[] = "1.275000e+01 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55); + static const uint8_t expected[] = " 1.750000e+00 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); + static const uint8_t expected[] = "1e+03 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %g format directive. */ + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%g %d", 12.75, 33, 44, 55); + static const uint8_t expected[] = "12.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10g %d", 1.75, 33, 44, 55); + static const uint8_t expected[] = " 1.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); + static const uint8_t expected1[] = "1e+03 33"; + static const uint8_t expected2[] = "1e+003 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected1) == 0 + || u8_strcmp (result, expected2) == 0); + free (result); + } + + { /* A positive number. */ + uint8_t *result = + my_xasprintf ("%Lg %d", 12.75L, 33, 44, 55); + static const uint8_t expected[] = "12.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Width. */ + uint8_t *result = + my_xasprintf ("%10Lg %d", 1.75L, 33, 44, 55); + static const uint8_t expected[] = " 1.75 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + { /* Precision. */ + uint8_t *result = + my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); + static const uint8_t expected[] = "1e+03 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the %n format directive. */ + + { + int count = -1; + uint8_t *result = + my_xasprintf ("%d %n", 123, &count, 33, 44, 55); + static const uint8_t expected[] = "123 "; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (count == 4); + free (result); + } + + /* Test the support of the POSIX/XSI format strings with positions. */ + + { + uint8_t *result = + my_xasprintf ("%2$d %1$d", 33, 55); + static const uint8_t expected[] = "55 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + + /* Test the support of the grouping flag. */ + + { + uint8_t *result = + my_xasprintf ("%'d %d", 1234567, 99); + ASSERT (result != NULL); + ASSERT (result[u8_strlen (result) - 1] == '9'); + free (result); + } + + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ + { + uint8_t *result = + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint8_t *result = + my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint8_t *result = + my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint8_t *result = + my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint16_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + uint8_t *result = + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint8_t *result = + my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint8_t *result = + my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint8_t *result = + my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + } + + { + static const uint32_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + uint8_t *result = + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* Width. */ + uint8_t *result = + my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ + uint8_t *result = + my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + uint8_t *result = + my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); + static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + free (result); + } + } + + /* Test non-ASCII characters in the format string. */ + + { + uint8_t *result = + my_xasprintf ("\304rger", 33, 44, 55); + ASSERT (result == NULL && errno == EINVAL); + } +} diff --git a/tests/unistdio/test-u8-vasnprintf1.c b/tests/unistdio/test-u8-vasnprintf1.c new file mode 100644 index 000000000..3cf9d93f2 --- /dev/null +++ b/tests/unistdio/test-u8-vasnprintf1.c @@ -0,0 +1,88 @@ +/* Test of u8_vasnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u8-asnprintf1.h" +#include "test-u8-printf1.h" + +static uint8_t * +my_asnprintf (uint8_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint8_t *ret; + + va_start (args, format); + ret = u8_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static uint8_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + size_t length; + uint8_t *ret; + + va_start (args, format); + ret = u8_vasnprintf (NULL, &length, format, args); + va_end (args); + if (ret != NULL) + ASSERT (length == u8_strlen (ret)); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u8-vasnprintf2.c b/tests/unistdio/test-u8-vasnprintf2.c new file mode 100644 index 000000000..ba6f2a486 --- /dev/null +++ b/tests/unistdio/test-u8-vasnprintf2.c @@ -0,0 +1,122 @@ +/* Test of u8_vasnprintf() function in an ISO-8859-1 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...)) +{ + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\304rger"; /* Ärger */ + { + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = "\303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = " \303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = "\303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = " \303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + } +} + +static uint8_t * +my_asnprintf (uint8_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint8_t *ret; + + va_start (args, format); + ret = u8_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u8-vasnprintf2.sh b/tests/unistdio/test-u8-vasnprintf2.sh new file mode 100755 index 000000000..ea5fcb080 --- /dev/null +++ b/tests/unistdio/test-u8-vasnprintf2.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a traditional french locale is installed. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR != none; then + testlocale=$LOCALE_FR +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-u8-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-u8-vasnprintf2${EXEEXT} diff --git a/tests/unistdio/test-u8-vasnprintf3.c b/tests/unistdio/test-u8-vasnprintf3.c new file mode 100644 index 000000000..0772331cb --- /dev/null +++ b/tests/unistdio/test-u8-vasnprintf3.c @@ -0,0 +1,122 @@ +/* Test of u8_vasnprintf() function in an UTF-8 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...)) +{ + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\303\204rger"; /* Ärger */ + { + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = "\303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = " \303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = "\303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + uint8_t *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + static const uint8_t expected[] = " \303\204rger 33"; + ASSERT (result != NULL); + ASSERT (u8_strcmp (result, expected) == 0); + ASSERT (length == u8_strlen (result)); + free (result); + } + } +} + +static uint8_t * +my_asnprintf (uint8_t *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + uint8_t *ret; + + va_start (args, format); + ret = u8_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u8-vasnprintf3.sh b/tests/unistdio/test-u8-vasnprintf3.sh new file mode 100755 index 000000000..9df0044ad --- /dev/null +++ b/tests/unistdio/test-u8-vasnprintf3.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a french Unicode locale is installed. +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR_UTF8 != none; then + testlocale=$LOCALE_FR_UTF8 +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no french Unicode locale is installed" + else + echo "Skipping test: no french Unicode locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-u8-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-u8-vasnprintf3${EXEEXT} diff --git a/tests/unistdio/test-u8-vasprintf1.c b/tests/unistdio/test-u8-vasprintf1.c new file mode 100644 index 000000000..c59b3a529 --- /dev/null +++ b/tests/unistdio/test-u8-vasprintf1.c @@ -0,0 +1,75 @@ +/* Test of u8_vasprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u8-printf1.h" + +static uint8_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint8_t *result; + int retval; + + va_start (args, format); + retval = u8_vasprintf (&result, format, args); + va_end (args); + if (retval < 0) + return NULL; + ASSERT (result != NULL); + return result; +} + +static void +test_vasprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasprintf (); + return 0; +} diff --git a/tests/unistdio/test-u8-vsnprintf1.c b/tests/unistdio/test-u8-vsnprintf1.c new file mode 100644 index 000000000..a11bf91a9 --- /dev/null +++ b/tests/unistdio/test-u8-vsnprintf1.c @@ -0,0 +1,80 @@ +/* Test of u8_vsnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u8-printf1.h" + +static uint8_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint8_t buf[1000]; + int retval; + size_t length; + uint8_t *result; + + va_start (args, format); + retval = u8_vsnprintf (buf, sizeof (buf), format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (buf)) + return NULL; + length = u8_strlen (buf); + result = XNMALLOC (length + 1, uint8_t); + u8_cpy (result, buf, length + 1); + return result; +} + +static void +test_vsnprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsnprintf (); + return 0; +} diff --git a/tests/unistdio/test-u8-vsprintf1.c b/tests/unistdio/test-u8-vsprintf1.c new file mode 100644 index 000000000..4c3563854 --- /dev/null +++ b/tests/unistdio/test-u8-vsprintf1.c @@ -0,0 +1,80 @@ +/* Test of u8_vsprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "unistr.h" +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-u8-printf1.h" + +static uint8_t * +my_xasprintf (const char *format, ...) +{ + va_list args; + uint8_t buf[1000]; + int retval; + size_t length; + uint8_t *result; + + va_start (args, format); + retval = u8_vsprintf (buf, format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (buf)) + return NULL; + length = u8_strlen (buf); + result = XNMALLOC (length + 1, uint8_t); + u8_cpy (result, buf, length + 1); + return result; +} + +static void +test_vsprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsprintf (); + return 0; +} diff --git a/tests/unistdio/test-ulc-asnprintf1.c b/tests/unistdio/test-ulc-asnprintf1.c new file mode 100644 index 000000000..57cdb05ac --- /dev/null +++ b/tests/unistdio/test-ulc-asnprintf1.c @@ -0,0 +1,56 @@ +/* Test of ulc_asnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-ulc-asnprintf1.h" + +static void +test_asnprintf () +{ + test_function (ulc_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + test_asnprintf (); + return 0; +} diff --git a/tests/unistdio/test-ulc-asnprintf1.h b/tests/unistdio/test-ulc-asnprintf1.h new file mode 100644 index 000000000..168d6723b --- /dev/null +++ b/tests/unistdio/test-ulc-asnprintf1.h @@ -0,0 +1,55 @@ +/* Test of ulc_[v]asnprintf() functions. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) +{ + char buf[8]; + int size; + + /* Test return value convention. */ + + for (size = 0; size <= 8; size++) + { + size_t length = size; + char *result = my_asnprintf (NULL, &length, "%d", 12345); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12345") == 0); + ASSERT (length == 5); + free (result); + } + + for (size = 0; size <= 8; size++) + { + size_t length; + char *result; + + memcpy (buf, "DEADBEEF", 8); + length = size; + result = my_asnprintf (buf, &length, "%d", 12345); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12345") == 0); + ASSERT (length == 5); + if (size < 6) + ASSERT (result != buf); + ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); + if (result != buf) + free (result); + } +} diff --git a/tests/unistdio/test-ulc-printf1.h b/tests/unistdio/test-ulc-printf1.h new file mode 100644 index 000000000..efcc48f67 --- /dev/null +++ b/tests/unistdio/test-ulc-printf1.h @@ -0,0 +1,499 @@ +/* Test of ulc_v[a]s[n]printf() functions. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_xfunction (char * (*my_xasprintf) (const char *, ...)) +{ + /* Test support of size specifiers as in C99. */ + + { + char *result = + my_xasprintf ("%ju %d", (uintmax_t) 12345671, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12345671 33") == 0); + free (result); + } + + { + char *result = + my_xasprintf ("%zu %d", (size_t) 12345672, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12345672 33") == 0); + free (result); + } + + { + char *result = + my_xasprintf ("%tu %d", (ptrdiff_t) 12345673, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12345673 33") == 0); + free (result); + } + + { + char *result = + my_xasprintf ("%Lg %d", (long double) 1.5, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.5 33") == 0); + free (result); + } + + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Hello"; + { + char *result = + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } + { /* Width. */ + char *result = + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + { /* FLAG_LEFT. */ + char *result = + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + char *result = + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + } + + { + static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + char *result = + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } + { /* Width. */ + char *result = + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + { /* FLAG_LEFT. */ + char *result = + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + char *result = + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + } + + { + static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; + { + char *result = + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } + { /* Width. */ + char *result = + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + { /* FLAG_LEFT. */ + char *result = + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Hello 33") == 0); + free (result); + } + { /* FLAG_ZERO: no effect. */ + char *result = + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Hello 33") == 0); + free (result); + } + } + + /* Test the support of the 's' conversion specifier for strings. */ + + { + char *result = + my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0); + free (result); + } + + { /* FLAG_LEFT. */ + char *result = + my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0); + free (result); + } + + { /* FLAG_ZERO: no effect. */ + char *result = + my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0); + free (result); + } + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + { /* A positive number. */ + char *result = + my_xasprintf ("%a %d", 3.1416015625, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.922p+1 33") == 0 + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%10a %d", 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); + free (result); + } + + { /* Small precision. */ + char *result = + my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); + free (result); + } + + { /* Large precision. */ + char *result = + my_xasprintf ("%.50a %d", 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + free (result); + } + + { /* A positive number. */ + char *result = + my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.922p+1 33") == 0 + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%10La %d", 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); + free (result); + } + + { /* Small precision. */ + char *result = + my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); + free (result); + } + + { /* Large precision. */ + char *result = + my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + free (result); + } + + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + char *result = + my_xasprintf ("%f %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%10f %d", 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + free (result); + } + + { /* A positive number. */ + char *result = + my_xasprintf ("%Lf %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%10Lf %d", 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + free (result); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + char *result = + my_xasprintf ("%F %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.F %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + free (result); + } + + { /* A positive number. */ + char *result = + my_xasprintf ("%LF %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.LF %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + free (result); + } + + /* Test the support of the %e format directive. */ + + { /* A positive number. */ + char *result = + my_xasprintf ("%e %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.275000e+01 33") == 0 + || strcmp (result, "1.275000e+001 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%15e %d", 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0 + || strcmp (result, " 1.750000e+000 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); + free (result); + } + + { /* A positive number. */ + char *result = + my_xasprintf ("%Le %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1.275000e+01 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.750000e+00 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1e+03 33") == 0); + free (result); + } + + /* Test the support of the %g format directive. */ + + { /* A positive number. */ + char *result = + my_xasprintf ("%g %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.75 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%10g %d", 1.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.75 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1e+03 33") == 0 + || strcmp (result, "1e+003 33") == 0); + free (result); + } + + { /* A positive number. */ + char *result = + my_xasprintf ("%Lg %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.75 33") == 0); + free (result); + } + + { /* Width. */ + char *result = + my_xasprintf ("%10Lg %d", 1.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " 1.75 33") == 0); + free (result); + } + + { /* Precision. */ + char *result = + my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1e+03 33") == 0); + free (result); + } + + /* Test the support of the %n format directive. */ + + { + int count = -1; + char *result = + my_xasprintf ("%d %n", 123, &count, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "123 ") == 0); + ASSERT (count == 4); + free (result); + } + + /* Test the support of the POSIX/XSI format strings with positions. */ + + { + char *result = + my_xasprintf ("%2$d %1$d", 33, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "55 33") == 0); + free (result); + } + + /* Test the support of the grouping flag. */ + + { + char *result = + my_xasprintf ("%'d %d", 1234567, 99); + ASSERT (result != NULL); + ASSERT (result[strlen (result) - 1] == '9'); + free (result); + } +} diff --git a/tests/unistdio/test-ulc-vasnprintf1.c b/tests/unistdio/test-ulc-vasnprintf1.c new file mode 100644 index 000000000..e6c0dd2f1 --- /dev/null +++ b/tests/unistdio/test-ulc-vasnprintf1.c @@ -0,0 +1,85 @@ +/* Test of ulc_vasnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-ulc-asnprintf1.h" +#include "test-ulc-printf1.h" + +static char * +my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + char *ret; + + va_start (args, format); + ret = ulc_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static char * +my_xasprintf (const char *format, ...) +{ + va_list args; + size_t length; + char *ret; + + va_start (args, format); + ret = ulc_vasnprintf (NULL, &length, format, args); + va_end (args); + if (ret != NULL) + ASSERT (length == strlen (ret)); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-ulc-vasnprintf2.c b/tests/unistdio/test-ulc-vasnprintf2.c new file mode 100644 index 000000000..5d514c9cd --- /dev/null +++ b/tests/unistdio/test-ulc-vasnprintf2.c @@ -0,0 +1,258 @@ +/* Test of ulc_vasnprintf() function in an ISO-8859-1 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) +{ + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 + || strcmp (result, "Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 + || strcmp (result, " Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 + || strcmp (result, "Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 + || strcmp (result, " Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } + + { + static const uint16_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 + || strcmp (result, "Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 + || strcmp (result, " Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 + || strcmp (result, "Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 + || strcmp (result, " Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } + + { + static const uint32_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 + || strcmp (result, "Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 + || strcmp (result, " Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 + || strcmp (result, "Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 + || strcmp (result, " Rafal Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } + + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\304rger"; /* Ärger */ + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "\304rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " \304rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "\304rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " \304rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } +} + +static char * +my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + char *ret; + + va_start (args, format); + ret = ulc_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-ulc-vasnprintf2.sh b/tests/unistdio/test-ulc-vasnprintf2.sh new file mode 100755 index 000000000..39056a638 --- /dev/null +++ b/tests/unistdio/test-ulc-vasnprintf2.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a traditional french locale is installed. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR != none; then + testlocale=$LOCALE_FR +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-ulc-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-ulc-vasnprintf2${EXEEXT} diff --git a/tests/unistdio/test-ulc-vasnprintf3.c b/tests/unistdio/test-ulc-vasnprintf3.c new file mode 100644 index 000000000..3072cec5e --- /dev/null +++ b/tests/unistdio/test-ulc-vasnprintf3.c @@ -0,0 +1,246 @@ +/* Test of ulc_vasnprintf() function in an UTF-8 locale. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +static void +test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) +{ + /* Test the support of the 'U' conversion specifier for Unicode strings. */ + + { + static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } + + { + static const uint16_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } + + { + static const uint32_t unicode_string[] = /* Rafał Maszkowski */ + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } + + /* Test the support of the 's' conversion specifier for strings. */ + + { + const char *locale_string = "\303\204rger"; /* Ärger */ + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "\303\204rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " \303\204rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "\303\204rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " \303\204rger 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + } +} + +static char * +my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + char *ret; + + va_start (args, format); + ret = ulc_vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return ret; +} + +static void +test_vasnprintf () +{ + test_function (my_asnprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_vasnprintf (); + return 0; +} diff --git a/tests/unistdio/test-ulc-vasnprintf3.sh b/tests/unistdio/test-ulc-vasnprintf3.sh new file mode 100755 index 000000000..caa528a63 --- /dev/null +++ b/tests/unistdio/test-ulc-vasnprintf3.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Test whether a french Unicode locale is installed. +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR_UTF8 != none; then + testlocale=$LOCALE_FR_UTF8 +else + if test -f /usr/bin/localedef; then + echo "Skipping test: no french Unicode locale is installed" + else + echo "Skipping test: no french Unicode locale is supported" + fi + exit 77 +fi + +LC_ALL=$testlocale \ +./test-ulc-vasnprintf1${EXEEXT} \ + || exit 1 + +LC_ALL=$testlocale \ +./test-ulc-vasnprintf3${EXEEXT} diff --git a/tests/unistdio/test-ulc-vasprintf1.c b/tests/unistdio/test-ulc-vasprintf1.c new file mode 100644 index 000000000..d1f568c9c --- /dev/null +++ b/tests/unistdio/test-ulc-vasprintf1.c @@ -0,0 +1,72 @@ +/* Test of ulc_vasprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-ulc-printf1.h" + +static char * +my_xasprintf (const char *format, ...) +{ + va_list args; + char *result; + int retval; + + va_start (args, format); + retval = ulc_vasprintf (&result, format, args); + va_end (args); + if (retval < 0) + return NULL; + ASSERT (result != NULL); + return result; +} + +static void +test_vasprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vasprintf (); + return 0; +} diff --git a/tests/unistdio/test-ulc-vsnprintf1.c b/tests/unistdio/test-ulc-vsnprintf1.c new file mode 100644 index 000000000..7d9d93800 --- /dev/null +++ b/tests/unistdio/test-ulc-vsnprintf1.c @@ -0,0 +1,73 @@ +/* Test of ulc_vsnprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-ulc-printf1.h" + +static char * +my_xasprintf (const char *format, ...) +{ + va_list args; + char result[1000]; + int retval; + + va_start (args, format); + retval = ulc_vsnprintf (result, sizeof (result), format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (result)) + return NULL; + return xstrdup (result); +} + +static void +test_vsnprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsnprintf (); + return 0; +} diff --git a/tests/unistdio/test-ulc-vsprintf1.c b/tests/unistdio/test-ulc-vsprintf1.c new file mode 100644 index 000000000..d270f02e9 --- /dev/null +++ b/tests/unistdio/test-ulc-vsprintf1.c @@ -0,0 +1,73 @@ +/* Test of ulc_vsprintf() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "unistdio.h" + +#include +#include +#include +#include +#include +#include + +#include "xalloc.h" + +#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-ulc-printf1.h" + +static char * +my_xasprintf (const char *format, ...) +{ + va_list args; + char result[1000]; + int retval; + + va_start (args, format); + retval = ulc_vsprintf (result, format, args); + va_end (args); + if (retval < 0 || retval >= (int) sizeof (result)) + return NULL; + return xstrdup (result); +} + +static void +test_vsprintf () +{ + test_xfunction (my_xasprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vsprintf (); + return 0; +} -- 2.11.0