Changeset 7fadb65 in mainline
- Timestamp:
- 2011-08-23T17:44:33Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 375ab5e, 4cf5ed46
- Parents:
- 7ce7cfb
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/generic/src/printf_core.c
r7ce7cfb r7fadb65 70 70 */ 71 71 #define PRINT_NUMBER_BUFFER_SIZE (64 + 5) 72 73 /** Get signed or unsigned integer argument */ 74 #define PRINTF_GET_INT_ARGUMENT(type, ap, flags) \ 75 ({ \ 76 unsigned type res; \ 77 \ 78 if ((flags) & __PRINTF_FLAG_SIGNED) { \ 79 signed type arg = va_arg((ap), signed type); \ 80 \ 81 if (arg < 0) { \ 82 res = -arg; \ 83 (flags) |= __PRINTF_FLAG_NEGATIVE; \ 84 } else \ 85 res = arg; \ 86 } else \ 87 res = va_arg((ap), unsigned type); \ 88 \ 89 res; \ 90 }) 72 91 73 92 /** Enumeration of possible arguments types. … … 171 190 } 172 191 173 return (int) (counter + 1);192 return (int) (counter); 174 193 } 175 194 … … 698 717 size_t size; 699 718 uint64_t number; 719 700 720 switch (qualifier) { 701 721 case PrintfQualifierByte: 702 722 size = sizeof(unsigned char); 703 number = (uint64_t) va_arg(ap, unsigned int);723 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 704 724 break; 705 725 case PrintfQualifierShort: 706 726 size = sizeof(unsigned short); 707 number = (uint64_t) va_arg(ap, unsigned int);727 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 708 728 break; 709 729 case PrintfQualifierInt: 710 730 size = sizeof(unsigned int); 711 number = (uint64_t) va_arg(ap, unsigned int);731 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 712 732 break; 713 733 case PrintfQualifierLong: 714 734 size = sizeof(unsigned long); 715 number = (uint64_t) va_arg(ap, unsigned long);735 number = PRINTF_GET_INT_ARGUMENT(long, ap, flags); 716 736 break; 717 737 case PrintfQualifierLongLong: 718 738 size = sizeof(unsigned long long); 719 number = (uint64_t) va_arg(ap, unsigned long long);739 number = PRINTF_GET_INT_ARGUMENT(long long, ap, flags); 720 740 break; 721 741 case PrintfQualifierPointer: … … 732 752 counter = -counter; 733 753 goto out; 734 }735 736 if (flags & __PRINTF_FLAG_SIGNED) {737 if (number & (0x1 << (size * 8 - 1))) {738 flags |= __PRINTF_FLAG_NEGATIVE;739 740 if (size == sizeof(uint64_t)) {741 number = -((int64_t) number);742 } else {743 number = ~number;744 number &=745 ~(0xFFFFFFFFFFFFFFFFll <<746 (size * 8));747 number++;748 }749 }750 754 } 751 755 -
kernel/generic/src/printf/printf_core.c
r7ce7cfb r7fadb65 75 75 #define PRINT_NUMBER_BUFFER_SIZE (64 + 5) 76 76 77 /** Get signed or unsigned integer argument */ 78 #define PRINTF_GET_INT_ARGUMENT(type, ap, flags) \ 79 ({ \ 80 unsigned type res; \ 81 \ 82 if ((flags) & __PRINTF_FLAG_SIGNED) { \ 83 signed type arg = va_arg((ap), signed type); \ 84 \ 85 if (arg < 0) { \ 86 res = -arg; \ 87 (flags) |= __PRINTF_FLAG_NEGATIVE; \ 88 } else \ 89 res = arg; \ 90 } else \ 91 res = va_arg((ap), unsigned type); \ 92 \ 93 res; \ 94 }) 95 77 96 /** Enumeration of possible arguments types. 78 97 */ … … 207 226 } 208 227 209 return (int) (counter + 1);228 return (int) (counter); 210 229 } 211 230 … … 245 264 } 246 265 247 return (int) (counter + 1);266 return (int) (counter); 248 267 } 249 268 … … 832 851 size_t size; 833 852 uint64_t number; 853 834 854 switch (qualifier) { 835 855 case PrintfQualifierByte: 836 856 size = sizeof(unsigned char); 837 number = (uint64_t) va_arg(ap, unsigned int);857 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 838 858 break; 839 859 case PrintfQualifierShort: 840 860 size = sizeof(unsigned short); 841 number = (uint64_t) va_arg(ap, unsigned int);861 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 842 862 break; 843 863 case PrintfQualifierInt: 844 864 size = sizeof(unsigned int); 845 number = (uint64_t) va_arg(ap, unsigned int);865 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 846 866 break; 847 867 case PrintfQualifierLong: 848 868 size = sizeof(unsigned long); 849 number = (uint64_t) va_arg(ap, unsigned long);869 number = PRINTF_GET_INT_ARGUMENT(long, ap, flags); 850 870 break; 851 871 case PrintfQualifierLongLong: 852 872 size = sizeof(unsigned long long); 853 number = (uint64_t) va_arg(ap, unsigned long long);873 number = PRINTF_GET_INT_ARGUMENT(long long, ap, flags); 854 874 break; 855 875 case PrintfQualifierPointer: … … 866 886 counter = -counter; 867 887 goto out; 868 }869 870 if (flags & __PRINTF_FLAG_SIGNED) {871 if (number & (0x1 << (size * 8 - 1))) {872 flags |= __PRINTF_FLAG_NEGATIVE;873 874 if (size == sizeof(uint64_t)) {875 number = -((int64_t) number);876 } else {877 number = ~number;878 number &=879 ~(0xFFFFFFFFFFFFFFFFll <<880 (size * 8));881 number++;882 }883 }884 888 } 885 889 -
kernel/test/print/print2.c
r7ce7cfb r7fadb65 44 44 TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); 45 45 46 TPRINTF("Testing printf(\"%%lld %%3.2lld %%-3.2lld %%2.3lld %%-2.3lld\", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5):\n"); 47 TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); 48 TPRINTF("Real output: [%lld] [%3.2lld] [%-3.2lld] [%2.3lld] [%-2.3lld]\n\n", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5); 49 46 50 TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); 47 51 TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); -
uspace/app/tester/print/print2.c
r7ce7cfb r7fadb65 45 45 TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); 46 46 47 TPRINTF("Testing printf(\"%%lld %%3.2lld %%-3.2lld %%2.3lld %%-2.3lld\", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5):\n"); 48 TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); 49 TPRINTF("Real output: [%lld] [%3.2lld] [%-3.2lld] [%2.3lld] [%-2.3lld]\n\n", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5); 50 47 51 TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); 48 52 TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); -
uspace/lib/c/generic/io/printf_core.c
r7ce7cfb r7fadb65 73 73 */ 74 74 #define PRINT_NUMBER_BUFFER_SIZE (64 + 5) 75 76 /** Get signed or unsigned integer argument */ 77 #define PRINTF_GET_INT_ARGUMENT(type, ap, flags) \ 78 ({ \ 79 unsigned type res; \ 80 \ 81 if ((flags) & __PRINTF_FLAG_SIGNED) { \ 82 signed type arg = va_arg((ap), signed type); \ 83 \ 84 if (arg < 0) { \ 85 res = -arg; \ 86 (flags) |= __PRINTF_FLAG_NEGATIVE; \ 87 } else \ 88 res = arg; \ 89 } else \ 90 res = va_arg((ap), unsigned type); \ 91 \ 92 res; \ 93 }) 75 94 76 95 /** Enumeration of possible arguments types. … … 831 850 size_t size; 832 851 uint64_t number; 852 833 853 switch (qualifier) { 834 854 case PrintfQualifierByte: 835 855 size = sizeof(unsigned char); 836 number = (uint64_t) va_arg(ap, unsigned int);856 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 837 857 break; 838 858 case PrintfQualifierShort: 839 859 size = sizeof(unsigned short); 840 number = (uint64_t) va_arg(ap, unsigned int);860 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 841 861 break; 842 862 case PrintfQualifierInt: 843 863 size = sizeof(unsigned int); 844 number = (uint64_t) va_arg(ap, unsigned int);864 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 845 865 break; 846 866 case PrintfQualifierLong: 847 867 size = sizeof(unsigned long); 848 number = (uint64_t) va_arg(ap, unsigned long);868 number = PRINTF_GET_INT_ARGUMENT(long, ap, flags); 849 869 break; 850 870 case PrintfQualifierLongLong: 851 871 size = sizeof(unsigned long long); 852 number = (uint64_t) va_arg(ap, unsigned long long);872 number = PRINTF_GET_INT_ARGUMENT(long long, ap, flags); 853 873 break; 854 874 case PrintfQualifierPointer: … … 865 885 counter = -counter; 866 886 goto out; 867 }868 869 if (flags & __PRINTF_FLAG_SIGNED) {870 if (number & (0x1 << (size * 8 - 1))) {871 flags |= __PRINTF_FLAG_NEGATIVE;872 873 if (size == sizeof(uint64_t)) {874 number = -((int64_t) number);875 } else {876 number = ~number;877 number &=878 ~(0xFFFFFFFFFFFFFFFFll <<879 (size * 8));880 number++;881 }882 }883 887 } 884 888
Note:
See TracChangeset
for help on using the changeset viewer.