diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Config.in | 7 | ||||
-rw-r--r-- | libbb/xfuncs.c | 58 |
2 files changed, 65 insertions, 0 deletions
diff --git a/libbb/Config.in b/libbb/Config.in index f82a2b1..5055015 100644 --- a/libbb/Config.in +++ b/libbb/Config.in @@ -120,4 +120,11 @@ config MONOTONIC_SYSCALL will be used instead (which gives wrong results if date/time is reset). +config IOCTL_HEX2STR_ERROR + bool "Use ioctl names rather than hex values in error messages" + default y + help + Use ioctl names rather than hex values in error messages + (e.g. VT_DISALLOCATE rather than 0x5608). If disabled this + saves about 1400 bytes. endmenu diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index d02ef9c..fad111a 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -639,3 +639,61 @@ int get_terminal_width_height(const int fd, int *width, int *height) return ret; } + +void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) +{ + va_list p; + + if (ioctl(fd, request, argp) < 0) { + va_start(p, fmt); + bb_vperror_msg(fmt, p); + /* xfunc_die can actually longjmp, so be nice */ + va_end(p); + xfunc_die(); + } +} + +int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) +{ + va_list p; + int ret = ioctl(fd, request, argp); + + if (ret < 0) { + va_start(p, fmt); + bb_vperror_msg(fmt, p); + va_end(p); + } + return ret; +} + +#if ENABLE_IOCTL_HEX2STR_ERROR +int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name) +{ + int ret; + + ret = ioctl(fd, request, argp); + if (ret < 0) + bb_perror_msg("%s", ioctl_name); + return ret; +} +void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name) +{ + if (ioctl(fd, request, argp) < 0) + bb_perror_msg_and_die("%s", ioctl_name); +} +#else +int bb_ioctl_or_warn(int fd, int request, void *argp) +{ + int ret; + + ret = ioctl(fd, request, argp); + if (ret < 0) + bb_perror_msg("ioctl %#x failed", request); + return ret; +} +void bb_xioctl(int fd, int request, void *argp) +{ + if (ioctl(fd, request, argp) < 0) + bb_perror_msg_and_die("ioctl %#x failed", request); +} +#endif |