diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-09-25 02:47:48 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-09-25 02:47:48 +0000 |
commit | d4a48a11220f6a86ee2702c01c986d0a1a0a7bbc (patch) | |
tree | f38c7ef4317eea28c6abdb0adbbb286fe041711e /libbb/xfuncs.c | |
parent | d2871e072e3f545a35e07d715f3cf02cf96c011d (diff) | |
download | busybox-w32-d4a48a11220f6a86ee2702c01c986d0a1a0a7bbc.tar.gz busybox-w32-d4a48a11220f6a86ee2702c01c986d0a1a0a7bbc.tar.bz2 busybox-w32-d4a48a11220f6a86ee2702c01c986d0a1a0a7bbc.zip |
New common unarchive code.
git-svn-id: svn://busybox.net/trunk/busybox@5589 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r-- | libbb/xfuncs.c | 56 |
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 @@ | |||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <sys/types.h> | ||
23 | #include <sys/stat.h> | ||
22 | #include <stdio.h> | 24 | #include <stdio.h> |
23 | #include <string.h> | 25 | #include <string.h> |
24 | #include <stdlib.h> | 26 | #include <stdlib.h> |
25 | #include <unistd.h> | 27 | #include <unistd.h> |
28 | #include <fcntl.h> | ||
26 | #include "libbb.h" | 29 | #include "libbb.h" |
27 | 30 | ||
28 | 31 | ||
@@ -85,6 +88,59 @@ FILE *xfopen(const char *path, const char *mode) | |||
85 | return fp; | 88 | return fp; |
86 | } | 89 | } |
87 | 90 | ||
91 | extern int xopen(const char *pathname, int flags) | ||
92 | { | ||
93 | int ret; | ||
94 | |||
95 | ret = open(pathname, flags); | ||
96 | if (ret == -1) { | ||
97 | perror_msg_and_die("%s", pathname); | ||
98 | } | ||
99 | return ret; | ||
100 | } | ||
101 | |||
102 | extern ssize_t xread(int fd, void *buf, size_t count) | ||
103 | { | ||
104 | ssize_t size; | ||
105 | |||
106 | size = read(fd, buf, count); | ||
107 | if (size == -1) { | ||
108 | perror_msg_and_die("Read error"); | ||
109 | } | ||
110 | return(size); | ||
111 | } | ||
112 | |||
113 | extern void xread_all(int fd, void *buf, size_t count) | ||
114 | { | ||
115 | ssize_t size; | ||
116 | |||
117 | size = xread(fd, buf, count); | ||
118 | if (size != count) { | ||
119 | error_msg_and_die("Short read"); | ||
120 | } | ||
121 | return; | ||
122 | } | ||
123 | |||
124 | extern ssize_t xread_all_eof(int fd, void *buf, size_t count) | ||
125 | { | ||
126 | ssize_t size; | ||
127 | |||
128 | size = xread(fd, buf, count); | ||
129 | if ((size != 0) && (size != count)) { | ||
130 | error_msg_and_die("Short read"); | ||
131 | } | ||
132 | return(size); | ||
133 | } | ||
134 | |||
135 | extern unsigned char xread_char(int fd) | ||
136 | { | ||
137 | char tmp; | ||
138 | |||
139 | xread_all(fd, &tmp, 1); | ||
140 | |||
141 | return(tmp); | ||
142 | } | ||
143 | |||
88 | /* Stupid gcc always includes its own builtin strlen()... */ | 144 | /* Stupid gcc always includes its own builtin strlen()... */ |
89 | #undef strlen | 145 | #undef strlen |
90 | size_t xstrlen(const char *string) | 146 | size_t xstrlen(const char *string) |