scanf.c 16 KB

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