| 213 | } |
| 214 | |
| 215 | static const char *fmt_with_err(char *buf, int n, const char *fmt) |
| 216 | { |
| 217 | char str_error[256], *err; |
| 218 | size_t i, j; |
| 219 | |
| 220 | err = strerror(errno); |
| 221 | for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) { |
| 222 | if ((str_error[j++] = err[i++]) != '%') |
| 223 | continue; |
| 224 | if (j < sizeof(str_error) - 1) { |
| 225 | str_error[j++] = '%'; |
| 226 | } else { |
| 227 | /* No room to double the '%', so we overwrite it with |
| 228 | * '\0' below */ |
| 229 | j--; |
| 230 | break; |
| 231 | } |
| 232 | } |
| 233 | str_error[j] = 0; |
| 234 | /* Truncation is acceptable here */ |
| 235 | snprintf(buf, n, "%s: %s", fmt, str_error); |
| 236 | return buf; |
| 237 | } |
| 238 | |
| 239 | void NORETURN die_errno(const char *fmt, ...) |
| 240 | { |
no outgoing calls
no test coverage detected