diff options
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) |
