From 00657c96b9b3963230d89ccc3dc2959d034673e7 Mon Sep 17 00:00:00 2001 From: aldot Date: Wed, 12 Apr 2006 17:55:51 +0000 Subject: - 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 --- libbb/Makefile.in | 1 + libbb/bb_xsocket.c | 18 ++++++++++++++++++ libbb/xconnect.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 libbb/bb_xsocket.c (limited to 'libbb') 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 +#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); -- cgit v1.2.3-55-g6feb