scanf.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * Modified by Manuel Novoa III Mar 13, 2001
  3. *
  4. * The vfscanf routine was completely rewritten to add features and remove
  5. * bugs. The function __strtold, based on my strtod code in stdlib, was
  6. * added to provide floating point support for the scanf functions.
  7. *
  8. * So far they pass the test cases from glibc-2.1.3, except in two instances.
  9. * In one case, the test appears to be broken. The other case is something
  10. * I need to research further. This version of scanf assumes it can only
  11. * peek one character ahead. Apparently, glibc looks further. The difference
  12. * can be seen when parsing a floating point value in the character
  13. * sequence "100ergs". glibc is able to back up before the 'e' and return
  14. * a value of 100, whereas this scanf reports a bad match with the stream
  15. * pointer at 'r'. A similar situation can also happen when parsing hex
  16. * values prefixed by 0x or 0X; a failure would occur for "0xg". In order to
  17. * fix this, I need to rework the "ungetc" machinery in stdio.c again.
  18. * I do have one reference though, that seems to imply scanf has a single
  19. * character of lookahead.
  20. *
  21. * May 20, 2001
  22. *
  23. * Quote from ANSI/ISO C99 standard:
  24. *
  25. * fscanf pushes back at most one input character onto the input stream.
  26. * Therefore, some sequences that are acceptable to strtod, strtol, etc.,
  27. * are unacceptable to fscanf.
  28. *
  29. * So uClibc's *scanf functions conform to the standard, and glibc's
  30. * implementation doesn't for the "100ergs" case mentioned above.
  31. */
  32. #include <stdlib.h>
  33. #include <unistd.h>
  34. #include <stdio.h>
  35. #include <ctype.h>
  36. #include <string.h>
  37. #include <stdarg.h>
  38. #ifdef L_scanf
  39. #ifdef __STDC__
  40. int scanf(const char *fmt, ...)
  41. #else
  42. int scanf(fmt, va_alist)
  43. __const char *fmt;
  44. va_dcl
  45. #endif
  46. {
  47. va_list ptr;
  48. int rv;
  49. va_start(ptr, fmt);
  50. rv = vfscanf(stdin, fmt, ptr);
  51. va_end(ptr);
  52. return rv;
  53. }
  54. #endif
  55. #ifdef L_sscanf
  56. #ifdef __STDC__
  57. int sscanf(const char *sp, const char *fmt, ...)
  58. #else
  59. int sscanf(sp, fmt, va_alist)
  60. __const char *sp;
  61. __const char *fmt;
  62. va_dcl
  63. #endif
  64. {
  65. FILE string[1] = {
  66. {0, (unsigned char *) ((unsigned) -1), 0, 0, (char *) ((unsigned) -1),
  67. 0, -1, _IOFBF}
  68. };
  69. va_list ptr;
  70. int rv;
  71. string->bufpos = (unsigned char *) ((void *) sp);
  72. va_start(ptr, fmt);
  73. rv = vfscanf(string, fmt, ptr);
  74. va_end(ptr);
  75. return rv;
  76. }
  77. #endif
  78. #ifdef L_fscanf
  79. #ifdef __STDC__
  80. int fscanf(FILE * fp, const char *fmt, ...)
  81. #else
  82. int fscanf(fp, fmt, va_alist)
  83. FILE *fp;
  84. __const char *fmt;
  85. va_dcl
  86. #endif
  87. {
  88. va_list ptr;
  89. int rv;
  90. va_start(ptr, fmt);
  91. rv = vfscanf(fp, fmt, ptr);
  92. va_end(ptr);
  93. return rv;
  94. }
  95. #endif
  96. #ifdef L_vscanf
  97. int vscanf(fmt, ap)
  98. __const char *fmt;
  99. va_list ap;
  100. {
  101. return vfscanf(stdin, fmt, ap);
  102. }
  103. #endif
  104. #ifdef L_vsscanf
  105. int vsscanf(__const char *sp, __const char *fmt, va_list ap)
  106. {
  107. FILE string[1] = {
  108. {0, (unsigned char *) ((unsigned) -1), 0, 0, (char *) ((unsigned) -1),
  109. 0, -1, _IOFBF}
  110. };
  111. string->bufpos = (unsigned char *) sp;
  112. return vfscanf(string, fmt, ap);
  113. }
  114. #endif
  115. #ifdef L_vfscanf
  116. #include <assert.h>
  117. #include <ctype.h>
  118. #include <limits.h>
  119. static int valid_digit(char c, char base)
  120. {
  121. if (base == 16) {
  122. return isxdigit(c);
  123. } else {
  124. return (isdigit(c) && (c < '0' + base));
  125. }
  126. }
  127. extern unsigned long long
  128. _strto_ll(const char *str, char **endptr, int base, int uflag);
  129. extern unsigned long
  130. _strto_l(const char *str, char **endptr, int base, int uflag);
  131. struct scan_cookie {
  132. FILE *fp;
  133. int nread;
  134. int width;
  135. int width_flag;
  136. int ungot_char;
  137. int ungot_flag;
  138. };
  139. #ifdef __UCLIBC_HAS_LONG_LONG__
  140. static const char qual[] = "hl" /* "jtz" */ "Lq";
  141. /* char = -2, short = -1, int = 0, long = 1, long long = 2 */
  142. static const char qsz[] = { -1, 1, 2, 2 };
  143. #else
  144. static const char qual[] = "hl" /* "jtz" */;
  145. static const char qsz[] = { -1, 1, };
  146. #endif
  147. #ifdef __UCLIBC_HAS_FLOATS__
  148. static int __strtold(long double *ld, struct scan_cookie *sc);
  149. /*01234567890123456 */
  150. static const char spec[] = "%n[csoupxXidfeEgG";
  151. #else
  152. static const char spec[] = "%n[csoupxXid";
  153. #endif
  154. /* radix[i] <-> spec[i+5] o u p x X i d */
  155. static const char radix[] = { 8, 10, 16, 16, 16, 0, 10 };
  156. static void init_scan_cookie(struct scan_cookie *sc, FILE *fp)
  157. {
  158. sc->fp = fp;
  159. sc->nread = 0;
  160. sc->width_flag = 0;
  161. sc->ungot_flag = 0;
  162. if ((sc->ungot_char = getc(fp)) > 0) { /* not EOF or EOS */
  163. sc->ungot_flag = 1;
  164. }
  165. }
  166. static int scan_getc_nw(struct scan_cookie *sc)
  167. {
  168. if (sc->ungot_flag == 0) {
  169. sc->ungot_char = getc(sc->fp);
  170. } else {
  171. sc->ungot_flag = 0;
  172. }
  173. if (sc->ungot_char > 0) {
  174. ++sc->nread;
  175. }
  176. sc->width_flag = 0;
  177. return sc->ungot_char;
  178. }
  179. static int scan_getc(struct scan_cookie *sc)
  180. {
  181. if (sc->ungot_flag == 0) {
  182. sc->ungot_char = getc(sc->fp);
  183. }
  184. sc->width_flag = 1;
  185. if (--sc->width < 0) {
  186. sc->ungot_flag = 1;
  187. return 0;
  188. }
  189. sc->ungot_flag = 0;
  190. if (sc->ungot_char > 0) {
  191. ++sc->nread;
  192. }
  193. return sc->ungot_char;
  194. }
  195. static void scan_ungetc(struct scan_cookie *sc)
  196. {
  197. if (sc->ungot_flag != 0) {
  198. assert(sc->width < 0);
  199. return;
  200. }
  201. if (sc->width_flag) {
  202. ++sc->width;
  203. }
  204. sc->ungot_flag = 1;
  205. if (sc->ungot_char > 0) { /* not EOF or EOS */
  206. --sc->nread;
  207. }
  208. }
  209. static void kill_scan_cookie(struct scan_cookie *sc)
  210. {
  211. if (sc->ungot_flag) {
  212. ungetc(sc->ungot_char,sc->fp);
  213. }
  214. }
  215. int vfscanf(fp, format, ap)
  216. FILE *fp;
  217. const char *format;
  218. va_list ap;
  219. {
  220. #ifdef __UCLIBC_HAS_LONG_LONG__
  221. #define STRTO_L_(s,e,b,u) _strto_ll(s,e,b,u)
  222. #define MAX_DIGITS 64
  223. #define UV_TYPE unsigned long long
  224. #define V_TYPE long long
  225. #else
  226. #define STRTO_L_(s,e,b,u) _strto_l(s,e,b,u)
  227. #define MAX_DIGITS 32
  228. #define UV_TYPE unsigned long
  229. #define V_TYPE long
  230. #endif
  231. #ifdef __UCLIBC_HAS_FLOATS__
  232. long double ld;
  233. #endif
  234. UV_TYPE uv;
  235. struct scan_cookie sc;
  236. unsigned const char *fmt;
  237. const char *p;
  238. unsigned char *b;
  239. void *vp;
  240. int cc, i, cnt;
  241. signed char lval;
  242. unsigned char store, usflag, base, invert, r0, r1;
  243. unsigned char buf[MAX_DIGITS+2];
  244. unsigned char scanset[UCHAR_MAX + 1];
  245. init_scan_cookie(&sc,fp);
  246. fmt = (unsigned const char *) format;
  247. cnt = 0;
  248. while (*fmt) {
  249. store = 1;
  250. lval = 0;
  251. sc.width = INT_MAX;
  252. if (*fmt == '%') { /* Conversion specification. */
  253. ++fmt;
  254. if (*fmt == '*') { /* Suppress assignment. */
  255. store = 0;
  256. ++fmt;
  257. }
  258. for (i = 0 ; isdigit(*fmt) ; sc.width = i) {
  259. i = (i * 10) + (*fmt++ - '0'); /* Get specified width. */
  260. }
  261. for (i = 0 ; i < sizeof(qual) ; i++) { /* Optional qualifier. */
  262. if (qual[i] == *fmt) {
  263. ++fmt;
  264. lval += qsz[i];
  265. if ((i < 2) && (qual[i] == *fmt)) { /* Double h or l. */
  266. ++fmt;
  267. lval += qsz[i];
  268. }
  269. break;
  270. }
  271. }
  272. for (p = spec ; *p ; p++) { /* Process format specifier. */
  273. if (*fmt != *p) continue;
  274. if (p-spec < 1) { /* % - match a '%'*/
  275. goto matchchar;
  276. }
  277. if (p-spec < 2) { /* n - store number of chars read */
  278. *(va_arg(ap, int *)) = sc.nread;
  279. scan_getc_nw(&sc);
  280. goto nextfmt;
  281. }
  282. if (p-spec > 3) { /* skip white space if not c or [ */
  283. while (isspace(scan_getc_nw(&sc)))
  284. {}
  285. scan_ungetc(&sc);
  286. }
  287. if (p-spec < 5) { /* [,c,s - string conversions */
  288. invert = 0;
  289. if (*p == 'c') {
  290. invert = 1;
  291. if (sc.width == INT_MAX) {
  292. sc.width = 1;
  293. }
  294. }
  295. for (i=0 ; i<= UCHAR_MAX ; i++) {
  296. scanset[i] = ((*p == 's') ? (isspace(i) == 0) : 0);
  297. }
  298. if (*p == '[') { /* need to build a scanset */
  299. if (*++fmt == '^') {
  300. invert = 1;
  301. ++fmt;
  302. }
  303. if (*fmt == ']') {
  304. scanset[(int)']'] = 1;
  305. ++fmt;
  306. }
  307. r0 = 0;
  308. while (*fmt && *fmt !=']') { /* build scanset */
  309. if ((*fmt == '-') && r0 && (fmt[1] != ']')) {
  310. /* range */
  311. ++fmt;
  312. if (*fmt < r0) {
  313. r1 = r0;
  314. r0 = *fmt;
  315. } else {
  316. r1 = *fmt;
  317. }
  318. for (i=r0 ; i<= r1 ; i++) {
  319. scanset[i] = 1;
  320. }
  321. r0 = 0;
  322. } else {
  323. r0 = *fmt;
  324. scanset[r0] = 1;
  325. }
  326. ++fmt;
  327. }
  328. if (!*fmt) { /* format string exhausted! */
  329. goto done;
  330. }
  331. }
  332. /* ok -- back to common work */
  333. if (sc.width <= 0) {
  334. goto done;
  335. }
  336. if (store) {
  337. b = va_arg(ap, unsigned char *);
  338. } else {
  339. b = buf;
  340. }
  341. i = 0;
  342. cc = scan_getc(&sc);
  343. while ((cc>0) && (scanset[cc] != invert)) {
  344. i = store; /* yes, we stored something */
  345. *b = cc;
  346. b += store;
  347. cc = scan_getc(&sc);
  348. }
  349. if (*p != 'c') { /* nul-terminate the stored string */
  350. *b = 0;
  351. cnt += i;
  352. goto nextfmt;
  353. } else if (sc.width < 0) { /* case 'c' */
  354. cnt += store;
  355. goto nextfmt;
  356. }
  357. scan_ungetc(&sc);
  358. goto done;
  359. }
  360. if (p-spec < 12) { /* o,u,p,x,X,i,d - (un)signed integer */
  361. if (*p == 'p') {
  362. /* assume pointer same size as int or long. */
  363. lval = (sizeof(char *) == sizeof(long));
  364. }
  365. usflag = ((p-spec) < 10); /* (1)0 if (un)signed */
  366. base = radix[(int)(p-spec) - 5];
  367. b = buf;
  368. if (sc.width <= 0) {
  369. goto done;
  370. }
  371. cc = scan_getc(&sc);
  372. if ((cc == '+') || (cc == '-')) { /* Handle leading sign.*/
  373. *b++ = cc;
  374. cc = scan_getc(&sc);
  375. }
  376. if (cc == '0') { /* Possibly set base and handle prefix. */
  377. if ((base == 0) || (base == 16)) {
  378. cc = scan_getc(&sc);
  379. if ((cc == 'x') || (cc == 'X')) {
  380. /* We're committed to base 16 now. */
  381. base = 16;
  382. cc = scan_getc(&sc);
  383. } else { /* oops... back up */
  384. scan_ungetc(&sc);
  385. cc = '0';
  386. if (base == 0) {
  387. base = 8;
  388. }
  389. }
  390. }
  391. }
  392. /* At this point, we're ready to start reading digits. */
  393. if (cc == '0') {
  394. *b++ = cc; /* Store first leading 0 */
  395. do { /* but ignore others. */
  396. cc = scan_getc(&sc);
  397. } while (cc == '0');
  398. }
  399. while (valid_digit(cc,base)) { /* Now for nonzero digits.*/
  400. if (b - buf < MAX_DIGITS) {
  401. *b++ = cc;
  402. }
  403. cc = scan_getc(&sc);
  404. }
  405. *b = 0; /* null-terminate */
  406. if ((b == buf) || (*--b == '+') || (*b == '-')) {
  407. scan_ungetc(&sc);
  408. goto done; /* No digits! */
  409. }
  410. if (store) {
  411. if (*buf == '-') {
  412. usflag = 0;
  413. }
  414. uv = STRTO_L_(buf, NULL, base, usflag);
  415. vp = va_arg(ap, void *);
  416. switch (lval) {
  417. case 2: /* If no long long, treat as long . */
  418. #ifdef __UCLIBC_HAS_LONG_LONG__
  419. *((unsigned long long *)vp) = uv;
  420. break;
  421. #endif
  422. case 1:
  423. #if ULONG_MAX == UINT_MAX
  424. case 0: /* int and long int are the same */
  425. #endif
  426. #ifdef __UCLIBC_HAS_LONG_LONG__
  427. if (usflag) {
  428. if (uv > ULONG_MAX) {
  429. uv = ULONG_MAX;
  430. }
  431. } else if (((V_TYPE)uv) > LONG_MAX) {
  432. uv = LONG_MAX;
  433. } else if (((V_TYPE)uv) < LONG_MIN) {
  434. uv = (UV_TYPE) LONG_MIN;
  435. }
  436. #endif
  437. *((unsigned long *)vp) = (unsigned long)uv;
  438. break;
  439. #if ULONG_MAX != UINT_MAX
  440. case 0: /* int and long int are different */
  441. if (usflag) {
  442. if (uv > UINT_MAX) {
  443. uv = UINT_MAX;
  444. }
  445. } else if (((V_TYPE)uv) > INT_MAX) {
  446. uv = INT_MAX;
  447. } else if (((V_TYPE)uv) < INT_MIN) {
  448. uv = (UV_TYPE) INT_MIN;
  449. }
  450. *((unsigned int *)vp) = (unsigned int)uv;
  451. break;
  452. #endif
  453. case -1:
  454. if (usflag) {
  455. if (uv > USHRT_MAX) {
  456. uv = USHRT_MAX;
  457. }
  458. } else if (((V_TYPE)uv) > SHRT_MAX) {
  459. uv = SHRT_MAX;
  460. } else if (((V_TYPE)uv) < SHRT_MIN) {
  461. uv = (UV_TYPE) SHRT_MIN;
  462. }
  463. *((unsigned short *)vp) = (unsigned short)uv;
  464. break;
  465. case -2:
  466. if (usflag) {
  467. if (uv > UCHAR_MAX) {
  468. uv = UCHAR_MAX;
  469. }
  470. } else if (((V_TYPE)uv) > CHAR_MAX) {
  471. uv = CHAR_MAX;
  472. } else if (((V_TYPE)uv) < CHAR_MIN) {
  473. uv = (UV_TYPE) CHAR_MIN;
  474. }
  475. *((unsigned char *)vp) = (unsigned char) uv;
  476. break;
  477. default:
  478. assert(0);
  479. }
  480. ++cnt;
  481. }
  482. goto nextfmt;
  483. }
  484. #ifdef __UCLIBC_HAS_FLOATS__
  485. else { /* floating point */
  486. if (sc.width <= 0) {
  487. goto done;
  488. }
  489. if (__strtold(&ld, &sc)) { /* Success! */
  490. if (store) {
  491. vp = va_arg(ap, void *);
  492. switch (lval) {
  493. case 2:
  494. *((long double *)vp) = ld;
  495. break;
  496. case 1:
  497. *((double *)vp) = (double) ld;
  498. break;
  499. case 0:
  500. *((float *)vp) = (float) ld;
  501. break;
  502. default: /* Illegal qualifier! */
  503. assert(0);
  504. goto done;
  505. }
  506. ++cnt;
  507. }
  508. goto nextfmt;
  509. }
  510. }
  511. #else
  512. assert(0);
  513. #endif
  514. goto done;
  515. }
  516. /* Unrecognized specifier! */
  517. goto done;
  518. } if (isspace(*fmt)) { /* Consume all whitespace. */
  519. while (isspace(scan_getc_nw(&sc)))
  520. {}
  521. } else { /* Match the current fmt char. */
  522. matchchar:
  523. if (scan_getc_nw(&sc) != *fmt) {
  524. goto done;
  525. }
  526. scan_getc_nw(&sc);
  527. }
  528. nextfmt:
  529. scan_ungetc(&sc);
  530. ++fmt;
  531. }
  532. done: /* end of scan */
  533. kill_scan_cookie(&sc);
  534. if ((sc.ungot_char <= 0) && (cnt == 0) && (*fmt)) {
  535. return (EOF);
  536. }
  537. return (cnt);
  538. }
  539. /*****************************************************************************/
  540. #ifdef __UCLIBC_HAS_FLOATS__
  541. #include <float.h>
  542. #define MAX_SIG_DIGITS 20
  543. #define MAX_IGNORED_DIGITS 2000
  544. #define MAX_ALLOWED_EXP (MAX_SIG_DIGITS + MAX_IGNORED_DIGITS + LDBL_MAX_10_EXP)
  545. #if LDBL_DIG > MAX_SIG_DIGITS
  546. #error need to adjust MAX_SIG_DIGITS
  547. #endif
  548. #include <limits.h>
  549. #if MAX_ALLOWED_EXP > INT_MAX
  550. #error size assumption violated for MAX_ALLOWED_EXP
  551. #endif
  552. int __strtold(long double *ld, struct scan_cookie *sc)
  553. {
  554. long double number;
  555. long double p10;
  556. int exponent_power;
  557. int exponent_temp;
  558. int negative;
  559. int num_digits;
  560. int since_decimal;
  561. int c;
  562. c = scan_getc(sc); /* Decrements width. */
  563. negative = 0;
  564. switch(c) { /* Handle optional sign. */
  565. case '-': negative = 1; /* Fall through to get next char. */
  566. case '+': c = scan_getc(sc);
  567. }
  568. number = 0.;
  569. num_digits = -1;
  570. exponent_power = 0;
  571. since_decimal = INT_MIN;
  572. LOOP:
  573. while (isdigit(c)) { /* Process string of digits. */
  574. ++since_decimal;
  575. if (num_digits < 0) { /* First time through? */
  576. ++num_digits; /* We've now seen a digit. */
  577. }
  578. if (num_digits || (c != '0')) { /* had/have nonzero */
  579. ++num_digits;
  580. if (num_digits <= MAX_SIG_DIGITS) { /* Is digit significant? */
  581. number = number * 10. + (c - '0');
  582. }
  583. }
  584. c = scan_getc(sc);
  585. }
  586. if ((c == '.') && (since_decimal < 0)) { /* If no previous decimal pt, */
  587. since_decimal = 0; /* save position of decimal point */
  588. c = scan_getc(sc); /* and process rest of digits */
  589. goto LOOP;
  590. }
  591. if (num_digits<0) { /* Must have at least one digit. */
  592. goto FAIL;
  593. }
  594. if (num_digits > MAX_SIG_DIGITS) { /* Adjust exp for skipped digits. */
  595. exponent_power += num_digits - MAX_SIG_DIGITS;
  596. }
  597. if (since_decimal >= 0) { /* Adjust exponent for decimal point. */
  598. exponent_power -= since_decimal;
  599. }
  600. if (negative) { /* Correct for sign. */
  601. number = -number;
  602. negative = 0; /* Reset for exponent processing below. */
  603. }
  604. /* Process an exponent string. */
  605. if (c == 'e' || c == 'E') {
  606. c = scan_getc(sc);
  607. switch(c) { /* Handle optional sign. */
  608. case '-': negative = 1; /* Fall through to get next char. */
  609. case '+': c = scan_getc(sc);
  610. }
  611. num_digits = 0;
  612. exponent_temp = 0;
  613. while (isdigit(c)) { /* Process string of digits. */
  614. if (exponent_temp < MAX_ALLOWED_EXP) { /* overflow check */
  615. exponent_temp = exponent_temp * 10 + (c - '0');
  616. }
  617. c = scan_getc(sc);
  618. ++num_digits;
  619. }
  620. if (num_digits == 0) { /* Were there no exp digits? */
  621. goto FAIL;
  622. } /* else */
  623. if (negative) {
  624. exponent_power -= exponent_temp;
  625. } else {
  626. exponent_power += exponent_temp;
  627. }
  628. }
  629. if (number != 0.) {
  630. /* Now scale the result. */
  631. exponent_temp = exponent_power;
  632. p10 = 10.;
  633. if (exponent_temp < 0) {
  634. exponent_temp = -exponent_temp;
  635. }
  636. while (exponent_temp) {
  637. if (exponent_temp & 1) {
  638. if (exponent_power < 0) {
  639. number /= p10;
  640. } else {
  641. number *= p10;
  642. }
  643. }
  644. exponent_temp >>= 1;
  645. p10 *= p10;
  646. }
  647. }
  648. *ld = number;
  649. return 1;
  650. FAIL:
  651. scan_ungetc(sc);
  652. return 0;
  653. }
  654. #endif /* __UCLIBC_HAS_FLOATS__ */
  655. #endif