Changes in uspace/lib/posix/source/stdio/scanf.c [a3da2b2:6b646dc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/source/stdio/scanf.c
ra3da2b2 r6b646dc 34 34 35 35 #define LIBPOSIX_INTERNAL 36 37 /* Must be first. */ 38 #include "posix/stdbool.h" 36 #define __POSIX_DEF__(x) posix_##x 39 37 40 38 #include "posix/assert.h" … … 50 48 #include "../internal/common.h" 51 49 #include "libc/malloc.h" 50 #include "libc/stdbool.h" 52 51 53 52 /** Unified data type for possible data sources for scanf. */ … … 1221 1220 } 1222 1221 1223 // FIXME: put the testcases to the app/tester after scanf is included into libc1224 1225 #if 01226 1227 //#include <stdio.h>1228 //#include <malloc.h>1229 //#include <string.h>1230 1231 #define test_val(fmt, exp_val, act_val) \1232 if (exp_val == act_val) { \1233 printf("succ, expected "fmt", actual "fmt"\n", exp_val, act_val); \1234 } else { \1235 printf("fail, expected "fmt", actual "fmt"\n", exp_val, act_val); \1236 ++fail; \1237 }1238 1239 #define test_str(fmt, exp_str, act_str) \1240 if (posix_strcmp(exp_str, act_str) == 0) { \1241 printf("succ, expected "fmt", actual "fmt"\n", exp_str, act_str); \1242 } else { \1243 printf("fail, expected "fmt", actual "fmt"\n", exp_str, act_str); \1244 ++fail; \1245 }1246 1247 void __posix_scanf_test(void);1248 void __posix_scanf_test(void)1249 {1250 int fail = 0;1251 1252 int ret;1253 1254 unsigned char uhh;1255 signed char shh;1256 unsigned short uh;1257 short sh;1258 unsigned udef;1259 int sdef;1260 unsigned long ul;1261 long sl;1262 unsigned long long ull;1263 long long sll;1264 void *p;1265 1266 float f;1267 double d;1268 long double ld;1269 1270 char str[20];1271 char seq[20];1272 char scanset[20];1273 1274 char *pstr;1275 char *pseq;1276 char *pscanset;1277 1278 ret = posix_sscanf(1279 "\n j tt % \t -121314 98765 aqw 0765 0x77 0xABCDEF88 -99 884",1280 " j tt %%%3hhd%1hhu%3hd %3hu%u aqw%n %lo%llx %p %li %lld",1281 &shh, &uhh, &sh, &uh, &udef, &sdef, &ul, &ull, &p, &sl, &sll);1282 test_val("%d", -12, shh);1283 test_val("%u", 1, uhh);1284 test_val("%d", 314, sh);1285 test_val("%u", 987, uh);1286 test_val("%u", 65, udef);1287 test_val("%d", 28, sdef);1288 test_val("%lo", (unsigned long) 0765, ul);1289 test_val("%llx", (unsigned long long) 0x77, ull);1290 test_val("%p", (void *) 0xABCDEF88, p);1291 test_val("%ld", (long) -99, sl);1292 test_val("%lld", (long long) 884, sll);1293 test_val("%d", 10, ret);1294 1295 ret = posix_sscanf(1296 "\n \t\t1.0 -0x555.AP10 1234.5678e12",1297 "%f %lf %Lf",1298 &f, &d, &ld);1299 test_val("%f", 1.0, f);1300 test_val("%lf", (double) -0x555.AP10, d);1301 test_val("%Lf", (long double) 1234.5678e12, ld);1302 test_val("%d", 3, ret);1303 1304 ret = posix_sscanf(1305 "\n\n\thello world \n",1306 "%5s %ms",1307 str, &pstr);1308 test_str("%s", "hello", str);1309 test_str("%s", "world", pstr);1310 test_val("%d", 2, ret);1311 free(pstr);1312 1313 ret = posix_sscanf(1314 "\n\n\thello world \n",1315 " %5c %mc",1316 seq, &pseq);1317 seq[5] = '\0';1318 pseq[1] = '\0';1319 test_str("%s", "hello", seq);1320 test_str("%s", "w", pseq);1321 test_val("%d", 2, ret);1322 free(pseq);1323 1324 ret = posix_sscanf(1325 "\n\n\th-e-l-l-o world-] \n",1326 " %9[-eh-o] %m[^]-]",1327 scanset, &pscanset);1328 test_str("%s", "h-e-l-l-o", scanset);1329 test_str("%s", "world", pscanset);1330 test_val("%d", 2, ret);1331 free(pscanset);1332 1333 printf("Failed: %d\n", fail);1334 }1335 1336 #endif1337 1338 1222 /** @} 1339 1223 */
Note:
See TracChangeset
for help on using the changeset viewer.