vfscanf.c (af1c9c0e4d69d542e6f079782cd3756588c15315) | vfscanf.c (6180233fd804806e7301790d2330da50ca57e71f) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Torek. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 369 unchanged lines hidden (view full) --- 378 break; 379 } 380 } 381 nread += sum; 382 } else if (flags & LONG) { 383 wcp = va_arg(ap, wchar_t *); 384 n = 0; 385 while (width != 0) { | 1/*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Torek. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 369 unchanged lines hidden (view full) --- 378 break; 379 } 380 } 381 nread += sum; 382 } else if (flags & LONG) { 383 wcp = va_arg(ap, wchar_t *); 384 n = 0; 385 while (width != 0) { |
386 if (n == MB_CUR_MAX) | 386 if (n == MB_CUR_MAX) { 387 fp->_flags |= __SERR; |
387 goto input_failure; | 388 goto input_failure; |
389 } |
|
388 buf[n++] = *fp->_p; 389 fp->_p++; 390 fp->_r--; 391 memset(&mbs, 0, sizeof(mbs)); 392 nconv = mbrtowc(wcp, buf, n, &mbs); | 390 buf[n++] = *fp->_p; 391 fp->_p++; 392 fp->_r--; 393 memset(&mbs, 0, sizeof(mbs)); 394 nconv = mbrtowc(wcp, buf, n, &mbs); |
393 if (nconv == 0 || nconv == (size_t)-1) | 395 if (nconv == (size_t)-1) { 396 fp->_flags |= __SERR; |
394 goto input_failure; | 397 goto input_failure; |
398 } 399 if (nconv == 0) 400 *wcp = L'\0'; |
|
395 if (nconv != (size_t)-2) { 396 nread += n; 397 width--; 398 wcp++; 399 n = 0; 400 } 401 if (fp->_r <= 0 && __srefill(fp)) { | 401 if (nconv != (size_t)-2) { 402 nread += n; 403 width--; 404 wcp++; 405 n = 0; 406 } 407 if (fp->_r <= 0 && __srefill(fp)) { |
402 if (n != 0) | 408 if (n != 0) { 409 fp->_flags |= __SERR; |
403 goto input_failure; | 410 goto input_failure; |
411 } |
|
404 break; 405 } 406 } 407 nassigned++; 408 } else { 409 size_t r = fread((void *)va_arg(ap, char *), 1, 410 width, fp); 411 --- 23 unchanged lines hidden (view full) --- 435 } 436 } 437 if (n == 0) 438 goto match_failure; 439 } else if (flags & LONG) { 440 wcp = wcp0 = va_arg(ap, wchar_t *); 441 n = 0; 442 while (width != 0) { | 412 break; 413 } 414 } 415 nassigned++; 416 } else { 417 size_t r = fread((void *)va_arg(ap, char *), 1, 418 width, fp); 419 --- 23 unchanged lines hidden (view full) --- 443 } 444 } 445 if (n == 0) 446 goto match_failure; 447 } else if (flags & LONG) { 448 wcp = wcp0 = va_arg(ap, wchar_t *); 449 n = 0; 450 while (width != 0) { |
443 if (n == MB_CUR_MAX) | 451 if (n == MB_CUR_MAX) { 452 fp->_flags |= __SERR; |
444 goto input_failure; | 453 goto input_failure; |
454 } |
|
445 buf[n++] = *fp->_p; 446 fp->_p++; 447 fp->_r--; 448 memset(&mbs, 0, sizeof(mbs)); 449 nconv = mbrtowc(wcp, buf, n, &mbs); | 455 buf[n++] = *fp->_p; 456 fp->_p++; 457 fp->_r--; 458 memset(&mbs, 0, sizeof(mbs)); 459 nconv = mbrtowc(wcp, buf, n, &mbs); |
450 if (nconv == 0 || nconv == (size_t)-1) | 460 if (nconv == (size_t)-1) { 461 fp->_flags |= __SERR; |
451 goto input_failure; | 462 goto input_failure; |
463 } 464 if (nconv == 0) 465 *wcp = L'\0'; |
|
452 if (nconv != (size_t)-2) { 453 if (wctob(*wcp) != EOF && 454 !ccltab[wctob(*wcp)]) { 455 while (--n > 0) 456 __ungetc(buf[n], 457 fp); 458 break; 459 } 460 nread += n; 461 width--; 462 wcp++; 463 n = 0; 464 } 465 if (fp->_r <= 0 && __srefill(fp)) { | 466 if (nconv != (size_t)-2) { 467 if (wctob(*wcp) != EOF && 468 !ccltab[wctob(*wcp)]) { 469 while (--n > 0) 470 __ungetc(buf[n], 471 fp); 472 break; 473 } 474 nread += n; 475 width--; 476 wcp++; 477 n = 0; 478 } 479 if (fp->_r <= 0 && __srefill(fp)) { |
466 if (n != 0) | 480 if (n != 0) { 481 fp->_flags |= __SERR; |
467 goto input_failure; | 482 goto input_failure; |
483 } |
|
468 break; 469 } 470 } | 484 break; 485 } 486 } |
471 if (n != 0) | 487 if (n != 0) { 488 fp->_flags |= __SERR; |
472 goto input_failure; | 489 goto input_failure; |
490 } |
|
473 n = wcp - wcp0; 474 if (n == 0) 475 goto match_failure; 476 *wcp = L'\0'; 477 nassigned++; 478 } else { 479 p0 = p = va_arg(ap, char *); 480 while (ccltab[*fp->_p]) { --- 30 unchanged lines hidden (view full) --- 511 if (fp->_r <= 0 && __srefill(fp)) 512 break; 513 } 514 nread += n; 515 } else if (flags & LONG) { 516 wcp = va_arg(ap, wchar_t *); 517 n = 0; 518 while (!isspace(*fp->_p) && width != 0) { | 491 n = wcp - wcp0; 492 if (n == 0) 493 goto match_failure; 494 *wcp = L'\0'; 495 nassigned++; 496 } else { 497 p0 = p = va_arg(ap, char *); 498 while (ccltab[*fp->_p]) { --- 30 unchanged lines hidden (view full) --- 529 if (fp->_r <= 0 && __srefill(fp)) 530 break; 531 } 532 nread += n; 533 } else if (flags & LONG) { 534 wcp = va_arg(ap, wchar_t *); 535 n = 0; 536 while (!isspace(*fp->_p) && width != 0) { |
519 if (n == MB_CUR_MAX) | 537 if (n == MB_CUR_MAX) { 538 fp->_flags |= __SERR; |
520 goto input_failure; | 539 goto input_failure; |
540 } |
|
521 buf[n++] = *fp->_p; 522 fp->_p++; 523 fp->_r--; 524 memset(&mbs, 0, sizeof(mbs)); 525 nconv = mbrtowc(wcp, buf, n, &mbs); | 541 buf[n++] = *fp->_p; 542 fp->_p++; 543 fp->_r--; 544 memset(&mbs, 0, sizeof(mbs)); 545 nconv = mbrtowc(wcp, buf, n, &mbs); |
526 if (nconv == 0 || nconv == (size_t)-1) | 546 if (nconv == (size_t)-1) { 547 fp->_flags |= __SERR; |
527 goto input_failure; | 548 goto input_failure; |
549 } 550 if (nconv == 0) 551 *wcp = L'\0'; |
|
528 if (nconv != (size_t)-2) { 529 if (iswspace(*wcp)) { 530 while (--n > 0) 531 __ungetc(buf[n], 532 fp); 533 break; 534 } 535 nread += n; 536 width--; 537 wcp++; 538 n = 0; 539 } 540 if (fp->_r <= 0 && __srefill(fp)) { | 552 if (nconv != (size_t)-2) { 553 if (iswspace(*wcp)) { 554 while (--n > 0) 555 __ungetc(buf[n], 556 fp); 557 break; 558 } 559 nread += n; 560 width--; 561 wcp++; 562 n = 0; 563 } 564 if (fp->_r <= 0 && __srefill(fp)) { |
541 if (n != 0) | 565 if (n != 0) { 566 fp->_flags |= __SERR; |
542 goto input_failure; | 567 goto input_failure; |
568 } |
|
543 break; 544 } 545 } 546 *wcp = L'\0'; 547 nassigned++; 548 } else { 549 p0 = p = va_arg(ap, char *); 550 while (!isspace(*fp->_p)) { --- 381 unchanged lines hidden --- | 569 break; 570 } 571 } 572 *wcp = L'\0'; 573 nassigned++; 574 } else { 575 p0 = p = va_arg(ap, char *); 576 while (!isspace(*fp->_p)) { --- 381 unchanged lines hidden --- |