summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c2
-rw-r--r--libbb/write.c5
-rw-r--r--libbb/xconnect.c18
-rw-r--r--libbb/xfuncs_printf.c4
4 files changed, 23 insertions, 6 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 13cdb81..80380ae 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -99,7 +99,7 @@ static const char *unpack_usage_messages(void)
static void full_write2_str(const char *str)
{
- full_write(STDERR_FILENO, str, strlen(str));
+ xwrite_str(STDERR_FILENO, str);
}
void FAST_FUNC bb_show_usage(void)
diff --git a/libbb/write.c b/libbb/write.c
index 37f4617..116e4d1 100644
--- a/libbb/write.c
+++ b/libbb/write.c
@@ -10,11 +10,10 @@
#include "libbb.h"
/* Open file and write string str to it, close file.
- * Die on any open or write-error. */
+ * Die on any open or write error. */
void FAST_FUNC xopen_xwrite_close(const char* file, const char* str)
{
int fd = xopen(file, O_WRONLY);
-
- xwrite(fd, str, strlen(str));
+ xwrite_str(fd, str);
close(fd);
}
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 2eb4cb9..9758445 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -35,6 +35,19 @@ int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface)
return r;
}
+len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd)
+{
+ len_and_sockaddr *lsa;
+ socklen_t len = 0;
+
+ /* Can be optimized to do only one getsockname() */
+ if (getsockname(fd, NULL, &len) != 0)
+ return NULL;
+ lsa = xzalloc(LSA_LEN_SIZE + len);
+ lsa->len = len;
+ getsockname(fd, &lsa->u.sa, &lsa->len);
+ return lsa;
+}
void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen)
{
@@ -51,8 +64,9 @@ void FAST_FUNC xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen)
/* Return port number for a service.
* If "port" is a number use it as the port.
- * If "port" is a name it is looked up in /etc/services, if it isnt found return
- * default_port */
+ * If "port" is a name it is looked up in /etc/services,
+ * if it isnt found return default_port
+ */
unsigned FAST_FUNC bb_lookup_port(const char *port, const char *protocol, unsigned default_port)
{
unsigned port_nr = default_port;
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index cd0f84d..6d0fa6e 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -208,6 +208,10 @@ void FAST_FUNC xwrite(int fd, const void *buf, size_t count)
bb_error_msg_and_die("short write");
}
}
+void FAST_FUNC xwrite_str(int fd, const char *str)
+{
+ xwrite(fd, str, strlen(str));
+}
// Die with an error message if we can't lseek to the right spot.
off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)