scanf.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. }
  163. static int scan_getc_nw(struct scan_cookie *sc)
  164. {
  165. if (sc->ungot_flag == 0) {
  166. sc->ungot_char = getc(sc->fp);
  167. } else {
  168. sc->ungot_flag = 0;
  169. }
  170. if (sc->ungot_char > 0) {
  171. ++sc->nread;
  172. }
  173. sc->width_flag = 0;
  174. return sc->ungot_char;
  175. }
  176. static int scan_getc(struct scan_cookie *sc)
  177. {
  178. if (sc->ungot_flag == 0) {
  179. sc->ungot_char = getc(sc->fp);
  180. }
  181. sc->width_flag = 1;
  182. if (--sc->width < 0) {
  183. sc->ungot_flag = 1;
  184. return 0;
  185. }
  186. sc->ungot_flag = 0;
  187. if (sc->ungot_char > 0) {
  188. ++sc->nread;
  189. }
  190. return sc->ungot_char;
  191. }
  192. static void scan_ungetc(struct scan_cookie *sc)
  193. {
  194. if (sc->ungot_flag != 0) {
  195. assert(sc->width < 0);
  196. return;
  197. }
  198. if (sc->width_flag) {
  199. ++sc->width;
  200. }
  201. sc->ungot_flag = 1;
  202. if (sc->ungot_char > 0) { /* not EOF or EOS */
  203. --sc->nread;
  204. }
  205. }
  206. static void kill_scan_cookie(struct scan_cookie *sc)
  207. {
  208. if (sc->ungot_flag) {
  209. ungetc(sc->ungot_char,sc->fp);
  210. }
  211. }
  212. int vfscanf(fp, format, ap)
  213. FILE *fp;
  214. const char *format;
  215. va_list ap;
  216. {
  217. #ifdef __UCLIBC_HAS_LONG_LONG__
  218. #define STRTO_L_(s,e,b,u) _strto_ll(s,e,b,u)
  219. #define MAX_DIGITS 64
  220. #define UV_TYPE unsigned long long
  221. #define V_TYPE long long
  222. #else
  223. #define STRTO_L_(s,e,b,u) _strto_l(s,e,b,u)
  224. #define MAX_DIGITS 32
  225. #define UV_TYPE unsigned long
  226. #define V_TYPE long
  227. #endif
  228. #ifdef __UCLIBC_HAS_FLOATS__
  229. long double ld;
  230. #endif
  231. UV_TYPE uv;
  232. struct scan_cookie sc;
  233. unsigned const char *fmt;
  234. const char *p;
  235. unsigned char *b;
  236. void *vp;
  237. int cc, i, cnt;
  238. signed char lval;
  239. unsigned char store, usflag, base, invert, r0, r1;
  240. unsigned char buf[MAX_DIGITS+2];
  241. unsigned char scanset[UCHAR_MAX + 1];
  242. init_scan_cookie(&sc,fp);
  243. fmt = (unsigned const char *) format;
  244. cnt = 0;
  245. while (*fmt) {
  246. store = 1;
  247. lval = 0;
  248. sc.width = INT_MAX;
  249. if (*fmt == '%') { /* Conversion specification. */
  250. ++fmt;
  251. if (*fmt == '*') { /* Suppress assignment. */
  252. store = 0;
  253. ++fmt;
  254. }
  255. for (i = 0 ; isdigit(*fmt) ; sc.width = i) {
  256. i = (i * 10) + (*fmt++ - '0'); /* Get specified width. */
  257. }
  258. for (i = 0 ; i < sizeof(qual) ; i++) { /* Optional qualifier. */
  259. if (qual[i] == *fmt) {
  260. ++fmt;
  261. lval += qsz[i];
  262. if ((i < 2) && (qual[i] == *fmt)) { /* Double h or l. */
  263. ++fmt;
  264. lval += qsz[i];
  265. }
  266. break;
  267. }
  268. }
  269. for (p = spec ; *p ; p++) { /* Process format specifier. */
  270. if (*fmt != *p) continue;
  271. if (p-spec < 1) { /* % - match a '%'*/
  272. goto matchchar;
  273. }
  274. if (p-spec < 2) { /* n - store number of chars read */
  275. *(va_arg(ap, int *)) = sc.nread;
  276. scan_getc_nw(&sc);
  277. goto nextfmt;
  278. }
  279. if (p-spec > 3) { /* skip white space if not c or [ */
  280. while (isspace(scan_getc_nw(&sc)))
  281. {}
  282. scan_ungetc(&sc);
  283. }
  284. if (p-spec < 5) { /* [,c,s - string conversions */
  285. invert = 0;
  286. if (*p == 'c') {
  287. invert = 1;
  288. if (sc.width == INT_MAX) {
  289. sc.width = 1;
  290. }
  291. }
  292. for (i=0 ; i<= UCHAR_MAX ; i++) {
  293. scanset[i] = ((*p == 's') ? (isspace(i) == 0) : 0);
  294. }
  295. if (*p == '[') { /* need to build a scanset */
  296. if (*++fmt == '^') {
  297. invert = 1;
  298. ++fmt;
  299. }
  300. if (*fmt == ']') {
  301. scanset[(int)']'] = 1;
  302. ++fmt;
  303. }
  304. r0 = 0;
  305. while (*fmt && *fmt !=']') { /* build scanset */
  306. if ((*fmt == '-') && r0 && (fmt[1] != ']')) {
  307. /* range */
  308. ++fmt;
  309. if (*fmt < r0) {
  310. r1 = r0;
  311. r0 = *fmt;
  312. } else {
  313. r1 = *fmt;
  314. }
  315. for (i=r0 ; i<= r1 ; i++) {
  316. scanset[i] = 1;
  317. }
  318. r0 = 0;
  319. } else {
  320. r0 = *fmt;
  321. scanset[r0] = 1;
  322. }
  323. ++fmt;
  324. }
  325. if (!*fmt) { /* format string exhausted! */
  326. goto done;
  327. }
  328. }
  329. /* ok -- back to common work */
  330. if (sc.width <= 0) {
  331. goto done;
  332. }
  333. if (store) {
  334. b = va_arg(ap, unsigned char *);
  335. } else {
  336. b = buf;
  337. }
  338. cc = scan_getc(&sc);
  339. if (cc <= 0) {
  340. scan_ungetc(&sc);
  341. goto done; /* return EOF if cnt == 0 */
  342. }
  343. i = 0;
  344. while ((cc>0) && (scanset[cc] != invert)) {
  345. i = 1; /* yes, we stored something */
  346. *b = cc;
  347. b += store;
  348. cc = scan_getc(&sc);
  349. }
  350. if (i==0) {
  351. scan_ungetc(&sc);
  352. goto done; /* return cnt */
  353. }
  354. if (*p != 'c') { /* nul-terminate the stored string */
  355. *b = 0;
  356. }
  357. cnt += store;
  358. goto nextfmt;
  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. if (base == 0) { /* Default to base 10 */
  393. base = 10;
  394. }
  395. /* At this point, we're ready to start reading digits. */
  396. if (cc == '0') {
  397. *b++ = cc; /* Store first leading 0 */
  398. do { /* but ignore others. */
  399. cc = scan_getc(&sc);
  400. } while (cc == '0');
  401. }
  402. while (valid_digit(cc,base)) { /* Now for nonzero digits.*/
  403. if (b - buf < MAX_DIGITS) {
  404. *b++ = cc;
  405. }
  406. cc = scan_getc(&sc);
  407. }
  408. *b = 0; /* null-terminate */
  409. if ((b == buf) || (*--b == '+') || (*b == '-')) {
  410. scan_ungetc(&sc);
  411. goto done; /* No digits! */
  412. }
  413. if (store) {
  414. if (*buf == '-') {
  415. usflag = 0;
  416. }
  417. uv = STRTO_L_(buf, NULL, base, usflag);
  418. vp = va_arg(ap, void *);
  419. switch (lval) {
  420. case 2: /* If no long long, treat as long . */
  421. #ifdef __UCLIBC_HAS_LONG_LONG__
  422. *((unsigned long long *)vp) = uv;
  423. break;
  424. #endif
  425. case 1:
  426. #if ULONG_MAX == UINT_MAX
  427. case 0: /* int and long int are the same */
  428. #endif
  429. #ifdef __UCLIBC_HAS_LONG_LONG__
  430. if (usflag) {
  431. if (uv > ULONG_MAX) {
  432. uv = ULONG_MAX;
  433. }
  434. } else if (((V_TYPE)uv) > LONG_MAX) {
  435. uv = LONG_MAX;
  436. } else if (((V_TYPE)uv) < LONG_MIN) {
  437. uv = (UV_TYPE) LONG_MIN;
  438. }
  439. #endif
  440. *((unsigned long *)vp) = (unsigned long)uv;
  441. break;
  442. #if ULONG_MAX != UINT_MAX
  443. case 0: /* int and long int are different */
  444. if (usflag) {
  445. if (uv > UINT_MAX) {
  446. uv = UINT_MAX;
  447. }
  448. } else if (((V_TYPE)uv) > INT_MAX) {
  449. uv = INT_MAX;
  450. } else if (((V_TYPE)uv) < INT_MIN) {
  451. uv = (UV_TYPE) INT_MIN;
  452. }
  453. *((unsigned int *)vp) = (unsigned int)uv;
  454. break;
  455. #endif
  456. case -1:
  457. if (usflag) {
  458. if (uv > USHRT_MAX) {
  459. uv = USHRT_MAX;
  460. }
  461. } else if (((V_TYPE)uv) > SHRT_MAX) {
  462. uv = SHRT_MAX;
  463. } else if (((V_TYPE)uv) < SHRT_MIN) {
  464. uv = (UV_TYPE) SHRT_MIN;
  465. }
  466. *((unsigned short *)vp) = (unsigned short)uv;
  467. break;
  468. case -2:
  469. if (usflag) {
  470. if (uv > UCHAR_MAX) {
  471. uv = UCHAR_MAX;
  472. }
  473. } else if (((V_TYPE)uv) > CHAR_MAX) {
  474. uv = CHAR_MAX;
  475. } else if (((V_TYPE)uv) < CHAR_MIN) {
  476. uv = (UV_TYPE) CHAR_MIN;
  477. }
  478. *((unsigned char *)vp) = (unsigned char) uv;
  479. break;
  480. default:
  481. assert(0);
  482. }
  483. ++cnt;
  484. }
  485. goto nextfmt;
  486. }
  487. #ifdef __UCLIBC_HAS_FLOATS__
  488. else { /* floating point */
  489. if (sc.width <= 0) {
  490. goto done;
  491. }
  492. if (__strtold(&ld, &sc)) { /* Success! */
  493. if (store) {
  494. vp = va_arg(ap, void *);
  495. switch (lval) {
  496. case 2:
  497. *((long double *)vp) = ld;
  498. break;
  499. case 1:
  500. *((double *)vp) = (double) ld;
  501. break;
  502. case 0:
  503. *((float *)vp) = (float) ld;
  504. break;
  505. default: /* Illegal qualifier! */
  506. assert(0);
  507. goto done;
  508. }
  509. ++cnt;
  510. }
  511. goto nextfmt;
  512. }
  513. }
  514. #else
  515. assert(0);
  516. #endif
  517. goto done;
  518. }
  519. /* Unrecognized specifier! */
  520. goto done;
  521. } if (isspace(*fmt)) { /* Consume all whitespace. */
  522. while (isspace(scan_getc_nw(&sc)))
  523. {}
  524. } else { /* Match the current fmt char. */
  525. matchchar:
  526. if (scan_getc_nw(&sc) != *fmt) {
  527. goto done;
  528. }
  529. scan_getc_nw(&sc);
  530. }
  531. nextfmt:
  532. scan_ungetc(&sc);
  533. ++fmt;
  534. }
  535. done: /* end of scan */
  536. kill_scan_cookie(&sc);
  537. if ((sc.ungot_char <= 0) && (cnt == 0) && (*fmt)) {
  538. return (EOF);
  539. }
  540. return (cnt);
  541. }
  542. /*****************************************************************************/
  543. #ifdef __UCLIBC_HAS_FLOATS__
  544. #include <float.h>
  545. #define MAX_SIG_DIGITS 20
  546. #define MAX_IGNORED_DIGITS 2000
  547. #define MAX_ALLOWED_EXP (MAX_SIG_DIGITS + MAX_IGNORED_DIGITS + LDBL_MAX_10_EXP)
  548. #if LDBL_DIG > MAX_SIG_DIGITS
  549. #error need to adjust MAX_SIG_DIGITS
  550. #endif
  551. #include <limits.h>
  552. #if MAX_ALLOWED_EXP > INT_MAX
  553. #error size assumption violated for MAX_ALLOWED_EXP
  554. #endif
  555. int __strtold(long double *ld, struct scan_cookie *sc)
  556. {
  557. long double number;
  558. long double p10;
  559. int exponent_power;
  560. int exponent_temp;
  561. int negative;
  562. int num_digits;
  563. int since_decimal;
  564. int c;
  565. c = scan_getc(sc); /* Decrements width. */
  566. negative = 0;
  567. switch(c) { /* Handle optional sign. */
  568. case '-': negative = 1; /* Fall through to get next char. */
  569. case '+': c = scan_getc(sc);
  570. }
  571. number = 0.;
  572. num_digits = -1;
  573. exponent_power = 0;
  574. since_decimal = INT_MIN;
  575. LOOP:
  576. while (isdigit(c)) { /* Process string of digits. */
  577. ++since_decimal;
  578. if (num_digits < 0) { /* First time through? */
  579. ++num_digits; /* We've now seen a digit. */
  580. }
  581. if (num_digits || (c != '0')) { /* had/have nonzero */
  582. ++num_digits;
  583. if (num_digits <= MAX_SIG_DIGITS) { /* Is digit significant? */
  584. number = number * 10. + (c - '0');
  585. }
  586. }
  587. c = scan_getc(sc);
  588. }
  589. if ((c == '.') && (since_decimal < 0)) { /* If no previous decimal pt, */
  590. since_decimal = 0; /* save position of decimal point */
  591. c = scan_getc(sc); /* and process rest of digits */
  592. goto LOOP;
  593. }
  594. if (num_digits<0) { /* Must have at least one digit. */
  595. goto FAIL;
  596. }
  597. if (num_digits > MAX_SIG_DIGITS) { /* Adjust exp for skipped digits. */
  598. exponent_power += num_digits - MAX_SIG_DIGITS;
  599. }
  600. if (since_decimal >= 0) { /* Adjust exponent for decimal point. */
  601. exponent_power -= since_decimal;
  602. }
  603. if (negative) { /* Correct for sign. */
  604. number = -number;
  605. negative = 0; /* Reset for exponent processing below. */
  606. }
  607. /* Process an exponent string. */
  608. if (c == 'e' || c == 'E') {
  609. c = scan_getc(sc);
  610. switch(c) { /* Handle optional sign. */
  611. case '-': negative = 1; /* Fall through to get next char. */
  612. case '+': c = scan_getc(sc);
  613. }
  614. num_digits = 0;
  615. exponent_temp = 0;
  616. while (isdigit(c)) { /* Process string of digits. */
  617. if (exponent_temp < MAX_ALLOWED_EXP) { /* overflow check */
  618. exponent_temp = exponent_temp * 10 + (c - '0');
  619. }
  620. c = scan_getc(sc);
  621. ++num_digits;
  622. }
  623. if (num_digits == 0) { /* Were there no exp digits? */
  624. goto FAIL;
  625. } /* else */
  626. if (negative) {
  627. exponent_power -= exponent_temp;
  628. } else {
  629. exponent_power += exponent_temp;
  630. }
  631. }
  632. if (number != 0.) {
  633. /* Now scale the result. */
  634. exponent_temp = exponent_power;
  635. p10 = 10.;
  636. if (exponent_temp < 0) {
  637. exponent_temp = -exponent_temp;
  638. }
  639. while (exponent_temp) {
  640. if (exponent_temp & 1) {
  641. if (exponent_power < 0) {
  642. number /= p10;
  643. } else {
  644. number *= p10;
  645. }
  646. }
  647. exponent_temp >>= 1;
  648. p10 *= p10;
  649. }
  650. }
  651. *ld = number;
  652. return 1;
  653. FAIL:
  654. scan_ungetc(sc);
  655. return 0;
  656. }
  657. #endif /* __UCLIBC_HAS_FLOATS__ */
  658. #endif