summaryrefslogtreecommitdiffhomepage
path: root/libbb
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-04-12 17:55:51 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-04-12 17:55:51 +0000
commitdac7ff15b7d32deeeef3d9665744fc5774c21d70 (patch)
tree0e4c34863628d79fdad0c6217f4deb0ca0a91c33 /libbb
parent79865bc5077cf6d17b27e9599921d4c85b1575fd (diff)
- 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.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Makefile.in1
-rw-r--r--libbb/bb_xsocket.c18
-rw-r--r--libbb/xconnect.c2
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:= \
trim.c u_signal_names.c vdprintf.c verror_msg.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
+ bb_xsocket.c \
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
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 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * bb_xsocket.c - a socket() which dies on failure with error message
+ *
+ * Copyright (C) 2006 Denis Vlasenko
+ *
+ * Licensed under LGPL, see file docs/lesser.txt in this tarball for details.
+ */
+#include <sys/socket.h>
+#include "libbb.h"
+
+int bb_xsocket(int domain, int type, int protocol)
+{
+ int r = socket(domain, type, protocol);
+ if (r < 0)
+ bb_perror_msg_and_die("socket");
+ return r;
+}
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)
int xconnect(struct sockaddr_in *s_addr)
{
- int s = socket(AF_INET, SOCK_STREAM, 0);
+ int s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0)
{
if (ENABLE_FEATURE_CLEAN_UP) close(s);