aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-09-25 02:47:48 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-09-25 02:47:48 +0000
commit7ca04f328e22fcbee4659d73f9a72dfdf1dd6a23 (patch)
treef38c7ef4317eea28c6abdb0adbbb286fe041711e /libbb/xfuncs.c
parentecfa290cfd4953598e6d91989bd66ac16e135f84 (diff)
downloadbusybox-7ca04f328e22fcbee4659d73f9a72dfdf1dd6a23.tar.gz
New common unarchive code.
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r--libbb/xfuncs.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 869c04a4c..2249e263a 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -19,10 +19,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <sys/types.h>
+#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#include "libbb.h"
@@ -85,6 +88,59 @@ FILE *xfopen(const char *path, const char *mode)
return fp;
}
+extern int xopen(const char *pathname, int flags)
+{
+ int ret;
+
+ ret = open(pathname, flags);
+ if (ret == -1) {
+ perror_msg_and_die("%s", pathname);
+ }
+ return ret;
+}
+
+extern ssize_t xread(int fd, void *buf, size_t count)
+{
+ ssize_t size;
+
+ size = read(fd, buf, count);
+ if (size == -1) {
+ perror_msg_and_die("Read error");
+ }
+ return(size);
+}
+
+extern void xread_all(int fd, void *buf, size_t count)
+{
+ ssize_t size;
+
+ size = xread(fd, buf, count);
+ if (size != count) {
+ error_msg_and_die("Short read");
+ }
+ return;
+}
+
+extern ssize_t xread_all_eof(int fd, void *buf, size_t count)
+{
+ ssize_t size;
+
+ size = xread(fd, buf, count);
+ if ((size != 0) && (size != count)) {
+ error_msg_and_die("Short read");
+ }
+ return(size);
+}
+
+extern unsigned char xread_char(int fd)
+{
+ char tmp;
+
+ xread_all(fd, &tmp, 1);
+
+ return(tmp);
+}
+
/* Stupid gcc always includes its own builtin strlen()... */
#undef strlen
size_t xstrlen(const char *string)