From f3745ea489c5ef454e2ce68926c5f39f5b30f240 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 19 Apr 2008 19:32:08 +0000 Subject: libbb: introduce xmalloc_xopen_read_close and use where appropriate instead of xmalloc_open_read_close. function old new delta xmalloc_xopen_read_close - 34 +34 xmalloc_open_read_close 163 171 +8 passwd_main 1070 1074 +4 rexecve 254 257 +3 handle_incoming_and_exit 2657 2659 +2 parse_command 1509 1510 +1 buffer_fill_and_print 76 73 -3 evaltreenr 599 589 -10 evaltree 599 589 -10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/3 up/down: 52/-23) Total: 29 bytes --- libbb/read.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'libbb') diff --git a/libbb/read.c b/libbb/read.c index 1d31fb076..ba366cb97 100644 --- a/libbb/read.c +++ b/libbb/read.c @@ -212,7 +212,9 @@ void *xmalloc_open_read_close(const char *filename, size_t *sizep) int fd; off_t len; - fd = xopen(filename, O_RDONLY); + fd = open(filename, O_RDONLY); + if (fd < 0) + return NULL; /* /proc/N/stat files report len 0 here */ /* In order to make such files readable, we add small const */ len = xlseek(fd, 0, SEEK_END) | 0x3ff; /* + up to 1k */ @@ -229,3 +231,11 @@ void *xmalloc_open_read_close(const char *filename, size_t *sizep) *sizep = size; return buf; } + +void *xmalloc_xopen_read_close(const char *filename, size_t *sizep) +{ + void *buf = xmalloc_open_read_close(filename, sizep); + if (!buf) + bb_perror_msg_and_die("can't read '%s'", filename); + return buf; +} -- cgit v1.2.3