aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-05-26 16:44:20 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-05-26 16:44:20 +0000
commit5a6aeddfa7262e41802c77f70c9ef88e9c2c2476 (patch)
tree36bf70fe7e6c67e4ab37c446a191272eb90097ed /libbb
parent6239b1f50a04121d96daba2cdc2f7c3765c9007b (diff)
downloadbusybox-w32-5a6aeddfa7262e41802c77f70c9ef88e9c2c2476.tar.gz
busybox-w32-5a6aeddfa7262e41802c77f70c9ef88e9c2c2476.tar.bz2
busybox-w32-5a6aeddfa7262e41802c77f70c9ef88e9c2c2476.zip
xpipe: introduce (saves ~170 bytes)
udhcp/signalpipe.c: use pipe instead of socketpair.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/xfuncs.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index a85a046cf..4eb4737c0 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -106,7 +106,7 @@ FILE *xfopen(const char *path, const char *mode)
106{ 106{
107 FILE *fp = fopen(path, mode); 107 FILE *fp = fopen(path, mode);
108 if (fp == NULL) 108 if (fp == NULL)
109 bb_perror_msg_and_die("cannot open '%s'", path); 109 bb_perror_msg_and_die("can't open '%s'", path);
110 return fp; 110 return fp;
111} 111}
112 112
@@ -117,7 +117,7 @@ int xopen3(const char *pathname, int flags, int mode)
117 117
118 ret = open(pathname, flags, mode); 118 ret = open(pathname, flags, mode);
119 if (ret < 0) { 119 if (ret < 0) {
120 bb_perror_msg_and_die("cannot open '%s'", pathname); 120 bb_perror_msg_and_die("can't open '%s'", pathname);
121 } 121 }
122 return ret; 122 return ret;
123} 123}
@@ -135,7 +135,7 @@ int open3_or_warn(const char *pathname, int flags, int mode)
135 135
136 ret = open(pathname, flags, mode); 136 ret = open(pathname, flags, mode);
137 if (ret < 0) { 137 if (ret < 0) {
138 bb_perror_msg("cannot open '%s'", pathname); 138 bb_perror_msg("can't open '%s'", pathname);
139 } 139 }
140 return ret; 140 return ret;
141} 141}
@@ -146,21 +146,27 @@ int open_or_warn(const char *pathname, int flags)
146 return open3_or_warn(pathname, flags, 0666); 146 return open3_or_warn(pathname, flags, 0666);
147} 147}
148 148
149void xpipe(int filedes[2])
150{
151 if (pipe(filedes))
152 bb_perror_msg_and_die("can't create pipe");
153}
154
149void xunlink(const char *pathname) 155void xunlink(const char *pathname)
150{ 156{
151 if (unlink(pathname)) 157 if (unlink(pathname))
152 bb_perror_msg_and_die("cannot remove file '%s'", pathname); 158 bb_perror_msg_and_die("can't remove file '%s'", pathname);
153} 159}
154 160
155// Turn on nonblocking I/O on a fd 161// Turn on nonblocking I/O on a fd
156int ndelay_on(int fd) 162int ndelay_on(int fd)
157{ 163{
158 return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | O_NONBLOCK); 164 return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) | O_NONBLOCK);
159} 165}
160 166
161int ndelay_off(int fd) 167int ndelay_off(int fd)
162{ 168{
163 return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); 169 return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) & ~O_NONBLOCK);
164} 170}
165 171
166// "Renumber" opened fd 172// "Renumber" opened fd
@@ -169,7 +175,7 @@ void xmove_fd(int from, int to)
169 if (from == to) 175 if (from == to)
170 return; 176 return;
171 if (dup2(from, to) != to) 177 if (dup2(from, to) != to)
172 bb_perror_msg_and_die("cannot duplicate file descriptor"); 178 bb_perror_msg_and_die("can't duplicate file descriptor");
173 close(from); 179 close(from);
174} 180}
175 181
@@ -199,7 +205,7 @@ off_t xlseek(int fd, off_t offset, int whence)
199void die_if_ferror(FILE *fp, const char *fn) 205void die_if_ferror(FILE *fp, const char *fn)
200{ 206{
201 if (ferror(fp)) { 207 if (ferror(fp)) {
202 /* doesn't set useful errno */ 208 /* ferror doesn't set useful errno */
203 bb_error_msg_and_die("%s: I/O error", fn); 209 bb_error_msg_and_die("%s: I/O error", fn);
204 } 210 }
205} 211}
@@ -520,7 +526,7 @@ DIR *warn_opendir(const char *path)
520 526
521 dp = opendir(path); 527 dp = opendir(path);
522 if (!dp) 528 if (!dp)
523 bb_perror_msg("cannot open '%s'", path); 529 bb_perror_msg("can't open '%s'", path);
524 return dp; 530 return dp;
525} 531}
526 532
@@ -531,7 +537,7 @@ DIR *xopendir(const char *path)
531 537
532 dp = opendir(path); 538 dp = opendir(path);
533 if (!dp) 539 if (!dp)
534 bb_perror_msg_and_die("cannot open '%s'", path); 540 bb_perror_msg_and_die("can't open '%s'", path);
535 return dp; 541 return dp;
536} 542}
537 543
@@ -568,10 +574,8 @@ void xlisten(int s, int backlog)
568 if (listen(s, backlog)) bb_perror_msg_and_die("listen"); 574 if (listen(s, backlog)) bb_perror_msg_and_die("listen");
569} 575}
570 576
571/* Die with an error message if we the sendto failed. 577/* Die with an error message if sendto failed.
572 * Return bytes sent otherwise 578 * Return bytes sent otherwise */
573 */
574
575ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 579ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
576 socklen_t tolen) 580 socklen_t tolen)
577{ 581{