diff options
author | Mike Frysinger <vapier@gentoo.org> | 2012-06-22 14:19:14 -0700 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2012-06-23 18:02:43 -0400 |
commit | 40abb498ca4a24495fe34e133379382ce8c3eaca (patch) | |
tree | a8779b17558a4c96eb2d5c56e82cee4743d408aa /libsbutil/sb_write_fd.c | |
parent | use m4_flatten to make multiline lists easier to handle (diff) | |
download | sandbox-40abb498ca4a24495fe34e133379382ce8c3eaca.tar.gz sandbox-40abb498ca4a24495fe34e133379382ce8c3eaca.tar.bz2 sandbox-40abb498ca4a24495fe34e133379382ce8c3eaca.zip |
significantly overhaul output helpers
There are a few major points we want to hit here:
- have all output from libsandbox go through portage helpers when we are
in the portage environment so that output is properly logged
- convert SB_E{info,warn,error} to sb_e{info,warn,error} to match style
of other functions and cut down on confusion
- move all abort/output helpers to libsbutil so it can be used in all
source trees and not just by libsandbox
- migrate all abort points to the centralized sb_ebort helper
Unfortunately, it's not terribly easy to untangle these into separate
patches, but hopefully this shouldn't be too messy as much of it is
mechanical: move funcs between files, and change the name of funcs
that get called.
URL: http://bugs.gentoo.org/278761
Reported-by: Mounir Lamouri <volkmar@gentoo.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsbutil/sb_write_fd.c')
-rw-r--r-- | libsbutil/sb_write_fd.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libsbutil/sb_write_fd.c b/libsbutil/sb_write_fd.c new file mode 100644 index 0000000..f19d7de --- /dev/null +++ b/libsbutil/sb_write_fd.c @@ -0,0 +1,42 @@ +/* + * helper for sucking up a file and writing it to a fd. + * good for copying the contents of small status files + * into a log file. + * + * Copyright 1999-2012 Gentoo Foundation + * Licensed under the GPL-2 + */ + +#include "headers.h" +#include "sbutil.h" + +int sb_copy_file_to_fd(const char *file, int ofd) +{ + int ret = -1; + + int ifd = sb_open(file, O_RDONLY|O_CLOEXEC, 0); + if (ifd == -1) + return ret; + + size_t pagesz = getpagesize(); + char *buf = xmalloc(pagesz); + while (1) { + size_t len = sb_read(ifd, buf, pagesz); + if (len == -1) + goto error; + else if (!len) + break; + size_t i; + for (i = 0; i < len; ++i) + if (!buf[i]) + buf[i] = ' '; + if (sb_write(ofd, buf, len) != len) + goto error; + } + + ret = 0; + error: + sb_close(ifd); + free(buf); + return ret; +} |