- Timestamp:
- Aug 27, 2006, 8:31:48 PM (19 years ago)
- Location:
- branches/libc-0.6/src/emx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/libc-0.6/src/emx/ChangeLog.LIBC
r2786 r2792 5 5 2006-08-27: knut st. osmundsen <bird-gccos2-spam@anduin.net> 6 6 - libc: 7 o Implemented the new length modifiers for *scanf. Adjusted the length 8 modifier implementation for *printf. Fixes #76. 7 9 o Fixed problems with fork() and module loading/unloading. Fixes #76. 8 10 o Fixed atexit() and on_exit() problem with callbacks in unloaded DLLs. Fixes #103. -
branches/libc-0.6/src/emx/src/lib/io/_input.c
r2090 r2792 4 4 #include <stdio.h> 5 5 #include <stdlib.h> 6 #include <stdint.h> 6 7 #include <stdarg.h> 7 8 #include <string.h> … … 16 17 #define TRUE 1 17 18 19 #define SIZE_HH (('h' << 8) | 'h') 20 #define SIZE_LL (('l' << 8) | 'l') 21 22 18 23 /* This structure holds the local variables of _input() which are 19 24 passed to the functions called by _input(). */ … … 28 33 int collected; /* Number of characters collected */ 29 34 size_t more_size; /* Size of the above */ 30 char size; /* Size (0, 'h', 'l' or 'L') */35 int size; /* Size (0, 'h', SIZE_HH, 'l', SIZE_LL, 'L', 'j', 'z', 'Z', 't' or 'q') */ 31 36 char width_given; /* A field width has been given */ 32 37 unsigned char ungetc_count; /* stream's _ungetc_count prior to get0() */ … … 192 197 193 198 199 static void inp_wchar (ilocal *v, wchar_t *dst) 200 { 201 /** @todo implement sscanf(, "%lc", pwsz). */ 202 int c, ok; 203 // mbstate_t mbs; 204 205 if (v->status == END_OF_FILE) 206 { 207 v->status = INPUT_FAILURE; 208 return; 209 } 210 if (!v->width_given) 211 v->width = 1; 212 ok = FALSE; 213 // mbsinit(&mbs); 214 while ((c = get (v)) != EOF) 215 { 216 ok = TRUE; 217 if (dst != NULL) 218 *dst++ = (unsigned char)c; 219 } 220 if (!ok) 221 v->status = INPUT_FAILURE; 222 else if (dst != NULL) 223 ++v->count; 224 } 225 226 194 227 static void inp_str (ilocal *v, unsigned char *dst) 195 228 { … … 197 230 198 231 c = skip (v); 199 if (v->status != OK) return; 232 if (v->status != OK) 233 return; 200 234 while (c != EOF && !isspace (c)) 201 235 { … … 211 245 make_unread (v, c); 212 246 } 247 248 249 static void inp_wstr (ilocal *v, wchar_t *dst) 250 { 251 int c; 252 /** @todo implement sscanf(, "%ls", pwsz). */ 253 // mbstate_t mbs; 254 255 c = skip (v); 256 if (v->status != OK) 257 return; 258 259 // mbsinit(&mbs); 260 while (c != EOF && !isspace (c)) 261 { 262 if (dst != NULL) 263 *dst++ = (unsigned char)c; 264 c = get (v); 265 } 266 if (dst != NULL) 267 { 268 *dst = 0; 269 ++v->count; 270 } 271 make_unread (v, c); 272 } 273 213 274 214 275 … … 372 433 switch (v->size) 373 434 { 374 case 'L':375 *(long long *)dst = n;376 break;377 435 case 'h': 378 436 *(short *)dst = n; 437 break; 438 case SIZE_HH: 439 *(signed char *)dst = n; 440 break; 441 case 'l': 442 *(long *)dst = n; 443 break; 444 case SIZE_LL: 445 case 'L': /* GNU */ 446 case 'q': /* bsd */ 447 *(long long *)dst = n; 448 break; 449 case 'j': 450 *(intmax_t *)dst = n; 451 break; 452 case 'z': 453 case 'Z': 454 *(size_t *)dst = n; 455 break; 456 case 't': 457 *(ptrdiff_t *)dst = n; 379 458 break; 380 459 default: … … 659 738 v->width_given = TRUE; 660 739 } 661 if (*format == 'h' || *format == 'l' || *format == 'L') 662 v->size = *format++; 740 if ( *format == 'h' || *format == 'l' || *format == 'L' 741 || *format == 'j' || *format == 'z' || *format == 't' 742 || *format == 'q' || *format == 'Z' ) 743 { 744 v->size = *format++; 745 if (v->size == 'l' && *format == 'l') 746 { 747 v->size = SIZE_LL; ++format; 748 } 749 else if (v->size == 'h' && *format == 'h') 750 { 751 v->size = SIZE_HH; ++format; 752 } 753 } 663 754 f = *format; 664 755 switch (f) 665 756 { 666 case 'c':667 if (assign)668 dst = va_arg (arg_ptr, char *);669 inp_char (v, dst);670 break;671 672 757 case '[': 673 758 if (assign) … … 676 761 break; 677 762 763 case 'c': 764 if (v->size != 'l' && v->size != 'L') 765 { 766 if (assign) 767 dst = va_arg (arg_ptr, char *); 768 inp_char (v, dst); 769 break; 770 } 771 /* fall thru */ 772 case 'C': 773 if (assign) 774 dst = va_arg (arg_ptr, wchar_t *); 775 inp_wchar (v, dst); 776 break; 777 678 778 case 's': 679 if (assign) 680 dst = va_arg (arg_ptr, char *); 681 inp_str (v, dst); 682 break; 779 if (v->size != 'l' && v->size == 'L') 780 { 781 if (assign) 782 dst = va_arg (arg_ptr, char *); 783 inp_str (v, dst); 784 break; 785 } 786 /* fall thru */ 787 case 'S': 788 if (assign) 789 dst = va_arg (arg_ptr, wchar_t *); 790 inp_wstr (v, dst); 791 break; 683 792 684 793 case 'f': … … 713 822 switch (v->size) 714 823 { 715 case 'L':716 dst = va_arg (arg_ptr, long long*);824 case SIZE_HH: 825 dst = va_arg (arg_ptr, char *); 717 826 break; 718 827 case 'h': 719 828 dst = va_arg (arg_ptr, short *); 829 break; 830 case 'l': 831 dst = va_arg (arg_ptr, long *); 832 break; 833 case SIZE_LL: 834 case 'L': 835 case 'q': 836 dst = va_arg (arg_ptr, long long *); 837 break; 838 case 'j': 839 dst = va_arg (arg_ptr, uintmax_t *); 840 break; 841 case 'z': 842 case 'Z': 843 dst = va_arg (arg_ptr, size_t *); 844 break; 845 case 't': 846 dst = va_arg (arg_ptr, ptrdiff_t *); 720 847 break; 721 848 default: … … 730 857 switch (v->size) 731 858 { 732 case 'L':733 *(va_arg (arg_ptr, long long*)) = v->chars;859 case SIZE_HH: 860 *(va_arg (arg_ptr, signed char *)) = v->chars; 734 861 break; 735 862 case 'h': 736 863 *(va_arg (arg_ptr, short *)) = v->chars; 864 break; 865 case 'l': 866 *(va_arg (arg_ptr, long *)) = v->chars; 867 break; 868 case SIZE_LL: 869 case 'L': 870 case 'q': 871 *(va_arg (arg_ptr, long long *)) = v->chars; 872 break; 873 case 'z': 874 case 'Z': 875 *(va_arg (arg_ptr, size_t *)) = v->chars; 876 break; 877 case 't': 878 *(va_arg (arg_ptr, ptrdiff_t *)) = v->chars; 737 879 break; 738 880 default: -
branches/libc-0.6/src/emx/src/lib/io/_output.c
r2160 r2792 5 5 #include <stdlib.h> 6 6 #include <stdarg.h> 7 #include <stdint.h> 7 8 #include <string.h> 8 9 #include <math.h> … … 21 22 #define SIZE_HH (('h' << 8) | 'h') 22 23 #define SIZE_LL (('l' << 8) | 'l') 24 25 /* ASSUMES that there are no odd integer sizes (like char being 7 bit or similar weirdnesses). */ 26 27 #define IS_SIZE_64BIT(size) ( (sizeof(long long) == sizeof(uint64_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \ 28 || (sizeof(size_t) == sizeof(uint64_t) && ((size) == 'z' || (size) == 'z')) \ 29 || (sizeof(uintmax_t) == sizeof(uint64_t) && (size) == 'j') \ 30 || (sizeof(ptrdiff_t) == sizeof(uint64_t) && (size) == 't') \ 31 || (sizeof(int) == sizeof(uint64_t) && (size) == 0) \ 32 || (sizeof(short) == sizeof(uint64_t) && (size) == 'h') \ 33 || (sizeof(char) == sizeof(uint64_t) && (size) == SIZE_HH) \ 34 ) 35 36 #define IS_SIZE_32BIT(size) ( (sizeof(long long) == sizeof(uint32_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \ 37 || (sizeof(size_t) == sizeof(uint32_t) && ((size) == 'z' || (size) == 'z')) \ 38 || (sizeof(uintmax_t) == sizeof(uint32_t) && (size) == 'j') \ 39 || (sizeof(ptrdiff_t) == sizeof(uint32_t) && (size) == 't') \ 40 || (sizeof(int) == sizeof(uint32_t) && (size) == 0) \ 41 || (sizeof(short) == sizeof(uint32_t) && (size) == 'h') \ 42 || (sizeof(char) == sizeof(uint32_t) && (size) == SIZE_HH) \ 43 ) 44 45 #define IS_SIZE_LE_32BIT(size) ( (sizeof(long long) <= sizeof(uint32_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \ 46 || (sizeof(size_t) <= sizeof(uint32_t) && ((size) == 'z' || (size) == 'z')) \ 47 || (sizeof(uintmax_t) <= sizeof(uint32_t) && (size) == 'j') \ 48 || (sizeof(ptrdiff_t) <= sizeof(uint32_t) && (size) == 't') \ 49 || (sizeof(int) <= sizeof(uint32_t) && (size) == 0) \ 50 || (sizeof(short) <= sizeof(uint32_t) && (size) == 'h') \ 51 || (sizeof(char) <= sizeof(uint32_t) && (size) == SIZE_HH) \ 52 ) 53 54 #define IS_SIZE_16BIT(size) ( (sizeof(long long) == sizeof(uint16_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \ 55 || (sizeof(size_t) == sizeof(uint16_t) && ((size) == 'z' || (size) == 'z')) \ 56 || (sizeof(uintmax_t) == sizeof(uint16_t) && (size) == 'j') \ 57 || (sizeof(ptrdiff_t) == sizeof(uint16_t) && (size) == 't') \ 58 || (sizeof(int) == sizeof(uint16_t) && (size) == 0) \ 59 || (sizeof(short) == sizeof(uint16_t) && (size) == 'h') \ 60 || (sizeof(char) == sizeof(uint16_t) && (size) == SIZE_HH) \ 61 ) 62 63 #define IS_SIZE_8BIT(size) ( (sizeof(long long) == sizeof(uint8_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \ 64 || (sizeof(size_t) == sizeof(uint8_t) && ((size) == 'z' || (size) == 'z')) \ 65 || (sizeof(uintmax_t) == sizeof(uint8_t) && (size) == 'j') \ 66 || (sizeof(ptrdiff_t) == sizeof(uint8_t) && (size) == 't') \ 67 || (sizeof(int) == sizeof(uint8_t) && (size) == 0) \ 68 || (sizeof(short) == sizeof(uint8_t) && (size) == 'h') \ 69 || (sizeof(char) == sizeof(uint8_t) && (size) == SIZE_HH) \ 70 ) 71 23 72 24 73 #define DEFAULT_PREC 6 … … 369 418 370 419 371 static int cvt_hex_32 (olocal *v, u nsignedn, char x)420 static int cvt_hex_32 (olocal *v, uint32_t n, char x) 372 421 { 373 422 char buf[9]; … … 378 427 379 428 380 static int cvt_hex_64 (olocal *v, u nsigned long longn, char x)429 static int cvt_hex_64 (olocal *v, uint64_t n, char x) 381 430 { 382 431 char buf[17]; … … 401 450 402 451 403 static int cvt_oct_32 (olocal *v, u nsignedn)452 static int cvt_oct_32 (olocal *v, uint32_t n) 404 453 { 405 454 char buf[12]; … … 410 459 411 460 412 static int cvt_oct_64 (olocal *v, u nsigned long longn)461 static int cvt_oct_64 (olocal *v, uint64_t n) 413 462 { 414 463 char buf[23]; … … 419 468 420 469 421 static int cvt_dec_32 (olocal *v, u nsignedn, int is_signed, int is_neg)470 static int cvt_dec_32 (olocal *v, uint32_t n, int is_signed, int is_neg) 422 471 { 423 472 char buf[11]; … … 428 477 429 478 430 static int cvt_dec_64 (olocal *v, unsigned long long n, int is_signed, 431 int is_neg) 479 static int cvt_dec_64 (olocal *v, uint64_t n, int is_signed, int is_neg) 432 480 { 433 481 char buf[21]; … … 905 953 size = SIZE_HH; ++format; 906 954 } 907 else if (size == 'q' || size == 'j')908 size = SIZE_LL;909 else if (size == 'z' || size == 'Z' || size == 't')910 size = 'l';911 955 } 912 956 … … 919 963 920 964 case 'n': 921 if ( size == SIZE_LL || size == 'L')922 { 923 long long *ptr = va_arg (arg_ptr, long long*);965 if (IS_SIZE_64BIT(size)) 966 { 967 int64_t *ptr = va_arg (arg_ptr, int64_t *); 924 968 *ptr = v.count; 925 969 } 926 else if ( size == 'h')927 { 928 short *ptr = va_arg (arg_ptr, short *);970 else if (IS_SIZE_16BIT(size)) 971 { 972 int16_t *ptr = va_arg (arg_ptr, int16_t *); 929 973 *ptr = v.count; 930 974 } 931 else if ( size == SIZE_HH)932 { 933 char *ptr = va_arg (arg_ptr, char*);975 else if (IS_SIZE_8BIT(size)) 976 { 977 int8_t *ptr = va_arg (arg_ptr, int8_t *); 934 978 *ptr = v.count; 935 979 } 936 else 937 { 938 int *ptr = va_arg (arg_ptr, int *);980 else /* 32-bit */ 981 { 982 int32_t *ptr = va_arg (arg_ptr, int32_t *); 939 983 *ptr = v.count; 940 984 } … … 975 1019 case 'd': 976 1020 case 'i': 977 if ( size == SIZE_LL || size == 'L')978 { 979 long long n = va_arg (arg_ptr, long long);1021 if (IS_SIZE_64BIT(size)) 1022 { 1023 int64_t n = va_arg (arg_ptr, int64_t); 980 1024 if (n < 0) 981 1025 CHECK (cvt_dec_64 (&v, -n, TRUE, TRUE)); … … 985 1029 else 986 1030 { 987 int n = va_arg (arg_ptr, int);1031 int32_t n = va_arg (arg_ptr, int32_t); 988 1032 if (size == 'h') 989 1033 n = (short)n; … … 998 1042 999 1043 case 'u': 1000 if (size == SIZE_LL || size == 'L') 1001 CHECK (cvt_dec_64 (&v, va_arg (arg_ptr, unsigned long long), 1002 FALSE, FALSE)); 1044 if (IS_SIZE_64BIT (size)) 1045 CHECK (cvt_dec_64 (&v, va_arg (arg_ptr, uint64_t), FALSE, FALSE)); 1003 1046 else 1004 1047 { 1005 u nsigned n = va_arg (arg_ptr, unsigned);1048 uint32_t n = va_arg (arg_ptr, uint32_t); 1006 1049 if (size == 'h') 1007 1050 n = (unsigned short)n; … … 1014 1057 case 'p': 1015 1058 v.hash = TRUE; 1016 CHECK (cvt_hex_32 (&v, va_arg (arg_ptr, unsigned), 'x')); 1059 if (sizeof(uintptr_t) == sizeof(uint64_t)) 1060 CHECK (cvt_hex_64 (&v, va_arg (arg_ptr, uintptr_t), 'x')); 1061 else 1062 CHECK (cvt_hex_32 (&v, va_arg (arg_ptr, uintptr_t), 'x')); 1017 1063 break; 1018 1064 1019 1065 case 'x': 1020 1066 case 'X': 1021 if ( size == SIZE_LL || size == 'L')1022 CHECK (cvt_hex_64 (&v, va_arg (arg_ptr, u nsigned long long),1067 if (IS_SIZE_64BIT (size)) 1068 CHECK (cvt_hex_64 (&v, va_arg (arg_ptr, uint64_t), 1023 1069 *format)); 1024 1070 else 1025 1071 { 1026 u nsigned n = va_arg (arg_ptr, unsigned);1072 uint32_t n = va_arg (arg_ptr, uint32_t); 1027 1073 if (size == 'h') 1028 1074 n = (unsigned short)n; … … 1034 1080 1035 1081 case 'o': 1036 if ( size == SIZE_LL || size == 'L')1037 CHECK (cvt_oct_64 (&v, va_arg (arg_ptr, u nsigned long long)));1082 if (IS_SIZE_64BIT (size)) 1083 CHECK (cvt_oct_64 (&v, va_arg (arg_ptr, uint64_t))); 1038 1084 else 1039 1085 { 1040 u nsigned n = va_arg (arg_ptr, unsigned);1086 uint32_t n = va_arg (arg_ptr, uint32_t); 1041 1087 if (size == 'h') 1042 1088 n = (unsigned short)n;
Note:
See TracChangeset
for help on using the changeset viewer.