From: Roland McGrath Date: Wed, 24 Jan 1996 08:23:33 +0000 (+0000) Subject: * stdio-common/Makefile (tests): Add scanf[1-9]. X-Git-Tag: upstream/2.30~29710 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a66067befed6a453b75a2a0caac2c50d3a6e9cfb;p=external%2Fglibc.git * stdio-common/Makefile (tests): Add scanf[1-9]. * stdio-common/scanf[1-9].c: New files. Bug tests from hjl. Wed Jan 24 03:22:07 1996 Roland McGrath * stdio-common/Makefile (tests): Add scanf[1-9]. * stdio-common/scanf[1-9].c: New files. Bug tests from hjl. --- diff --git a/ChangeLog b/ChangeLog index 291b2bf..0c5af3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jan 24 03:22:07 1996 Roland McGrath + + * stdio-common/Makefile (tests): Add scanf[1-9]. + * stdio-common/scanf[1-9].c: New files. Bug tests from hjl. + Wed Jan 24 04:18:36 1996 Paul Eggert * strftime.c (strftime): diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 96a2731..deb6f92 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -40,7 +40,8 @@ tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \ temptest tst-fileno test-fwrite \ xbug errnobug \ bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 \ - tfformat tiformat tstdiomisc + tfformat tiformat tstdiomisc \ + scanf1 scanf2 scanf3 scanf4 scanf5 scanf6 scanf7 scanf8 scanf9 include ../Rules diff --git a/stdio-common/scanf1.c b/stdio-common/scanf1.c new file mode 100644 index 0000000..4a5be88 --- /dev/null +++ b/stdio-common/scanf1.c @@ -0,0 +1,15 @@ +#include +#include + +int +main() +{ + int i,n,r; + + n = i = r = -1; + r = sscanf("1234:567", "%d%n", &i, &n); + printf("%d %d %d\n", r, n, i); + if (r != 1 || i != 1234 || n != 4) + abort (); + return 0; +} diff --git a/stdio-common/scanf2.c b/stdio-common/scanf2.c new file mode 100644 index 0000000..06c97c6 --- /dev/null +++ b/stdio-common/scanf2.c @@ -0,0 +1,24 @@ +#include +#include + +main() +{ + int point, x, y; + + point = x = y = -1; + sscanf("0x10 10", "%x %x", &x, &y); + printf("%d %d\n", x, y); + if (x != 0x10 || y != 0x10) + abort (); + point = x = y = -1; + sscanf("P012349876", "P%1d%4d%4d", &point, &x, &y); + printf("%d %d %d\n", point, x, y); + if (point != 0 || x != 1234 || y != 9876) + abort (); + point = x = y = -1; + sscanf("P112349876", "P%1d%4d%4d", &point, &x, &y); + printf("%d %d %d\n", point, x, y); + if (point != 1 || x != 1234 || y != 9876) + abort (); + return 0; +} diff --git a/stdio-common/scanf3.c b/stdio-common/scanf3.c new file mode 100644 index 0000000..1a77522 --- /dev/null +++ b/stdio-common/scanf3.c @@ -0,0 +1,30 @@ +#include +#include + +int main(int arc, char *argv) +{ + int n, res; + unsigned int val; + char *s; + + s = "111"; + + val = n = -1; + res = sscanf(s, "%u %n", &val, &n); + printf("Result of sscanf = %d\n", res); + printf("Scanned format %%u = %u\n", val); + printf("Possibly scanned format %%n = %d\n", n); + if (n != 3 || val != 111 || res != 1) + abort (); + + val = n = -1; + res = sscanf(s, "%u%n", &val, &n); + printf("Result of sscanf = %d\n", res); + printf("Scanned format %%u = %u\n", val); + printf("Possibly scanned format %%n = %d\n", n); + if (n != 3 || val != 111 || res != 1) + abort (); + + return 0; + return 0; +} diff --git a/stdio-common/scanf4.c b/stdio-common/scanf4.c new file mode 100644 index 0000000..b624b69 --- /dev/null +++ b/stdio-common/scanf4.c @@ -0,0 +1,30 @@ +#include + +int main(int arc, char *argv) +{ + int n, res; + unsigned int val; + + FILE *fp = fopen ("/dev/null", "r"); + + val = 0; + res = fscanf(fp, "%n", &val); + + printf("Result of fscanf %%n = %d\n", res); + printf("Scanned format = %d\n", val); + + res = fscanf(fp, ""); + printf("Result of fscanf \"\" = %d\n", res); + if (res != 0) + abort (); + + res = fscanf(fp, "BLURB"); + printf("Result of fscanf \"BLURB\" = %d\n", res); + if (res >= 0) + abort (); + + fclose (fp); + + return 0; + return 0; +} diff --git a/stdio-common/scanf5.c b/stdio-common/scanf5.c new file mode 100644 index 0000000..b52e853 --- /dev/null +++ b/stdio-common/scanf5.c @@ -0,0 +1,20 @@ +#include + +int +main() +{ + int a, b; + + a = b = -1; + sscanf ("12ab", "%dab%n", &a, &b); + printf ("%d, %d\n", a, b); + if (a != 12 || b != 4) + abort (); + + a = b = -1; + sscanf ("12ab100", "%dab%n100", &a, &b); + printf ("%d, %d\n", a, b); + if (a != 12 || b != 4) + abort (); + return 0; +} diff --git a/stdio-common/scanf6.c b/stdio-common/scanf6.c new file mode 100644 index 0000000..36055aa --- /dev/null +++ b/stdio-common/scanf6.c @@ -0,0 +1,15 @@ +#include +#include + +main () +{ + int n = -1; + char c = '!'; + int ret; + + ret = sscanf ("0x", "%i%c", &n, &c); + printf ("ret: %d, n: %d, c: %c\n", ret, n, c); + if (ret != 2 || n != 0 || c != 'x') + abort (); + return 0; +} diff --git a/stdio-common/scanf7.c b/stdio-common/scanf7.c new file mode 100644 index 0000000..386dac4 --- /dev/null +++ b/stdio-common/scanf7.c @@ -0,0 +1,22 @@ +#include +#include + +main () +{ + long long int n; + int ret; + + n = -1; + ret = sscanf ("1000", "%lld", &n); + printf ("%%lld: ret: %d, n: %Ld, c: %c\n", ret, n); + if (ret != 1 || n != 1000L) + abort (); + + n = -2; + ret = sscanf ("1000", "%llld", &n); + printf ("%%llld: ret: %d, n: %Ld\n", ret, n); + if (ret != 0 || n >= 0L) + abort (); + + return 0; +} diff --git a/stdio-common/scanf8.c b/stdio-common/scanf8.c new file mode 100644 index 0000000..316f45d --- /dev/null +++ b/stdio-common/scanf8.c @@ -0,0 +1,15 @@ +#include +#include +#include + +main () +{ + int ret; + char buf [1024] = "Ooops"; + + ret = sscanf ("static char Term_bits[] = {", "static char %s = {", buf); + printf ("ret: %d, name: %s\n", ret, buf); + if (ret != 1 || strcmp (buf, "Term_bits[]") != 0) + abort (); + return 0; +} diff --git a/stdio-common/scanf9.c b/stdio-common/scanf9.c new file mode 100644 index 0000000..52bff08 --- /dev/null +++ b/stdio-common/scanf9.c @@ -0,0 +1,23 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + int matches; + char str[10]; + + str[0] = '\0'; + matches = -9; + matches = sscanf("x ]", "%[^] ]", str); + printf("Matches = %d, string str = \"%s\".\n", matches, str); + printf("str should be \"x\".\n"); + if (strcmp (str, "x")) abort (); + str[0] = '\0'; + matches = -9; + matches = sscanf(" ] x", "%[] ]", str); + printf("Matches = %d, string str = \"%s\".\n", matches, str); + printf("str should be \" ] \".\n"); + if (strcmp (str, " ] ")) abort (); + exit(0); + return 0; +}