mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Fix for errno-style error reporting in printf
This commit is contained in:
parent
3a475a99fc
commit
40c0c5a298
1 changed files with 34 additions and 39 deletions
|
@ -66,7 +66,7 @@ struct builtin_printf_state_t
|
|||
{
|
||||
}
|
||||
|
||||
void verify_numeric(const wchar_t *s, const wchar_t *end);
|
||||
void verify_numeric(const wchar_t *s, const wchar_t *end, int errcode);
|
||||
|
||||
void print_direc(const wchar_t *start, size_t length, wchar_t conversion,
|
||||
bool have_field_width, int field_width,
|
||||
|
@ -216,11 +216,11 @@ void builtin_printf_state_t::append_format_output(const wchar_t *fmt, ...)
|
|||
}
|
||||
|
||||
|
||||
void builtin_printf_state_t::verify_numeric(const wchar_t *s, const wchar_t *end)
|
||||
void builtin_printf_state_t::verify_numeric(const wchar_t *s, const wchar_t *end, int errcode)
|
||||
{
|
||||
if (errno)
|
||||
if (errcode != 0)
|
||||
{
|
||||
this->fatal_error(L"%ls", s);
|
||||
this->fatal_error(L"%ls: %s", s, strerror(errcode));
|
||||
}
|
||||
else if (*end)
|
||||
{
|
||||
|
@ -267,7 +267,7 @@ static T string_to_scalar_type(const wchar_t *s, builtin_printf_state_t *state)
|
|||
wchar_t *end = NULL;
|
||||
errno = 0;
|
||||
val = raw_string_to_scalar_type<T>(s, &end);
|
||||
state->verify_numeric(s, end);
|
||||
state->verify_numeric(s, end, errno);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
@ -405,11 +405,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
|
|||
// Start with everything except the conversion specifier
|
||||
wcstring fmt(start, length);
|
||||
|
||||
/* Create a null-terminated copy of the % directive, with an
|
||||
intmax_t-wide width modifier substituted for any existing
|
||||
integer length modifier. */
|
||||
{
|
||||
// Append the appropriate width specifier
|
||||
/* Create a copy of the % directive, with an intmax_t-wide width modifier substituted for any existing integer length modifier. */
|
||||
switch (conversion)
|
||||
{
|
||||
case L'd':
|
||||
|
@ -436,7 +432,6 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
|
|||
|
||||
// Append the conversion itself
|
||||
fmt.push_back(conversion);
|
||||
}
|
||||
|
||||
switch (conversion)
|
||||
{
|
||||
|
@ -735,6 +730,6 @@ static int builtin_printf(parser_t &parser, wchar_t **argv)
|
|||
argc -= args_used;
|
||||
argv += args_used;
|
||||
}
|
||||
while (args_used > 0 && argc > 0);
|
||||
while (args_used > 0 && argc > 0 && ! state.early_exit);
|
||||
return state.exit_code;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue