diff options
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r-- | libbb/xfuncs.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index d02ef9c77..fad111aa9 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) | |||
639 | 639 | ||
640 | return ret; | 640 | return ret; |
641 | } | 641 | } |
642 | |||
643 | void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) | ||
644 | { | ||
645 | va_list p; | ||
646 | |||
647 | if (ioctl(fd, request, argp) < 0) { | ||
648 | va_start(p, fmt); | ||
649 | bb_vperror_msg(fmt, p); | ||
650 | /* xfunc_die can actually longjmp, so be nice */ | ||
651 | va_end(p); | ||
652 | xfunc_die(); | ||
653 | } | ||
654 | } | ||
655 | |||
656 | int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) | ||
657 | { | ||
658 | va_list p; | ||
659 | int ret = ioctl(fd, request, argp); | ||
660 | |||
661 | if (ret < 0) { | ||
662 | va_start(p, fmt); | ||
663 | bb_vperror_msg(fmt, p); | ||
664 | va_end(p); | ||
665 | } | ||
666 | return ret; | ||
667 | } | ||
668 | |||
669 | #if ENABLE_IOCTL_HEX2STR_ERROR | ||
670 | int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name) | ||
671 | { | ||
672 | int ret; | ||
673 | |||
674 | ret = ioctl(fd, request, argp); | ||
675 | if (ret < 0) | ||
676 | bb_perror_msg("%s", ioctl_name); | ||
677 | return ret; | ||
678 | } | ||
679 | void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name) | ||
680 | { | ||
681 | if (ioctl(fd, request, argp) < 0) | ||
682 | bb_perror_msg_and_die("%s", ioctl_name); | ||
683 | } | ||
684 | #else | ||
685 | int bb_ioctl_or_warn(int fd, int request, void *argp) | ||
686 | { | ||
687 | int ret; | ||
688 | |||
689 | ret = ioctl(fd, request, argp); | ||
690 | if (ret < 0) | ||
691 | bb_perror_msg("ioctl %#x failed", request); | ||
692 | return ret; | ||
693 | } | ||
694 | void bb_xioctl(int fd, int request, void *argp) | ||
695 | { | ||
696 | if (ioctl(fd, request, argp) < 0) | ||
697 | bb_perror_msg_and_die("ioctl %#x failed", request); | ||
698 | } | ||
699 | #endif | ||