aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-01-04 01:32:44 -0600
committerRob Landley <rob@landley.net>2017-01-04 01:32:44 -0600
commita1a559e25a19726b3a62267feb5e89bad2fcd01e (patch)
tree7f6942e4a2801e41a027f4ba5db40a47e05a7eab /lib/xwrap.c
parent4d4ca28acaa44069893d06aea64e304809527b16 (diff)
downloadtoybox-a1a559e25a19726b3a62267feb5e89bad2fcd01e.tar.gz
Some lib fixes: mark xvfork() noinline, make xsendfile() return bytes copied,
make xsocket()'s returned fd CLOEXEC.
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 66972f2b..611bdb52 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -163,7 +163,7 @@ void xflush(void)
// share a stack, so child returning from a function would stomp the return
// address parent would need. Solution: make vfork() an argument so processes
// diverge before function gets called.
-pid_t xvforkwrap(pid_t pid)
+pid_t __attribute__((noinline)) xvforkwrap(pid_t pid)
{
if (pid == -1) perror_exit("vfork");
@@ -732,16 +732,20 @@ void xpidfile(char *name)
// Copy the rest of in to out and close both files.
-void xsendfile(int in, int out)
+long long xsendfile(int in, int out)
{
+ long long total = 0;
long len;
- if (in<0) return;
+ if (in<0) return 0;
for (;;) {
len = xread(in, libbuf, sizeof(libbuf));
if (len<1) break;
xwrite(out, libbuf, len);
+ total += len;
}
+
+ return total;
}
// parse fractional seconds with optional s/m/h/d suffix