Changeset 2911 in kBuild
- Timestamp:
- Sep 10, 2016 11:16:59 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/err.c
r2413 r2911 5 5 6 6 /* 7 * Copyright (c) 2005-201 0knut st. osmundsen <[email protected]>7 * Copyright (c) 2005-2016 knut st. osmundsen <[email protected]> 8 8 * 9 9 * This file is part of kBuild. … … 34 34 #include "err.h" 35 35 36 #ifdef KBUILD_OS_WINDOWS 37 /* This is a trick to speed up console output on windows. */ 38 # undef fwrite 39 # define fwrite maybe_con_fwrite 40 extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *); 41 #endif 42 36 43 37 44 /** The current program name. */ … … 43 50 va_list args; 44 51 int error = errno; 52 53 /* stderr is unbuffered, so try format the whole message and print it in 54 one go so it won't be split by other output. */ 55 char szMsg[4096]; 56 int cchMsg = snprintf(szMsg, sizeof(szMsg), "%s: ", g_progname); 57 if (cchMsg < sizeof(szMsg) - 1 && cchMsg > 0) 58 { 59 int cchMsg2; 60 va_start(args, fmt); 61 cchMsg += cchMsg2 = vsnprintf(&szMsg[cchMsg], sizeof(szMsg) - cchMsg, fmt, args); 62 va_end(args); 63 64 if ( cchMsg < sizeof(szMsg) - 1 65 && cchMsg2 >= 0) 66 { 67 cchMsg += cchMsg2 = snprintf(&szMsg[cchMsg], sizeof(szMsg) - cchMsg, ": %s\n", strerror(error)); 68 if ( cchMsg < sizeof(szMsg) - 1 69 && cchMsg2 >= 0) 70 { 71 fwrite(szMsg, cchMsg, 1, stderr); 72 return eval; 73 } 74 75 } 76 77 } 78 79 /* fallback */ 45 80 fprintf(stderr, "%s: ", g_progname); 46 81 va_start(args, fmt); … … 56 91 { 57 92 va_list args; 93 94 /* stderr is unbuffered, so try format the whole message and print it in 95 one go so it won't be split by other output. */ 96 char szMsg[4096]; 97 int cchMsg = snprintf(szMsg, sizeof(szMsg), "%s: ", g_progname); 98 if (cchMsg < sizeof(szMsg) - 1 && cchMsg > 0) 99 { 100 int cchMsg2; 101 va_start(args, fmt); 102 cchMsg += cchMsg2 = vsnprintf(&szMsg[cchMsg], sizeof(szMsg) - cchMsg, fmt, args); 103 va_end(args); 104 105 if ( cchMsg < sizeof(szMsg) - 1 106 && cchMsg2 >= 0) 107 { 108 szMsg[cchMsg++] = '\n'; 109 fwrite(szMsg, cchMsg, 1, stderr); 110 return eval; 111 } 112 113 } 114 115 /* fallback */ 58 116 fprintf(stderr, "%s: ", g_progname); 59 117 va_start(args, fmt); … … 69 127 int error = errno; 70 128 va_list args; 129 130 /* stderr is unbuffered, so try format the whole message and print it in 131 one go so it won't be split by other output. */ 132 char szMsg[4096]; 133 int cchMsg = snprintf(szMsg, sizeof(szMsg), "%s: ", g_progname); 134 if (cchMsg < sizeof(szMsg) - 1 && cchMsg > 0) 135 { 136 int cchMsg2; 137 va_start(args, fmt); 138 cchMsg += cchMsg2 = vsnprintf(&szMsg[cchMsg], sizeof(szMsg) - cchMsg, fmt, args); 139 va_end(args); 140 141 if ( cchMsg < sizeof(szMsg) - 1 142 && cchMsg2 >= 0) 143 { 144 cchMsg += cchMsg2 = snprintf(&szMsg[cchMsg], sizeof(szMsg) - cchMsg, ": %s\n", strerror(error)); 145 if ( cchMsg < sizeof(szMsg) - 1 146 && cchMsg2 >= 0) 147 { 148 fwrite(szMsg, cchMsg, 1, stderr); 149 return; 150 } 151 152 } 153 } 154 155 /* fallback */ 71 156 fprintf(stderr, "%s: ", g_progname); 72 157 va_start(args, fmt); … … 79 164 { 80 165 va_list args; 166 167 /* stderr is unbuffered, so try format the whole message and print it in 168 one go so it won't be split by other output. */ 169 char szMsg[4096]; 170 int cchMsg = snprintf(szMsg, sizeof(szMsg), "%s: ", g_progname); 171 if (cchMsg < sizeof(szMsg) - 1 && cchMsg > 0) 172 { 173 int cchMsg2; 174 va_start(args, fmt); 175 cchMsg += cchMsg2 = vsnprintf(&szMsg[cchMsg], sizeof(szMsg) - cchMsg, fmt, args); 176 va_end(args); 177 178 if ( cchMsg < sizeof(szMsg) - 1 179 && cchMsg2 >= 0) 180 { 181 szMsg[cchMsg++] = '\n'; 182 fwrite(szMsg, cchMsg, 1, stderr); 183 return; 184 } 185 186 } 187 188 /* fallback */ 81 189 fprintf(stderr, "%s: ", g_progname); 82 190 va_start(args, fmt);
Note:
See TracChangeset
for help on using the changeset viewer.