diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-17 16:33:57 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-17 16:33:57 +0100 |
commit | 146a7fe4a2427d4aaece1d1a642c52a50c95691f (patch) | |
tree | 610db5431aeffbda14d1f37381995a7322ce21aa /lib | |
parent | 84fd8a956cda82b54c85d8047c6f7ed7ec6879c5 (diff) | |
parent | 52fac4b1ff5da3deff3e9f0cae681ff23337c1f1 (diff) | |
download | barebox-146a7fe4a2427d4aaece1d1a642c52a50c95691f.tar.gz barebox-146a7fe4a2427d4aaece1d1a642c52a50c95691f.tar.xz |
Merge branch 'work/uimage' into next
Conflicts:
arch/ppc/lib/ppclinux.c
commands/bootm.c
include/boot.h
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libbb.c | 50 | ||||
-rw-r--r-- | lib/uncompress.c | 8 |
2 files changed, 58 insertions, 0 deletions
diff --git a/lib/libbb.c b/lib/libbb.c index 3d02202634..9a0a60bdb8 100644 --- a/lib/libbb.c +++ b/lib/libbb.c @@ -127,3 +127,53 @@ char *simple_itoa(unsigned int i) return p + 1; } EXPORT_SYMBOL(simple_itoa); + +/* + * write_full - write to filedescriptor + * + * Like write, but guarantees to write the full buffer out, else + * it returns with an error. + */ +int write_full(int fd, void *buf, size_t size) +{ + size_t insize = size; + int now; + + while (size) { + now = write(fd, buf, size); + if (now <= 0) + return now; + size -= now; + buf += now; + } + + return insize; +} +EXPORT_SYMBOL(write_full); + +/* + * read_full - read from filedescriptor + * + * Like read, but this function only returns less bytes than + * requested when the end of file is reached. + */ +int read_full(int fd, void *buf, size_t size) +{ + size_t insize = size; + int now; + int total = 0; + + while (size) { + now = read(fd, buf, size); + if (now == 0) + return total; + if (now < 0) + return now; + total += now; + size -= now; + buf += now; + } + + return insize; +} +EXPORT_SYMBOL(read_full); diff --git a/lib/uncompress.c b/lib/uncompress.c index beb96d167a..cdfebe9173 100644 --- a/lib/uncompress.c +++ b/lib/uncompress.c @@ -158,3 +158,11 @@ int uncompress_fd_to_fd(int infd, int outfd, NULL, error_fn); } + +int uncompress_fd_to_buf(int infd, void *output, + void(*error_fn)(char *x)) +{ + uncompress_infd = infd; + + return uncompress(NULL, 0, fill_fd, NULL, output, NULL, error_fn); +} |