| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <stdarg.h> |
| 20 |
#include <stdint.h> |
| 21 |
#include <stdio.h> |
| 22 |
#include <string.h> |
| 23 |
#include <wchar.h> |
| 24 |
|
| 25 |
#include <support/check.h> |
| 26 |
|
| 27 |
#define CLEAR_VARGS \ |
| 28 |
va_start (args, format); \ |
| 29 |
ldptr = va_arg (args, long double *); \ |
| 30 |
fptr = va_arg (args, float *); \ |
| 31 |
*ldptr = 0; \ |
| 32 |
*fptr = 0; \ |
| 33 |
va_end (args); |
| 34 |
|
| 35 |
#define CHECK_VARGS \ |
| 36 |
va_start (args, format); \ |
| 37 |
ldptr = va_arg (args, long double *); \ |
| 38 |
fptr = va_arg (args, float *); \ |
| 39 |
va_end (args); \ |
| 40 |
if (*ldptr == -1 && *fptr == -2 && ret == 2) \ |
| 41 |
printf ("OK"); \ |
| 42 |
else \ |
| 43 |
printf ("ERROR (%Lf %f %d)", *ldptr, *fptr, ret); \ |
| 44 |
printf ("\n"); |
| 45 |
|
| 46 |
#define CLEAR_VALUE \ |
| 47 |
ld = 0; \ |
| 48 |
f = 0; |
| 49 |
|
| 50 |
#define CHECK_VALUE \ |
| 51 |
if (ld == -1 && f == -2 && ret == 2) \ |
| 52 |
printf ("OK"); \ |
| 53 |
else \ |
| 54 |
printf ("ERROR (%Lf %f %d)", ld, f, ret); \ |
| 55 |
printf ("\n"); |
| 56 |
|
| 57 |
static void |
| 58 |
do_test_call (FILE *stream, CHAR *string, const CHAR *format, ...) |
| 59 |
{ |
| 60 |
float f; |
| 61 |
long double ld; |
| 62 |
float *fptr; |
| 63 |
long double *ldptr; |
| 64 |
va_list args; |
| 65 |
int ret; |
| 66 |
|
| 67 |
CLEAR_VALUE |
| 68 |
printf ("fscanf: "); |
| 69 |
ret = FSCANF (stream, format, &ld, &f); |
| 70 |
CHECK_VALUE |
| 71 |
|
| 72 |
CLEAR_VALUE |
| 73 |
printf ("scanf: "); |
| 74 |
ret = SCANF (format, &ld, &f); |
| 75 |
CHECK_VALUE |
| 76 |
|
| 77 |
CLEAR_VALUE |
| 78 |
printf ("sscanf: "); |
| 79 |
ret = SSCANF (string, format, &ld, &f); |
| 80 |
CHECK_VALUE |
| 81 |
|
| 82 |
CLEAR_VARGS |
| 83 |
printf ("vfscanf: "); |
| 84 |
va_start (args, format); |
| 85 |
ret = VFSCANF (stream, format, args); |
| 86 |
va_end (args); |
| 87 |
CHECK_VARGS |
| 88 |
|
| 89 |
CLEAR_VARGS |
| 90 |
printf ("vscanf: "); |
| 91 |
va_start (args, format); |
| 92 |
ret = VSCANF (format, args); |
| 93 |
va_end (args); |
| 94 |
CHECK_VARGS |
| 95 |
|
| 96 |
CLEAR_VARGS |
| 97 |
printf ("vsscanf: "); |
| 98 |
va_start (args, format); |
| 99 |
ret = VSSCANF (string, format, args); |
| 100 |
va_end (args); |
| 101 |
CHECK_VARGS |
| 102 |
} |
| 103 |
|
| 104 |
static int |
| 105 |
do_test (void) |
| 106 |
{ |
| 107 |
CHAR string[256]; |
| 108 |
float f; |
| 109 |
long double ld; |
| 110 |
|
| 111 |
|
| 112 |
STRCPY (string, |
| 113 |
L ("-1.0 -2.0\n") |
| 114 |
L ("-1.0 -2.0\n") ); |
| 115 |
do_test_call (stdin, string, L("%Lf %f"), &ld, &f); |
| 116 |
|
| 117 |
|
| 118 |
STRCPY (string, |
| 119 |
L ("-0x1.0p+0 -0x2.0p+0\n") |
| 120 |
L ("-0x1.0p+0 -0x2.0p+0\n") ); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
#if __GLIBC_USE (DEPRECATED_SCANF) |
| 126 |
# define FMT "%La %a" |
| 127 |
#else |
| 128 |
# define FMT "%La %as" |
| 129 |
#endif |
| 130 |
do_test_call (stdin, string, L(FMT), &ld, &f); |
| 131 |
|
| 132 |
return 0; |
| 133 |
} |
| 134 |
|
| 135 |
#include <support/test-driver.c> |