diff options
| author | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-04-12 17:55:51 +0000 |
|---|---|---|
| committer | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-04-12 17:55:51 +0000 |
| commit | 00657c96b9b3963230d89ccc3dc2959d034673e7 (patch) | |
| tree | 0e4c34863628d79fdad0c6217f4deb0ca0a91c33 /libbb | |
| parent | fa6199c4ed8fdbb6901f43a06fb22d37e6e9b9e1 (diff) | |
| download | busybox-w32-00657c96b9b3963230d89ccc3dc2959d034673e7.tar.gz busybox-w32-00657c96b9b3963230d89ccc3dc2959d034673e7.tar.bz2 busybox-w32-00657c96b9b3963230d89ccc3dc2959d034673e7.zip | |
- patch from Denis Vlasenko to add and use bb_xsocket() and to use
bb_xopen some more while at it.
Also use shorter boilerplate while at it.
git-svn-id: svn://busybox.net/trunk/busybox@14833 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/Makefile.in | 1 | ||||
| -rw-r--r-- | libbb/bb_xsocket.c | 18 | ||||
| -rw-r--r-- | libbb/xconnect.c | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index de511fc9b..c69978370 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
| @@ -30,6 +30,7 @@ LIBBB-y:= \ | |||
| 30 | trim.c u_signal_names.c vdprintf.c verror_msg.c \ | 30 | trim.c u_signal_names.c vdprintf.c verror_msg.c \ |
| 31 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ | 31 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ |
| 32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ | 32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ |
| 33 | bb_xsocket.c \ | ||
| 33 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ | 34 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ |
| 34 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ | 35 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ |
| 35 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ | 36 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ |
diff --git a/libbb/bb_xsocket.c b/libbb/bb_xsocket.c new file mode 100644 index 000000000..839309ae1 --- /dev/null +++ b/libbb/bb_xsocket.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * bb_xsocket.c - a socket() which dies on failure with error message | ||
| 4 | * | ||
| 5 | * Copyright (C) 2006 Denis Vlasenko | ||
| 6 | * | ||
| 7 | * Licensed under LGPL, see file docs/lesser.txt in this tarball for details. | ||
| 8 | */ | ||
| 9 | #include <sys/socket.h> | ||
| 10 | #include "libbb.h" | ||
| 11 | |||
| 12 | int bb_xsocket(int domain, int type, int protocol) | ||
| 13 | { | ||
| 14 | int r = socket(domain, type, protocol); | ||
| 15 | if (r < 0) | ||
| 16 | bb_perror_msg_and_die("socket"); | ||
| 17 | return r; | ||
| 18 | } | ||
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index ec99c5882..39052b87b 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
| @@ -61,7 +61,7 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host) | |||
| 61 | 61 | ||
| 62 | int xconnect(struct sockaddr_in *s_addr) | 62 | int xconnect(struct sockaddr_in *s_addr) |
| 63 | { | 63 | { |
| 64 | int s = socket(AF_INET, SOCK_STREAM, 0); | 64 | int s = bb_xsocket(AF_INET, SOCK_STREAM, 0); |
| 65 | if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) | 65 | if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) |
| 66 | { | 66 | { |
| 67 | if (ENABLE_FEATURE_CLEAN_UP) close(s); | 67 | if (ENABLE_FEATURE_CLEAN_UP) close(s); |
