New common unarchive code.

This commit is contained in:
Glenn L McGrath
2002-09-25 02:47:48 +00:00
parent ecfa290cfd
commit 7ca04f328e
36 changed files with 2436 additions and 1914 deletions

View File

@ -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)