Changeset 2b3dd78 in mainline for uspace/lib/posix/src/stdio/scanf.c
- Timestamp:
- 2018-01-31T12:02:00Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5595841
- Parents:
- a0a9cc2 (diff), 14d789c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/src/stdio/scanf.c
ra0a9cc2 r2b3dd78 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include <assert.h> 39 36 … … 119 116 /* Initialize internal structures. */ 120 117 self->consumed = 0; 121 ssize_t fetched = posix_getline(118 ssize_t fetched = getline( 122 119 &self->window, &self->window_size, self->source.stream); 123 120 if (fetched != -1) { … … 140 137 /* Initialize internal structures. */ 141 138 self->consumed = 0; 142 self->fetched = posix_strlen(self->source.string);139 self->fetched = strlen(self->source.string); 143 140 self->window = (char *) self->source.string; 144 141 self->window_size = self->fetched + 1; … … 158 155 /* Do we need to fetch a new line from the source? */ 159 156 if (*self->cursor == '\0') { 160 ssize_t fetched = posix_getline(&self->window,157 ssize_t fetched = getline(&self->window, 161 158 &self->window_size, self->source.stream); 162 159 if (fetched != -1) { … … 208 205 * containing newline, while at the same time newline is the character 209 206 * that breaks the matching process. */ 210 int rc = posix_fseek( 211 self->source.stream, -1, SEEK_CUR); 207 int rc = fseek(self->source.stream, -1, SEEK_CUR); 212 208 if (rc == -1) { 213 209 /* Seek failed. */ 214 210 return 0; 215 211 } 216 ssize_t fetched = posix_getline(&self->window,212 ssize_t fetched = getline(&self->window, 217 213 &self->window_size, self->source.stream); 218 214 if (fetched != -1) { … … 266 262 if (*self->cursor == '\0') { 267 263 /* Window was completely consumed, fetch new data. */ 268 ssize_t fetched = posix_getline(&self->window,264 ssize_t fetched = getline(&self->window, 269 265 &self->window_size, self->source.stream); 270 266 if (fetched != -1) { … … 298 294 /* Try to correct the difference between the stream position and what was 299 295 * actually consumed. If it is not possible, continue anyway. */ 300 posix_fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR);296 fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR); 301 297 302 298 /* Destruct internal structures. */ … … 563 559 } 564 560 char *fmt_new = NULL; 565 width = posix_strtol(fmt, &fmt_new, 10);561 width = strtol(fmt, &fmt_new, 10); 566 562 if (width != 0) { 567 563 fmt = fmt_new; … … 625 621 626 622 const char *cur_borrowed = NULL; 623 char *cur_duplicated = NULL; 627 624 const char *cur_limited = NULL; 628 c har *cur_updated = NULL;625 const char *cur_updated = NULL; 629 626 630 627 /* Borrow the cursor. Until it is returned to the provider … … 637 634 * than allowed by width. */ 638 635 if (width != -1) { 639 cur_limited = posix_strndup(cur_borrowed, width); 636 cur_duplicated = strndup(cur_borrowed, width); 637 cur_limited = cur_duplicated; 640 638 } else { 641 639 cur_limited = cur_borrowed; 642 640 } 643 cur_updated = (char *)cur_limited;641 cur_updated = cur_limited; 644 642 645 643 long long sres = 0; … … 648 646 /* Try to convert the integer. */ 649 647 if (int_conv_unsigned) { 650 ures = posix_strtoull(cur_limited,&cur_updated, int_conv_base);648 ures = strtoull(cur_limited, (char **) &cur_updated, int_conv_base); 651 649 } else { 652 sres = posix_strtoll(cur_limited,&cur_updated, int_conv_base);650 sres = strtoll(cur_limited, (char **) &cur_updated, int_conv_base); 653 651 } 654 652 655 653 /* Update the cursor so it can be returned to the provider. */ 656 654 cur_borrowed += cur_updated - cur_limited; 657 if ( width != -1 && cur_limited != NULL) {655 if (cur_duplicated != NULL) { 658 656 /* Deallocate duplicated part of the cursor view. */ 659 free(cur_ limited);657 free(cur_duplicated); 660 658 } 661 659 cur_limited = NULL; 662 660 cur_updated = NULL; 661 cur_duplicated = NULL; 663 662 /* Return the cursor to the provider. Input consistency is again 664 663 * the job of the provider, so we can report errors from … … 797 796 const char *cur_borrowed = NULL; 798 797 const char *cur_limited = NULL; 799 char *cur_updated = NULL; 798 char *cur_duplicated = NULL; 799 const char *cur_updated = NULL; 800 800 801 801 /* Borrow the cursor. Until it is returned to the provider … … 808 808 * than allowed by width. */ 809 809 if (width != -1) { 810 cur_limited = posix_strndup(cur_borrowed, width); 810 cur_duplicated = strndup(cur_borrowed, width); 811 cur_limited = cur_duplicated; 811 812 } else { 812 813 cur_limited = cur_borrowed; 813 814 } 814 cur_updated = (char *)cur_limited;815 cur_updated = cur_limited; 815 816 816 817 float fres = 0.0; … … 821 822 switch (length_mod) { 822 823 case LMOD_NONE: 823 fres = posix_strtof(cur_limited,&cur_updated);824 fres = strtof(cur_limited, (char **) &cur_updated); 824 825 break; 825 826 case LMOD_l: 826 dres = posix_strtod(cur_limited,&cur_updated);827 dres = strtod(cur_limited, (char **) &cur_updated); 827 828 break; 828 829 case LMOD_L: 829 ldres = posix_strtold(cur_limited,&cur_updated);830 ldres = strtold(cur_limited, (char **) &cur_updated); 830 831 break; 831 832 default: … … 835 836 /* Update the cursor so it can be returned to the provider. */ 836 837 cur_borrowed += cur_updated - cur_limited; 837 if ( width != -1 && cur_limited != NULL) {838 if (cur_duplicated != NULL) { 838 839 /* Deallocate duplicated part of the cursor view. */ 839 free(cur_ limited);840 free(cur_duplicated); 840 841 } 841 842 cur_limited = NULL; … … 1189 1190 * @return The number of converted output items or EOF on failure. 1190 1191 */ 1191 int posix_vfscanf(1192 int vfscanf( 1192 1193 FILE *restrict stream, const char *restrict format, va_list arg) 1193 1194 { … … 1209 1210 * @return The number of converted output items or EOF on failure. 1210 1211 */ 1211 int posix_vsscanf(1212 int vsscanf( 1212 1213 const char *restrict s, const char *restrict format, va_list arg) 1213 1214 {
Note:
See TracChangeset
for help on using the changeset viewer.