diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 09:05:02 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 09:05:02 +0000 |
commit | dca0b707c0f0998670f8e69600cc30d94e9b217b (patch) | |
tree | bf0291a625fee415b6500007b0ec90880104f962 | |
parent | 621204bbf6750f1ba3977b43bb35375ddda6b5ae (diff) | |
download | busybox-w32-dca0b707c0f0998670f8e69600cc30d94e9b217b.tar.gz busybox-w32-dca0b707c0f0998670f8e69600cc30d94e9b217b.tar.bz2 busybox-w32-dca0b707c0f0998670f8e69600cc30d94e9b217b.zip |
reshuffle libbb.h contents so that order of decls makes sense
Found bad typo in largefile support :)
-rw-r--r-- | coreutils/df.c | 6 | ||||
-rw-r--r-- | coreutils/du.c | 6 | ||||
-rw-r--r-- | coreutils/mkdir.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 518 | ||||
-rw-r--r-- | init/init.c | 2 | ||||
-rw-r--r-- | libbb/human_readable.c | 9 |
6 files changed, 263 insertions, 280 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index c569dae33..6ae3eed33 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #ifndef CONFIG_FEATURE_HUMAN_READABLE | 29 | #ifndef CONFIG_FEATURE_HUMAN_READABLE |
30 | static long kscale(long b, long bs) | 30 | static long kscale(long b, long bs) |
31 | { | 31 | { |
32 | return ( b * (long long) bs + KILOBYTE/2 ) / KILOBYTE; | 32 | return ( b * (long long) bs + 1024/2 ) / 1024; |
33 | } | 33 | } |
34 | #endif | 34 | #endif |
35 | 35 | ||
@@ -38,7 +38,7 @@ int df_main(int argc, char **argv) | |||
38 | long blocks_used; | 38 | long blocks_used; |
39 | long blocks_percent_used; | 39 | long blocks_percent_used; |
40 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 40 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
41 | unsigned long df_disp_hr = KILOBYTE; | 41 | unsigned long df_disp_hr = 1024; |
42 | #endif | 42 | #endif |
43 | int status = EXIT_SUCCESS; | 43 | int status = EXIT_SUCCESS; |
44 | unsigned opt; | 44 | unsigned opt; |
@@ -56,7 +56,7 @@ int df_main(int argc, char **argv) | |||
56 | disp_units_hdr = " Size"; | 56 | disp_units_hdr = " Size"; |
57 | } | 57 | } |
58 | if (opt & 2) { | 58 | if (opt & 2) { |
59 | df_disp_hr = MEGABYTE; | 59 | df_disp_hr = 1024*1024; |
60 | disp_units_hdr = "1M-blocks"; | 60 | disp_units_hdr = "1M-blocks"; |
61 | } | 61 | } |
62 | #else | 62 | #else |
diff --git a/coreutils/du.c b/coreutils/du.c index cae76af38..a547b1e14 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 28 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
29 | # ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K | 29 | # ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
30 | static unsigned long disp_hr = KILOBYTE; | 30 | static unsigned long disp_hr = 1024; |
31 | # else | 31 | # else |
32 | static unsigned long disp_hr = 512; | 32 | static unsigned long disp_hr = 512; |
33 | # endif | 33 | # endif |
@@ -180,11 +180,11 @@ int du_main(int argc, char **argv) | |||
180 | } | 180 | } |
181 | if((opt & (1 << 10))) { | 181 | if((opt & (1 << 10))) { |
182 | /* -m opt */ | 182 | /* -m opt */ |
183 | disp_hr = MEGABYTE; | 183 | disp_hr = 1024*1024; |
184 | } | 184 | } |
185 | if((opt & (1 << 2))) { | 185 | if((opt & (1 << 2))) { |
186 | /* -k opt */ | 186 | /* -k opt */ |
187 | disp_hr = KILOBYTE; | 187 | disp_hr = 1024; |
188 | } | 188 | } |
189 | #else | 189 | #else |
190 | opt_complementary = "H-L:L-H:s-d:d-s"; | 190 | opt_complementary = "H-L:L-H:s-d:d-s"; |
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index 3fe55c395..1aee8b2b5 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c | |||
@@ -42,7 +42,7 @@ int mkdir_main (int argc, char **argv) | |||
42 | #endif | 42 | #endif |
43 | opt = getopt32(argc, argv, "m:p", &smode); | 43 | opt = getopt32(argc, argv, "m:p", &smode); |
44 | if(opt & 1) { | 44 | if(opt & 1) { |
45 | mode = 0777; | 45 | mode = 0777; |
46 | if (!bb_parse_mode (smode, &mode)) { | 46 | if (!bb_parse_mode (smode, &mode)) { |
47 | bb_error_msg_and_die ("invalid mode `%s'", smode); | 47 | bb_error_msg_and_die ("invalid mode `%s'", smode); |
48 | } | 48 | } |
diff --git a/include/libbb.h b/include/libbb.h index 234ba122f..169964ba3 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -10,7 +10,6 @@ | |||
10 | #ifndef __LIBBUSYBOX_H__ | 10 | #ifndef __LIBBUSYBOX_H__ |
11 | #define __LIBBUSYBOX_H__ 1 | 11 | #define __LIBBUSYBOX_H__ 1 |
12 | 12 | ||
13 | //Ok to remove? #include "bb_config.h" | ||
14 | #include "platform.h" | 13 | #include "platform.h" |
15 | 14 | ||
16 | #include <ctype.h> | 15 | #include <ctype.h> |
@@ -83,7 +82,7 @@ | |||
83 | * (in today's world - signed 64bit). For full support of large files, | 82 | * (in today's world - signed 64bit). For full support of large files, |
84 | * we need a few helper #defines (below) and careful use of off_t | 83 | * we need a few helper #defines (below) and careful use of off_t |
85 | * instead of int/ssize_t. No lseek64(), O_LARGEFILE etc necessary */ | 84 | * instead of int/ssize_t. No lseek64(), O_LARGEFILE etc necessary */ |
86 | #if ENBALE_LFS | 85 | #if ENABLE_LFS |
87 | /* CONFIG_LFS is on */ | 86 | /* CONFIG_LFS is on */ |
88 | # if ULONG_MAX > 0xffffffff | 87 | # if ULONG_MAX > 0xffffffff |
89 | /* "long" is long enough on this system */ | 88 | /* "long" is long enough on this system */ |
@@ -158,93 +157,107 @@ | |||
158 | #endif | 157 | #endif |
159 | 158 | ||
160 | 159 | ||
161 | typedef struct llist_s { | 160 | #if (__GLIBC__ < 2) |
162 | char *data; | 161 | int vdprintf(int d, const char *format, va_list ap); |
163 | struct llist_s *link; | 162 | #endif |
164 | } llist_t; | 163 | // This is declared here rather than #including <libgen.h> in order to avoid |
165 | extern void llist_add_to(llist_t **old_head, void *data); | 164 | // confusing the two versions of basename. See the dirname/basename man page |
166 | extern void llist_add_to_end(llist_t **list_head, void *data); | 165 | // for details. |
167 | extern void *llist_pop(llist_t **elm); | 166 | char *dirname(char *path); |
168 | extern void llist_free(llist_t *elm, void (*freeit)(void *data)); | 167 | /* Include our own copy of struct sysinfo to avoid binary compatibility |
169 | extern llist_t* rev_llist(llist_t *list); | 168 | * problems with Linux 2.4, which changed things. Grumble, grumble. */ |
170 | 169 | struct sysinfo { | |
171 | enum { | 170 | long uptime; /* Seconds since boot */ |
172 | LOGMODE_NONE = 0, | 171 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ |
173 | LOGMODE_STDIO = 1<<0, | 172 | unsigned long totalram; /* Total usable main memory size */ |
174 | LOGMODE_SYSLOG = 1<<1, | 173 | unsigned long freeram; /* Available memory size */ |
175 | LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO, | 174 | unsigned long sharedram; /* Amount of shared memory */ |
175 | unsigned long bufferram; /* Memory used by buffers */ | ||
176 | unsigned long totalswap; /* Total swap space size */ | ||
177 | unsigned long freeswap; /* swap space still available */ | ||
178 | unsigned short procs; /* Number of current processes */ | ||
179 | unsigned short pad; /* Padding needed for m68k */ | ||
180 | unsigned long totalhigh; /* Total high memory size */ | ||
181 | unsigned long freehigh; /* Available high memory size */ | ||
182 | unsigned int mem_unit; /* Memory unit size in bytes */ | ||
183 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ | ||
176 | }; | 184 | }; |
177 | extern const char *msg_eol; | 185 | extern int sysinfo(struct sysinfo* info); |
178 | extern int logmode; | ||
179 | extern int die_sleep; | ||
180 | |||
181 | extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; | ||
182 | extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
183 | extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
184 | extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
185 | extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
186 | extern void bb_vherror_msg(const char *s, va_list p); | ||
187 | extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
188 | extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
189 | 186 | ||
190 | extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN; | ||
191 | extern void bb_perror_nomsg(void); | ||
192 | |||
193 | extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
194 | 187 | ||
195 | /* These two are used internally -- you shouldn't need to use them */ | 188 | extern void chomp(char *s); |
196 | extern void bb_verror_msg(const char *s, va_list p, const char *strerr) __attribute__ ((format (printf, 1, 0))); | 189 | extern void trim(char *s); |
197 | extern void bb_vperror_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0))); | 190 | extern char *skip_whitespace(const char *); |
198 | extern void bb_vinfo_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0))); | ||
199 | |||
200 | extern int bb_echo(int argc, char** argv); | ||
201 | extern int bb_test(int argc, char** argv); | ||
202 | 191 | ||
203 | extern const char *bb_mode_string(int mode); | 192 | extern const char *bb_mode_string(int mode); |
204 | extern int is_directory(const char *name, int followLinks, struct stat *statBuf); | 193 | extern int is_directory(const char *name, int followLinks, struct stat *statBuf); |
205 | extern DIR *warn_opendir(const char *path); | ||
206 | extern DIR *xopendir(const char *path); | ||
207 | |||
208 | extern ssize_t safe_read(int fd, void *buf, size_t count); | ||
209 | extern ssize_t full_read(int fd, void *buf, size_t count); | ||
210 | extern void xread(int fd, void *buf, size_t count); | ||
211 | extern unsigned char xread_char(int fd); | ||
212 | extern char *reads(int fd, char *buf, size_t count); | ||
213 | ssize_t read_close(int fd, void *buf, size_t count); | ||
214 | ssize_t open_read_close(const char *filename, void *buf, size_t count); | ||
215 | void *xmalloc_open_read_close(const char *filename, size_t *sizep); | ||
216 | |||
217 | extern ssize_t safe_write(int fd, const void *buf, size_t count); | ||
218 | extern ssize_t full_write(int fd, const void *buf, size_t count); | ||
219 | extern void xwrite(int fd, void *buf, size_t count); | ||
220 | |||
221 | extern int remove_file(const char *path, int flags); | 194 | extern int remove_file(const char *path, int flags); |
222 | extern int copy_file(const char *source, const char *dest, int flags); | 195 | extern int copy_file(const char *source, const char *dest, int flags); |
223 | |||
224 | extern int recursive_action(const char *fileName, int recurse, | 196 | extern int recursive_action(const char *fileName, int recurse, |
225 | int followLinks, int depthFirst, | 197 | int followLinks, int depthFirst, |
226 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData), | 198 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData), |
227 | int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData), | 199 | int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData), |
228 | void* userData); | 200 | void* userData); |
229 | 201 | extern int device_open(const char *device, int mode); | |
230 | extern int bb_parse_mode(const char* s, mode_t* theMode); | ||
231 | |||
232 | extern unsigned int tty_baud_to_value(speed_t speed); | ||
233 | extern speed_t tty_value_to_baud(unsigned int value); | ||
234 | |||
235 | extern int get_linux_version_code(void); | ||
236 | |||
237 | extern int get_console_fd(void); | 202 | extern int get_console_fd(void); |
238 | extern struct mntent *find_mount_point(const char *name, const char *table); | ||
239 | extern void erase_mtab(const char * name); | ||
240 | extern long *find_pid_by_name( const char* pidName); | ||
241 | extern long *pidlist_reverse(long *pidList); | ||
242 | extern char *find_block_device(char *path); | 203 | extern char *find_block_device(char *path); |
243 | extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); | 204 | extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); |
244 | extern off_t bb_copyfd_eof(int fd1, int fd2); | 205 | extern off_t bb_copyfd_eof(int fd1, int fd2); |
245 | extern char bb_process_escape_sequence(const char **ptr); | 206 | extern char bb_process_escape_sequence(const char **ptr); |
246 | extern char *bb_get_last_path_component(char *path); | 207 | extern char *bb_get_last_path_component(char *path); |
247 | 208 | ||
209 | |||
210 | extern DIR *xopendir(const char *path); | ||
211 | extern DIR *warn_opendir(const char *path); | ||
212 | |||
213 | char *xgetcwd(char *cwd); | ||
214 | char *xreadlink(const char *path); | ||
215 | extern void xstat(char *filename, struct stat *buf); | ||
216 | extern pid_t spawn(char **argv); | ||
217 | extern pid_t xspawn(char **argv); | ||
218 | extern int wait4pid(int pid); | ||
219 | extern void xsetgid(gid_t gid); | ||
220 | extern void xsetuid(uid_t uid); | ||
221 | extern void xdaemon(int nochdir, int noclose); | ||
222 | extern void xchdir(const char *path); | ||
223 | extern void xsetenv(const char *key, const char *value); | ||
224 | extern int xopen(const char *pathname, int flags); | ||
225 | extern int xopen3(const char *pathname, int flags, int mode); | ||
226 | extern off_t xlseek(int fd, off_t offset, int whence); | ||
227 | extern off_t fdlength(int fd); | ||
228 | |||
229 | extern int xsocket(int domain, int type, int protocol); | ||
230 | extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); | ||
231 | extern void xlisten(int s, int backlog); | ||
232 | extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen); | ||
233 | extern int xconnect_tcp_v4(struct sockaddr_in *s_addr); | ||
234 | extern struct hostent *xgethostbyname(const char *name); | ||
235 | extern struct hostent *xgethostbyname2(const char *name, int af); | ||
236 | |||
237 | extern char *xstrdup(const char *s); | ||
238 | extern char *xstrndup(const char *s, int n); | ||
239 | extern char *safe_strncpy(char *dst, const char *src, size_t size); | ||
240 | extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); | ||
241 | |||
242 | /* dmalloc will redefine these to it's own implementation. It is safe | ||
243 | * to have the prototypes here unconditionally. */ | ||
244 | extern void *xmalloc(size_t size); | ||
245 | extern void *xrealloc(void *old, size_t size); | ||
246 | extern void *xzalloc(size_t size); | ||
247 | |||
248 | extern ssize_t safe_read(int fd, void *buf, size_t count); | ||
249 | extern ssize_t full_read(int fd, void *buf, size_t count); | ||
250 | extern void xread(int fd, void *buf, size_t count); | ||
251 | extern unsigned char xread_char(int fd); | ||
252 | extern char *reads(int fd, char *buf, size_t count); | ||
253 | extern ssize_t read_close(int fd, void *buf, size_t count); | ||
254 | extern ssize_t open_read_close(const char *filename, void *buf, size_t count); | ||
255 | extern void *xmalloc_open_read_close(const char *filename, size_t *sizep); | ||
256 | |||
257 | extern ssize_t safe_write(int fd, const void *buf, size_t count); | ||
258 | extern ssize_t full_write(int fd, const void *buf, size_t count); | ||
259 | extern void xwrite(int fd, void *buf, size_t count); | ||
260 | |||
248 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ | 261 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ |
249 | extern void xprint_and_close_file(FILE *file); | 262 | extern void xprint_and_close_file(FILE *file); |
250 | extern char *xmalloc_fgets(FILE *file); | 263 | extern char *xmalloc_fgets(FILE *file); |
@@ -264,49 +277,12 @@ extern FILE *fopen_or_warn(const char *filename, const char *mode); | |||
264 | /* "Opens" stdin if filename is special, else just opens file: */ | 277 | /* "Opens" stdin if filename is special, else just opens file: */ |
265 | extern FILE *fopen_or_warn_stdin(const char *filename); | 278 | extern FILE *fopen_or_warn_stdin(const char *filename); |
266 | 279 | ||
267 | extern void xstat(char *filename, struct stat *buf); | 280 | |
268 | extern int xsocket(int domain, int type, int protocol); | ||
269 | extern pid_t spawn(char **argv); | ||
270 | extern pid_t xspawn(char **argv); | ||
271 | extern int wait4pid(int pid); | ||
272 | extern void xdaemon(int nochdir, int noclose); | ||
273 | extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); | ||
274 | extern void xlisten(int s, int backlog); | ||
275 | extern void xchdir(const char *path); | ||
276 | extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen); | 281 | extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen); |
277 | extern char *utoa(unsigned n); | 282 | extern char *utoa(unsigned n); |
278 | extern void itoa_to_buf(int n, char *buf, unsigned buflen); | 283 | extern void itoa_to_buf(int n, char *buf, unsigned buflen); |
279 | extern char *itoa(int n); | 284 | extern char *itoa(int n); |
280 | extern void xsetgid(gid_t gid); | ||
281 | extern void xsetuid(uid_t uid); | ||
282 | extern off_t fdlength(int fd); | ||
283 | |||
284 | enum { BB_GETOPT_ERROR = 0x80000000 }; | ||
285 | extern const char *opt_complementary; | ||
286 | extern const struct option *applet_long_options; | ||
287 | extern uint32_t option_mask32; | ||
288 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); | ||
289 | |||
290 | extern void bb_warn_ignoring_args(int n); | ||
291 | |||
292 | extern void chomp(char *s); | ||
293 | extern void trim(char *s); | ||
294 | extern char *skip_whitespace(const char *); | ||
295 | 285 | ||
296 | #ifndef BUILD_INDIVIDUAL | ||
297 | extern struct BB_applet *find_applet_by_name(const char *name); | ||
298 | extern void run_applet_by_name(const char *name, int argc, char **argv); | ||
299 | #endif | ||
300 | |||
301 | /* dmalloc will redefine these to it's own implementation. It is safe | ||
302 | * to have the prototypes here unconditionally. */ | ||
303 | extern void *xmalloc(size_t size); | ||
304 | extern void *xrealloc(void *old, size_t size); | ||
305 | extern void *xzalloc(size_t size); | ||
306 | |||
307 | extern char *xstrdup(const char *s); | ||
308 | extern char *xstrndup(const char *s, int n); | ||
309 | extern char *safe_strncpy(char *dst, const char *src, size_t size); | ||
310 | // FIXME: the prototype doesn't match libc strtoXX -> confusion | 286 | // FIXME: the prototype doesn't match libc strtoXX -> confusion |
311 | // FIXME: alot of unchecked strtoXXX are still in tree | 287 | // FIXME: alot of unchecked strtoXXX are still in tree |
312 | // FIXME: atoi_or_else(str, N)? | 288 | // FIXME: atoi_or_else(str, N)? |
@@ -321,9 +297,8 @@ extern int safe_strtou32(const char *arg, uint32_t* value); | |||
321 | 297 | ||
322 | struct suffix_mult { | 298 | struct suffix_mult { |
323 | const char *suffix; | 299 | const char *suffix; |
324 | unsigned int mult; | 300 | unsigned mult; |
325 | }; | 301 | }; |
326 | |||
327 | unsigned long long xstrtoull(const char *numstr, int base); | 302 | unsigned long long xstrtoull(const char *numstr, int base); |
328 | unsigned long long xatoull(const char *numstr); | 303 | unsigned long long xatoull(const char *numstr); |
329 | unsigned long xstrtoul_range_sfx(const char *numstr, int base, | 304 | unsigned long xstrtoul_range_sfx(const char *numstr, int base, |
@@ -371,6 +346,7 @@ uint32_t xatou32(const char *numstr); | |||
371 | /* Useful for reading port numbers */ | 346 | /* Useful for reading port numbers */ |
372 | uint16_t xatou16(const char *numstr); | 347 | uint16_t xatou16(const char *numstr); |
373 | 348 | ||
349 | |||
374 | /* These parse entries in /etc/passwd and /etc/group. This is desirable | 350 | /* These parse entries in /etc/passwd and /etc/group. This is desirable |
375 | * for BusyBox since we want to avoid using the glibc NSS stuff, which | 351 | * for BusyBox since we want to avoid using the glibc NSS stuff, which |
376 | * increases target size and is often not needed on embedded systems. */ | 352 | * increases target size and is often not needed on embedded systems. */ |
@@ -379,7 +355,6 @@ extern long bb_xgetgrnam(const char *name); | |||
379 | extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix); | 355 | extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix); |
380 | extern char *bb_getpwuid(char *name, long uid, int bufsize); | 356 | extern char *bb_getpwuid(char *name, long uid, int bufsize); |
381 | extern char *bb_getgrgid(char *group, long gid, int bufsize); | 357 | extern char *bb_getgrgid(char *group, long gid, int bufsize); |
382 | extern char *bb_askpass(int timeout, const char * prompt); | ||
383 | /* from chpst */ | 358 | /* from chpst */ |
384 | struct bb_uidgid_t { | 359 | struct bb_uidgid_t { |
385 | uid_t uid; | 360 | uid_t uid; |
@@ -388,49 +363,80 @@ struct bb_uidgid_t { | |||
388 | extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/); | 363 | extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/); |
389 | 364 | ||
390 | 365 | ||
391 | extern int device_open(const char *device, int mode); | 366 | enum { BB_GETOPT_ERROR = 0x80000000 }; |
367 | extern const char *opt_complementary; | ||
368 | extern const struct option *applet_long_options; | ||
369 | extern uint32_t option_mask32; | ||
370 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); | ||
371 | |||
372 | |||
373 | typedef struct llist_s { | ||
374 | char *data; | ||
375 | struct llist_s *link; | ||
376 | } llist_t; | ||
377 | extern void llist_add_to(llist_t **old_head, void *data); | ||
378 | extern void llist_add_to_end(llist_t **list_head, void *data); | ||
379 | extern void *llist_pop(llist_t **elm); | ||
380 | extern void llist_free(llist_t *elm, void (*freeit)(void *data)); | ||
381 | extern llist_t* rev_llist(llist_t *list); | ||
382 | |||
383 | enum { | ||
384 | LOGMODE_NONE = 0, | ||
385 | LOGMODE_STDIO = 1<<0, | ||
386 | LOGMODE_SYSLOG = 1<<1, | ||
387 | LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO, | ||
388 | }; | ||
389 | extern const char *msg_eol; | ||
390 | extern int logmode; | ||
391 | extern int die_sleep; | ||
392 | extern int xfunc_error_retval; | ||
393 | extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; | ||
394 | extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
395 | extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
396 | extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
397 | extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
398 | extern void bb_vherror_msg(const char *s, va_list p); | ||
399 | extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
400 | extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
401 | extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN; | ||
402 | extern void bb_perror_nomsg(void); | ||
403 | extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | ||
404 | /* These two are used internally -- you shouldn't need to use them */ | ||
405 | extern void bb_verror_msg(const char *s, va_list p, const char *strerr); | ||
406 | extern void bb_vperror_msg(const char *s, va_list p); | ||
407 | extern void bb_vinfo_msg(const char *s, va_list p); | ||
408 | |||
409 | |||
410 | extern int bb_echo(int argc, char** argv); | ||
411 | extern int bb_test(int argc, char** argv); | ||
412 | |||
413 | #ifndef BUILD_INDIVIDUAL | ||
414 | extern struct BB_applet *find_applet_by_name(const char *name); | ||
415 | extern void run_applet_by_name(const char *name, int argc, char **argv); | ||
416 | #endif | ||
417 | |||
418 | extern struct mntent *find_mount_point(const char *name, const char *table); | ||
419 | extern void erase_mtab(const char * name); | ||
420 | extern unsigned int tty_baud_to_value(speed_t speed); | ||
421 | extern speed_t tty_value_to_baud(unsigned int value); | ||
422 | extern void bb_warn_ignoring_args(int n); | ||
423 | |||
424 | extern int get_linux_version_code(void); | ||
392 | 425 | ||
393 | extern char *query_loop(const char *device); | 426 | extern char *query_loop(const char *device); |
394 | extern int del_loop(const char *device); | 427 | extern int del_loop(const char *device); |
395 | extern int set_loop(char **device, const char *file, unsigned long long offset); | 428 | extern int set_loop(char **device, const char *file, unsigned long long offset); |
396 | 429 | ||
397 | #if (__GLIBC__ < 2) | ||
398 | extern int vdprintf(int d, const char *format, va_list ap); | ||
399 | #endif | ||
400 | 430 | ||
401 | /* Include our own copy of struct sysinfo to avoid binary compatibility | ||
402 | * problems with Linux 2.4, which changed things. Grumble, grumble. */ | ||
403 | struct sysinfo { | ||
404 | long uptime; /* Seconds since boot */ | ||
405 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ | ||
406 | unsigned long totalram; /* Total usable main memory size */ | ||
407 | unsigned long freeram; /* Available memory size */ | ||
408 | unsigned long sharedram; /* Amount of shared memory */ | ||
409 | unsigned long bufferram; /* Memory used by buffers */ | ||
410 | unsigned long totalswap; /* Total swap space size */ | ||
411 | unsigned long freeswap; /* swap space still available */ | ||
412 | unsigned short procs; /* Number of current processes */ | ||
413 | unsigned short pad; /* Padding needed for m68k */ | ||
414 | unsigned long totalhigh; /* Total high memory size */ | ||
415 | unsigned long freehigh; /* Available high memory size */ | ||
416 | unsigned int mem_unit; /* Memory unit size in bytes */ | ||
417 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ | ||
418 | }; | ||
419 | extern int sysinfo (struct sysinfo* info); | ||
420 | |||
421 | enum { | ||
422 | KILOBYTE = 1024, | ||
423 | MEGABYTE = (KILOBYTE*1024), | ||
424 | GIGABYTE = (MEGABYTE*1024) | ||
425 | }; | ||
426 | const char *make_human_readable_str(unsigned long long size, | 431 | const char *make_human_readable_str(unsigned long long size, |
427 | unsigned long block_size, unsigned long display_unit); | 432 | unsigned long block_size, unsigned long display_unit); |
428 | 433 | ||
434 | char *bb_askpass(int timeout, const char * prompt); | ||
429 | int bb_ask_confirmation(void); | 435 | int bb_ask_confirmation(void); |
430 | int klogctl(int type, char * b, int len); | 436 | int klogctl(int type, char * b, int len); |
431 | 437 | ||
432 | char *xgetcwd(char *cwd); | 438 | extern int bb_parse_mode(const char* s, mode_t* theMode); |
433 | char *xreadlink(const char *path); | 439 | |
434 | char *concat_path_file(const char *path, const char *filename); | 440 | char *concat_path_file(const char *path, const char *filename); |
435 | char *concat_subpath_file(const char *path, const char *filename); | 441 | char *concat_subpath_file(const char *path, const char *filename); |
436 | char *last_char_is(const char *s, int c); | 442 | char *last_char_is(const char *s, int c); |
@@ -439,23 +445,14 @@ int execable_file(const char *name); | |||
439 | char *find_execable(const char *filename); | 445 | char *find_execable(const char *filename); |
440 | int exists_execable(const char *filename); | 446 | int exists_execable(const char *filename); |
441 | 447 | ||
442 | extern USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out); | 448 | USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out); |
443 | extern int inflate(int in, int out); | 449 | int inflate(int in, int out); |
444 | 450 | ||
445 | extern struct hostent *xgethostbyname(const char *name); | 451 | int create_icmp_socket(void); |
446 | extern struct hostent *xgethostbyname2(const char *name, int af); | 452 | int create_icmp6_socket(void); |
447 | extern int create_icmp_socket(void); | ||
448 | extern int create_icmp6_socket(void); | ||
449 | extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen); | ||
450 | extern int xconnect_tcp_v4(struct sockaddr_in *s_addr); | ||
451 | |||
452 | extern unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port); | ||
453 | extern void bb_lookup_host(struct sockaddr_in *s_in, const char *host); | ||
454 | 453 | ||
455 | // This is declared here rather than #including <libgen.h> in order to avoid | 454 | unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port); |
456 | // confusing the two versions of basename. See the dirname/basename man page | 455 | void bb_lookup_host(struct sockaddr_in *s_in, const char *host); |
457 | // for details. | ||
458 | char *dirname(char *path); | ||
459 | 456 | ||
460 | int bb_make_directory(char *path, long mode, int flags); | 457 | int bb_make_directory(char *path, long mode, int flags); |
461 | 458 | ||
@@ -464,6 +461,96 @@ const char *get_signame(int number); | |||
464 | 461 | ||
465 | char *bb_simplify_path(const char *path); | 462 | char *bb_simplify_path(const char *path); |
466 | 463 | ||
464 | #define FAIL_DELAY 3 | ||
465 | extern void bb_do_delay(int seconds); | ||
466 | extern void change_identity(const struct passwd *pw); | ||
467 | extern const char *change_identity_e2str(const struct passwd *pw); | ||
468 | extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args); | ||
469 | #ifdef CONFIG_SELINUX | ||
470 | extern void renew_current_security_context(void); | ||
471 | extern void set_current_security_context(security_context_t sid); | ||
472 | #endif | ||
473 | extern int run_parts(char **args, const unsigned char test_mode, char **env); | ||
474 | extern int restricted_shell(const char *shell); | ||
475 | extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); | ||
476 | extern int correct_password(const struct passwd *pw); | ||
477 | extern char *pw_encrypt(const char *clear, const char *salt); | ||
478 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); | ||
479 | extern int compare_string_array(const char * const string_array[], const char *key); | ||
480 | extern void print_login_issue(const char *issue_file, const char *tty); | ||
481 | extern void print_login_prompt(void); | ||
482 | #ifdef BB_NOMMU | ||
483 | extern void vfork_daemon(int nochdir, int noclose); | ||
484 | extern void vfork_daemon_rexec(int nochdir, int noclose, | ||
485 | int argc, char **argv, char *foreground_opt); | ||
486 | #endif | ||
487 | extern int get_terminal_width_height(int fd, int *width, int *height); | ||
488 | extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *)); | ||
489 | |||
490 | int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name); | ||
491 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); | ||
492 | void reset_ino_dev_hashtable(void); | ||
493 | |||
494 | |||
495 | #ifndef COMM_LEN | ||
496 | #ifdef TASK_COMM_LEN | ||
497 | #define COMM_LEN TASK_COMM_LEN | ||
498 | #else | ||
499 | /* synchronize with sizeof(task_struct.comm) in /usr/include/linux/sched.h */ | ||
500 | #define COMM_LEN 16 | ||
501 | #endif | ||
502 | #endif | ||
503 | typedef struct { | ||
504 | int pid; | ||
505 | char user[9]; | ||
506 | char state[4]; | ||
507 | unsigned long rss; | ||
508 | int ppid; | ||
509 | #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE | ||
510 | unsigned pcpu; | ||
511 | unsigned pscpu; | ||
512 | unsigned long stime, utime; | ||
513 | #endif | ||
514 | char *cmd; | ||
515 | |||
516 | /* basename of executable file in call to exec(2), | ||
517 | size from kernel headers */ | ||
518 | char short_cmd[COMM_LEN]; | ||
519 | } procps_status_t; | ||
520 | procps_status_t* procps_scan(int save_user_arg0); | ||
521 | long *find_pid_by_name( const char* pidName); | ||
522 | long *pidlist_reverse(long *pidList); | ||
523 | |||
524 | |||
525 | extern const char bb_uuenc_tbl_base64[]; | ||
526 | extern const char bb_uuenc_tbl_std[]; | ||
527 | void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl); | ||
528 | |||
529 | typedef struct _sha1_ctx_t_ { | ||
530 | uint32_t count[2]; | ||
531 | uint32_t hash[5]; | ||
532 | uint32_t wbuf[16]; | ||
533 | } sha1_ctx_t; | ||
534 | void sha1_begin(sha1_ctx_t *ctx); | ||
535 | void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx); | ||
536 | void *sha1_end(void *resbuf, sha1_ctx_t *ctx); | ||
537 | |||
538 | typedef struct _md5_ctx_t_ { | ||
539 | uint32_t A; | ||
540 | uint32_t B; | ||
541 | uint32_t C; | ||
542 | uint32_t D; | ||
543 | uint64_t total; | ||
544 | uint32_t buflen; | ||
545 | char buffer[128]; | ||
546 | } md5_ctx_t; | ||
547 | void md5_begin(md5_ctx_t *ctx); | ||
548 | void md5_hash(const void *data, size_t length, md5_ctx_t *ctx); | ||
549 | void *md5_end(void *resbuf, md5_ctx_t *ctx); | ||
550 | |||
551 | uint32_t *crc32_filltable(int endian); | ||
552 | |||
553 | |||
467 | enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ | 554 | enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ |
468 | FILEUTILS_PRESERVE_STATUS = 1, | 555 | FILEUTILS_PRESERVE_STATUS = 1, |
469 | FILEUTILS_DEREFERENCE = 2, | 556 | FILEUTILS_DEREFERENCE = 2, |
@@ -476,6 +563,7 @@ enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ | |||
476 | #define FILEUTILS_CP_OPTSTR "pdRfils" | 563 | #define FILEUTILS_CP_OPTSTR "pdRfils" |
477 | 564 | ||
478 | extern const char *applet_name; | 565 | extern const char *applet_name; |
566 | extern const char BB_BANNER[]; | ||
479 | 567 | ||
480 | extern const char bb_msg_full_version[]; | 568 | extern const char bb_msg_full_version[]; |
481 | extern const char bb_msg_memory_exhausted[]; | 569 | extern const char bb_msg_memory_exhausted[]; |
@@ -491,6 +579,7 @@ extern const char bb_msg_invalid_arg[]; | |||
491 | extern const char bb_msg_standard_input[]; | 579 | extern const char bb_msg_standard_input[]; |
492 | extern const char bb_msg_standard_output[]; | 580 | extern const char bb_msg_standard_output[]; |
493 | 581 | ||
582 | extern const char bb_path_mtab_file[]; | ||
494 | extern const char bb_path_nologin_file[]; | 583 | extern const char bb_path_nologin_file[]; |
495 | extern const char bb_path_passwd_file[]; | 584 | extern const char bb_path_passwd_file[]; |
496 | extern const char bb_path_shadow_file[]; | 585 | extern const char bb_path_shadow_file[]; |
@@ -506,14 +595,11 @@ extern const char bb_dev_null[]; | |||
506 | #endif | 595 | #endif |
507 | extern char bb_common_bufsiz1[BUFSIZ+1]; | 596 | extern char bb_common_bufsiz1[BUFSIZ+1]; |
508 | 597 | ||
509 | /* | 598 | /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, |
510 | * You can change LIBBB_DEFAULT_LOGIN_SHELL, but don`t use, | 599 | * use bb_default_login_shell and following defines. |
511 | * use bb_default_login_shell and next defines, | 600 | * If you change LIBBB_DEFAULT_LOGIN_SHELL, |
512 | * if you LIBBB_DEFAULT_LOGIN_SHELL change, | 601 | * don't forget to change increment constant. */ |
513 | * don`t lose change increment constant! | ||
514 | */ | ||
515 | #define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" | 602 | #define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" |
516 | |||
517 | extern const char bb_default_login_shell[]; | 603 | extern const char bb_default_login_shell[]; |
518 | /* "/bin/sh" */ | 604 | /* "/bin/sh" */ |
519 | #define DEFAULT_SHELL (bb_default_login_shell+1) | 605 | #define DEFAULT_SHELL (bb_default_login_shell+1) |
@@ -521,10 +607,6 @@ extern const char bb_default_login_shell[]; | |||
521 | #define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) | 607 | #define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) |
522 | 608 | ||
523 | 609 | ||
524 | extern const char bb_path_mtab_file[]; | ||
525 | |||
526 | extern int xfunc_error_retval; | ||
527 | |||
528 | #ifdef CONFIG_FEATURE_DEVFS | 610 | #ifdef CONFIG_FEATURE_DEVFS |
529 | # define CURRENT_VC "/dev/vc/0" | 611 | # define CURRENT_VC "/dev/vc/0" |
530 | # define VC_1 "/dev/vc/1" | 612 | # define VC_1 "/dev/vc/1" |
@@ -570,116 +652,16 @@ extern int xfunc_error_retval; | |||
570 | # define FB_0 "/dev/fb0" | 652 | # define FB_0 "/dev/fb0" |
571 | #endif | 653 | #endif |
572 | 654 | ||
573 | |||
574 | /* The following devices are the same on devfs and non-devfs systems. */ | 655 | /* The following devices are the same on devfs and non-devfs systems. */ |
575 | #define CURRENT_TTY "/dev/tty" | 656 | #define CURRENT_TTY "/dev/tty" |
576 | #define CONSOLE_DEV "/dev/console" | 657 | #define CONSOLE_DEV "/dev/console" |
577 | 658 | ||
578 | int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name); | ||
579 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); | ||
580 | void reset_ino_dev_hashtable(void); | ||
581 | |||
582 | char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); | ||
583 | |||
584 | #define FAIL_DELAY 3 | ||
585 | extern void bb_do_delay(int seconds); | ||
586 | extern void change_identity(const struct passwd *pw); | ||
587 | extern const char *change_identity_e2str(const struct passwd *pw); | ||
588 | extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args); | ||
589 | #ifdef CONFIG_SELINUX | ||
590 | extern void renew_current_security_context(void); | ||
591 | extern void set_current_security_context(security_context_t sid); | ||
592 | #endif | ||
593 | extern int run_parts(char **args, const unsigned char test_mode, char **env); | ||
594 | extern int restricted_shell(const char *shell); | ||
595 | extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); | ||
596 | extern int correct_password(const struct passwd *pw); | ||
597 | extern char *pw_encrypt(const char *clear, const char *salt); | ||
598 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); | ||
599 | |||
600 | extern void xsetenv(const char *key, const char *value); | ||
601 | extern int xopen(const char *pathname, int flags); | ||
602 | extern int xopen3(const char *pathname, int flags, int mode); | ||
603 | extern off_t xlseek(int fd, off_t offset, int whence); | ||
604 | |||
605 | extern const char bb_uuenc_tbl_base64[]; | ||
606 | extern const char bb_uuenc_tbl_std[]; | ||
607 | extern void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl); | ||
608 | |||
609 | #ifndef COMM_LEN | ||
610 | #ifdef TASK_COMM_LEN | ||
611 | #define COMM_LEN TASK_COMM_LEN | ||
612 | #else | ||
613 | /* synchronize with sizeof(task_struct.comm) in /usr/include/linux/sched.h */ | ||
614 | #define COMM_LEN 16 | ||
615 | #endif | ||
616 | #endif | ||
617 | typedef struct { | ||
618 | int pid; | ||
619 | char user[9]; | ||
620 | char state[4]; | ||
621 | unsigned long rss; | ||
622 | int ppid; | ||
623 | #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE | ||
624 | unsigned pcpu; | ||
625 | unsigned pscpu; | ||
626 | unsigned long stime, utime; | ||
627 | #endif | ||
628 | char *cmd; | ||
629 | |||
630 | /* basename of executable file in call to exec(2), | ||
631 | size from kernel headers */ | ||
632 | char short_cmd[COMM_LEN]; | ||
633 | } procps_status_t; | ||
634 | |||
635 | extern procps_status_t * procps_scan(int save_user_arg0); | ||
636 | extern int compare_string_array(const char * const string_array[], const char *key); | ||
637 | |||
638 | extern void print_login_issue(const char *issue_file, const char *tty); | ||
639 | extern void print_login_prompt(void); | ||
640 | |||
641 | #ifdef BB_NOMMU | ||
642 | extern void vfork_daemon(int nochdir, int noclose); | ||
643 | extern void vfork_daemon_rexec(int nochdir, int noclose, | ||
644 | int argc, char **argv, char *foreground_opt); | ||
645 | #endif | ||
646 | |||
647 | extern int get_terminal_width_height(int fd, int *width, int *height); | ||
648 | extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *)); | ||
649 | |||
650 | typedef struct _sha1_ctx_t_ { | ||
651 | uint32_t count[2]; | ||
652 | uint32_t hash[5]; | ||
653 | uint32_t wbuf[16]; | ||
654 | } sha1_ctx_t; | ||
655 | |||
656 | void sha1_begin(sha1_ctx_t *ctx); | ||
657 | void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx); | ||
658 | void *sha1_end(void *resbuf, sha1_ctx_t *ctx); | ||
659 | |||
660 | typedef struct _md5_ctx_t_ { | ||
661 | uint32_t A; | ||
662 | uint32_t B; | ||
663 | uint32_t C; | ||
664 | uint32_t D; | ||
665 | uint64_t total; | ||
666 | uint32_t buflen; | ||
667 | char buffer[128]; | ||
668 | } md5_ctx_t; | ||
669 | |||
670 | void md5_begin(md5_ctx_t *ctx); | ||
671 | void md5_hash(const void *data, size_t length, md5_ctx_t *ctx); | ||
672 | void *md5_end(void *resbuf, md5_ctx_t *ctx); | ||
673 | |||
674 | extern uint32_t *crc32_filltable (int endian); | ||
675 | 659 | ||
676 | #ifndef RB_POWER_OFF | 660 | #ifndef RB_POWER_OFF |
677 | /* Stop system and switch power off if possible. */ | 661 | /* Stop system and switch power off if possible. */ |
678 | #define RB_POWER_OFF 0x4321fedc | 662 | #define RB_POWER_OFF 0x4321fedc |
679 | #endif | 663 | #endif |
680 | 664 | ||
681 | extern const char BB_BANNER[]; | ||
682 | |||
683 | // Make sure we call functions instead of macros. | 665 | // Make sure we call functions instead of macros. |
684 | #undef isalnum | 666 | #undef isalnum |
685 | #undef isalpha | 667 | #undef isalpha |
diff --git a/init/init.c b/init/init.c index beb2b28f0..213a5c149 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -1035,7 +1035,7 @@ int init_main(int argc, char **argv) | |||
1035 | struct sysinfo info; | 1035 | struct sysinfo info; |
1036 | 1036 | ||
1037 | if (!sysinfo(&info) && | 1037 | if (!sysinfo(&info) && |
1038 | (info.mem_unit ? : 1) * (long long)info.totalram < MEGABYTE) | 1038 | (info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024) |
1039 | { | 1039 | { |
1040 | message(CONSOLE,"Low memory: forcing swapon."); | 1040 | message(CONSOLE,"Low memory: forcing swapon."); |
1041 | /* swapon -a requires /proc typically */ | 1041 | /* swapon -a requires /proc typically */ |
diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 115fde744..ff1b55141 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c | |||
@@ -58,12 +58,13 @@ const char *make_human_readable_str(unsigned long long size, | |||
58 | val /= display_unit; /* Don't combine with the line above!!! */ | 58 | val /= display_unit; /* Don't combine with the line above!!! */ |
59 | } else { | 59 | } else { |
60 | ++u; | 60 | ++u; |
61 | while ((val >= KILOBYTE) | 61 | while ((val >= 1024) |
62 | && (u < zero_and_units + sizeof(zero_and_units) - 1)) { | 62 | && (u < zero_and_units + sizeof(zero_and_units) - 1) |
63 | ) { | ||
63 | f = fmt_tenths; | 64 | f = fmt_tenths; |
64 | ++u; | 65 | ++u; |
65 | frac = ((((int)(val % KILOBYTE)) * 10) + (KILOBYTE/2)) / KILOBYTE; | 66 | frac = (((int)(val % 1024)) * 10 + 1024/2) / 1024; |
66 | val /= KILOBYTE; | 67 | val /= 1024; |
67 | } | 68 | } |
68 | if (frac >= 10) { /* We need to round up here. */ | 69 | if (frac >= 10) { /* We need to round up here. */ |
69 | ++val; | 70 | ++val; |