diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /libbb/xfuncs.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r-- | libbb/xfuncs.c | 89 |
1 files changed, 69 insertions, 20 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 820a0d7cc..43e8aef0c 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -30,31 +30,38 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | #ifndef DMALLOC | 32 | #ifndef DMALLOC |
33 | #ifdef L_xmalloc | ||
33 | extern void *xmalloc(size_t size) | 34 | extern void *xmalloc(size_t size) |
34 | { | 35 | { |
35 | void *ptr = malloc(size); | 36 | void *ptr = malloc(size); |
36 | if (ptr == NULL && size != 0) | 37 | if (ptr == NULL && size != 0) |
37 | error_msg_and_die(memory_exhausted); | 38 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
38 | return ptr; | 39 | return ptr; |
39 | } | 40 | } |
41 | #endif | ||
40 | 42 | ||
43 | #ifdef L_xrealloc | ||
41 | extern void *xrealloc(void *ptr, size_t size) | 44 | extern void *xrealloc(void *ptr, size_t size) |
42 | { | 45 | { |
43 | ptr = realloc(ptr, size); | 46 | ptr = realloc(ptr, size); |
44 | if (ptr == NULL && size != 0) | 47 | if (ptr == NULL && size != 0) |
45 | error_msg_and_die(memory_exhausted); | 48 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
46 | return ptr; | 49 | return ptr; |
47 | } | 50 | } |
51 | #endif | ||
48 | 52 | ||
53 | #ifdef L_xcalloc | ||
49 | extern void *xcalloc(size_t nmemb, size_t size) | 54 | extern void *xcalloc(size_t nmemb, size_t size) |
50 | { | 55 | { |
51 | void *ptr = calloc(nmemb, size); | 56 | void *ptr = calloc(nmemb, size); |
52 | if (ptr == NULL && nmemb != 0 && size != 0) | 57 | if (ptr == NULL && nmemb != 0 && size != 0) |
53 | error_msg_and_die(memory_exhausted); | 58 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
54 | return ptr; | 59 | return ptr; |
55 | } | 60 | } |
61 | #endif | ||
56 | 62 | ||
57 | extern char * xstrdup (const char *s) { | 63 | #ifdef L_xstrdup |
64 | extern char * bb_xstrdup (const char *s) { | ||
58 | char *t; | 65 | char *t; |
59 | 66 | ||
60 | if (s == NULL) | 67 | if (s == NULL) |
@@ -63,79 +70,121 @@ extern char * xstrdup (const char *s) { | |||
63 | t = strdup (s); | 70 | t = strdup (s); |
64 | 71 | ||
65 | if (t == NULL) | 72 | if (t == NULL) |
66 | error_msg_and_die(memory_exhausted); | 73 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
67 | 74 | ||
68 | return t; | 75 | return t; |
69 | } | 76 | } |
70 | #endif | 77 | #endif |
78 | #endif /* DMALLOC */ | ||
71 | 79 | ||
72 | extern char * xstrndup (const char *s, int n) { | 80 | #ifdef L_xstrndup |
81 | extern char * bb_xstrndup (const char *s, int n) { | ||
73 | char *t; | 82 | char *t; |
74 | 83 | ||
75 | if (s == NULL) | 84 | if (s == NULL) |
76 | error_msg_and_die("xstrndup bug"); | 85 | bb_error_msg_and_die("bb_xstrndup bug"); |
77 | 86 | ||
78 | t = xmalloc(++n); | 87 | t = xmalloc(++n); |
79 | 88 | ||
80 | return safe_strncpy(t,s,n); | 89 | return safe_strncpy(t,s,n); |
81 | } | 90 | } |
91 | #endif | ||
82 | 92 | ||
83 | FILE *xfopen(const char *path, const char *mode) | 93 | #ifdef L_xfopen |
94 | FILE *bb_xfopen(const char *path, const char *mode) | ||
84 | { | 95 | { |
85 | FILE *fp; | 96 | FILE *fp; |
86 | if ((fp = fopen(path, mode)) == NULL) | 97 | if ((fp = fopen(path, mode)) == NULL) |
87 | perror_msg_and_die("%s", path); | 98 | bb_perror_msg_and_die("%s", path); |
88 | return fp; | 99 | return fp; |
89 | } | 100 | } |
101 | #endif | ||
90 | 102 | ||
91 | extern int xopen(const char *pathname, int flags) | 103 | #ifdef L_xopen |
104 | extern int bb_xopen(const char *pathname, int flags) | ||
92 | { | 105 | { |
93 | int ret; | 106 | int ret; |
94 | 107 | ||
95 | ret = open(pathname, flags, 0777); | 108 | ret = open(pathname, flags, 0777); |
96 | if (ret == -1) { | 109 | if (ret == -1) { |
97 | perror_msg_and_die("%s", pathname); | 110 | bb_perror_msg_and_die("%s", pathname); |
98 | } | 111 | } |
99 | return ret; | 112 | return ret; |
100 | } | 113 | } |
114 | #endif | ||
101 | 115 | ||
102 | extern ssize_t xread(int fd, void *buf, size_t count) | 116 | #ifdef L_xread |
117 | extern ssize_t bb_xread(int fd, void *buf, size_t count) | ||
103 | { | 118 | { |
104 | ssize_t size; | 119 | ssize_t size; |
105 | 120 | ||
106 | size = read(fd, buf, count); | 121 | size = read(fd, buf, count); |
107 | if (size == -1) { | 122 | if (size == -1) { |
108 | perror_msg_and_die("Read error"); | 123 | bb_perror_msg_and_die("Read error"); |
109 | } | 124 | } |
110 | return(size); | 125 | return(size); |
111 | } | 126 | } |
127 | #endif | ||
112 | 128 | ||
113 | extern void xread_all(int fd, void *buf, size_t count) | 129 | #ifdef L_xread_all |
130 | extern void bb_xread_all(int fd, void *buf, size_t count) | ||
114 | { | 131 | { |
115 | ssize_t size; | 132 | ssize_t size; |
116 | 133 | ||
117 | size = xread(fd, buf, count); | 134 | while (count) { |
118 | if (size != count) { | 135 | if ((size = bb_xread(fd, buf, count)) == 0) { /* EOF */ |
119 | error_msg_and_die("Short read"); | 136 | bb_error_msg_and_die("Short read"); |
137 | } | ||
138 | count -= size; | ||
120 | } | 139 | } |
121 | return; | 140 | return; |
122 | } | 141 | } |
142 | #endif | ||
123 | 143 | ||
124 | extern unsigned char xread_char(int fd) | 144 | #ifdef L_xread_char |
145 | extern unsigned char bb_xread_char(int fd) | ||
125 | { | 146 | { |
126 | char tmp; | 147 | char tmp; |
127 | 148 | ||
128 | xread_all(fd, &tmp, 1); | 149 | bb_xread_all(fd, &tmp, 1); |
129 | 150 | ||
130 | return(tmp); | 151 | return(tmp); |
131 | } | 152 | } |
153 | #endif | ||
154 | |||
155 | #ifdef L_xferror | ||
156 | extern void bb_xferror(FILE *fp, const char *fn) | ||
157 | { | ||
158 | if (ferror(fp)) { | ||
159 | bb_error_msg_and_die("%s", fn); | ||
160 | } | ||
161 | } | ||
162 | #endif | ||
163 | |||
164 | #ifdef L_xferror_stdout | ||
165 | extern void bb_xferror_stdout(void) | ||
166 | { | ||
167 | bb_xferror(stdout, bb_msg_standard_output); | ||
168 | } | ||
169 | #endif | ||
170 | |||
171 | #ifdef L_xfflush_stdout | ||
172 | extern void bb_xfflush_stdout(void) | ||
173 | { | ||
174 | if (fflush(stdout)) { | ||
175 | bb_perror_msg_and_die(bb_msg_standard_output); | ||
176 | } | ||
177 | } | ||
178 | #endif | ||
132 | 179 | ||
180 | #ifdef L_strlen | ||
133 | /* Stupid gcc always includes its own builtin strlen()... */ | 181 | /* Stupid gcc always includes its own builtin strlen()... */ |
134 | #undef strlen | 182 | #undef strlen |
135 | size_t xstrlen(const char *string) | 183 | size_t bb_strlen(const char *string) |
136 | { | 184 | { |
137 | return(strlen(string)); | 185 | return(strlen(string)); |
138 | } | 186 | } |
187 | #endif | ||
139 | 188 | ||
140 | /* END CODE */ | 189 | /* END CODE */ |
141 | /* | 190 | /* |