aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-27 09:05:02 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-27 09:05:02 +0000
commite7c6f0b4c27e36a1331ae7310bfa0549ead33849 (patch)
treebf0291a625fee415b6500007b0ec90880104f962
parent9bc0f50defc28a31a2d214e654ec48e2a1bcc897 (diff)
downloadbusybox-w32-e7c6f0b4c27e36a1331ae7310bfa0549ead33849.tar.gz
busybox-w32-e7c6f0b4c27e36a1331ae7310bfa0549ead33849.tar.bz2
busybox-w32-e7c6f0b4c27e36a1331ae7310bfa0549ead33849.zip
reshuffle libbb.h contents so that order of decls makes sense
Found bad typo in largefile support :) git-svn-id: svn://busybox.net/trunk/busybox@16453 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/df.c6
-rw-r--r--coreutils/du.c6
-rw-r--r--coreutils/mkdir.c2
-rw-r--r--include/libbb.h518
-rw-r--r--init/init.c2
-rw-r--r--libbb/human_readable.c9
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
30static long kscale(long b, long bs) 30static 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
30static unsigned long disp_hr = KILOBYTE; 30static unsigned long disp_hr = 1024;
31# else 31# else
32static unsigned long disp_hr = 512; 32static 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
161typedef struct llist_s { 160#if (__GLIBC__ < 2)
162 char *data; 161int 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
165extern void llist_add_to(llist_t **old_head, void *data); 164// confusing the two versions of basename. See the dirname/basename man page
166extern void llist_add_to_end(llist_t **list_head, void *data); 165// for details.
167extern void *llist_pop(llist_t **elm); 166char *dirname(char *path);
168extern void llist_free(llist_t *elm, void (*freeit)(void *data)); 167/* Include our own copy of struct sysinfo to avoid binary compatibility
169extern llist_t* rev_llist(llist_t *list); 168 * problems with Linux 2.4, which changed things. Grumble, grumble. */
170 169struct sysinfo {
171enum { 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};
177extern const char *msg_eol; 185extern int sysinfo(struct sysinfo* info);
178extern int logmode;
179extern int die_sleep;
180
181extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
182extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
183extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
184extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
185extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
186extern void bb_vherror_msg(const char *s, va_list p);
187extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
188extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
189 186
190extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN;
191extern void bb_perror_nomsg(void);
192
193extern 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 */ 188extern void chomp(char *s);
196extern void bb_verror_msg(const char *s, va_list p, const char *strerr) __attribute__ ((format (printf, 1, 0))); 189extern void trim(char *s);
197extern void bb_vperror_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0))); 190extern char *skip_whitespace(const char *);
198extern void bb_vinfo_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0)));
199
200extern int bb_echo(int argc, char** argv);
201extern int bb_test(int argc, char** argv);
202 191
203extern const char *bb_mode_string(int mode); 192extern const char *bb_mode_string(int mode);
204extern int is_directory(const char *name, int followLinks, struct stat *statBuf); 193extern int is_directory(const char *name, int followLinks, struct stat *statBuf);
205extern DIR *warn_opendir(const char *path);
206extern DIR *xopendir(const char *path);
207
208extern ssize_t safe_read(int fd, void *buf, size_t count);
209extern ssize_t full_read(int fd, void *buf, size_t count);
210extern void xread(int fd, void *buf, size_t count);
211extern unsigned char xread_char(int fd);
212extern char *reads(int fd, char *buf, size_t count);
213ssize_t read_close(int fd, void *buf, size_t count);
214ssize_t open_read_close(const char *filename, void *buf, size_t count);
215void *xmalloc_open_read_close(const char *filename, size_t *sizep);
216
217extern ssize_t safe_write(int fd, const void *buf, size_t count);
218extern ssize_t full_write(int fd, const void *buf, size_t count);
219extern void xwrite(int fd, void *buf, size_t count);
220
221extern int remove_file(const char *path, int flags); 194extern int remove_file(const char *path, int flags);
222extern int copy_file(const char *source, const char *dest, int flags); 195extern int copy_file(const char *source, const char *dest, int flags);
223
224extern int recursive_action(const char *fileName, int recurse, 196extern 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 201extern int device_open(const char *device, int mode);
230extern int bb_parse_mode(const char* s, mode_t* theMode);
231
232extern unsigned int tty_baud_to_value(speed_t speed);
233extern speed_t tty_value_to_baud(unsigned int value);
234
235extern int get_linux_version_code(void);
236
237extern int get_console_fd(void); 202extern int get_console_fd(void);
238extern struct mntent *find_mount_point(const char *name, const char *table);
239extern void erase_mtab(const char * name);
240extern long *find_pid_by_name( const char* pidName);
241extern long *pidlist_reverse(long *pidList);
242extern char *find_block_device(char *path); 203extern char *find_block_device(char *path);
243extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); 204extern off_t bb_copyfd_size(int fd1, int fd2, off_t size);
244extern off_t bb_copyfd_eof(int fd1, int fd2); 205extern off_t bb_copyfd_eof(int fd1, int fd2);
245extern char bb_process_escape_sequence(const char **ptr); 206extern char bb_process_escape_sequence(const char **ptr);
246extern char *bb_get_last_path_component(char *path); 207extern char *bb_get_last_path_component(char *path);
247 208
209
210extern DIR *xopendir(const char *path);
211extern DIR *warn_opendir(const char *path);
212
213char *xgetcwd(char *cwd);
214char *xreadlink(const char *path);
215extern void xstat(char *filename, struct stat *buf);
216extern pid_t spawn(char **argv);
217extern pid_t xspawn(char **argv);
218extern int wait4pid(int pid);
219extern void xsetgid(gid_t gid);
220extern void xsetuid(uid_t uid);
221extern void xdaemon(int nochdir, int noclose);
222extern void xchdir(const char *path);
223extern void xsetenv(const char *key, const char *value);
224extern int xopen(const char *pathname, int flags);
225extern int xopen3(const char *pathname, int flags, int mode);
226extern off_t xlseek(int fd, off_t offset, int whence);
227extern off_t fdlength(int fd);
228
229extern int xsocket(int domain, int type, int protocol);
230extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
231extern void xlisten(int s, int backlog);
232extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
233extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
234extern struct hostent *xgethostbyname(const char *name);
235extern struct hostent *xgethostbyname2(const char *name, int af);
236
237extern char *xstrdup(const char *s);
238extern char *xstrndup(const char *s, int n);
239extern char *safe_strncpy(char *dst, const char *src, size_t size);
240extern 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. */
244extern void *xmalloc(size_t size);
245extern void *xrealloc(void *old, size_t size);
246extern void *xzalloc(size_t size);
247
248extern ssize_t safe_read(int fd, void *buf, size_t count);
249extern ssize_t full_read(int fd, void *buf, size_t count);
250extern void xread(int fd, void *buf, size_t count);
251extern unsigned char xread_char(int fd);
252extern char *reads(int fd, char *buf, size_t count);
253extern ssize_t read_close(int fd, void *buf, size_t count);
254extern ssize_t open_read_close(const char *filename, void *buf, size_t count);
255extern void *xmalloc_open_read_close(const char *filename, size_t *sizep);
256
257extern ssize_t safe_write(int fd, const void *buf, size_t count);
258extern ssize_t full_write(int fd, const void *buf, size_t count);
259extern 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: */
249extern void xprint_and_close_file(FILE *file); 262extern void xprint_and_close_file(FILE *file);
250extern char *xmalloc_fgets(FILE *file); 263extern 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: */
265extern FILE *fopen_or_warn_stdin(const char *filename); 278extern FILE *fopen_or_warn_stdin(const char *filename);
266 279
267extern void xstat(char *filename, struct stat *buf); 280
268extern int xsocket(int domain, int type, int protocol);
269extern pid_t spawn(char **argv);
270extern pid_t xspawn(char **argv);
271extern int wait4pid(int pid);
272extern void xdaemon(int nochdir, int noclose);
273extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
274extern void xlisten(int s, int backlog);
275extern void xchdir(const char *path);
276extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen); 281extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
277extern char *utoa(unsigned n); 282extern char *utoa(unsigned n);
278extern void itoa_to_buf(int n, char *buf, unsigned buflen); 283extern void itoa_to_buf(int n, char *buf, unsigned buflen);
279extern char *itoa(int n); 284extern char *itoa(int n);
280extern void xsetgid(gid_t gid);
281extern void xsetuid(uid_t uid);
282extern off_t fdlength(int fd);
283
284enum { BB_GETOPT_ERROR = 0x80000000 };
285extern const char *opt_complementary;
286extern const struct option *applet_long_options;
287extern uint32_t option_mask32;
288extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
289
290extern void bb_warn_ignoring_args(int n);
291
292extern void chomp(char *s);
293extern void trim(char *s);
294extern char *skip_whitespace(const char *);
295 285
296#ifndef BUILD_INDIVIDUAL
297extern struct BB_applet *find_applet_by_name(const char *name);
298extern 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. */
303extern void *xmalloc(size_t size);
304extern void *xrealloc(void *old, size_t size);
305extern void *xzalloc(size_t size);
306
307extern char *xstrdup(const char *s);
308extern char *xstrndup(const char *s, int n);
309extern 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
322struct suffix_mult { 298struct suffix_mult {
323 const char *suffix; 299 const char *suffix;
324 unsigned int mult; 300 unsigned mult;
325}; 301};
326
327unsigned long long xstrtoull(const char *numstr, int base); 302unsigned long long xstrtoull(const char *numstr, int base);
328unsigned long long xatoull(const char *numstr); 303unsigned long long xatoull(const char *numstr);
329unsigned long xstrtoul_range_sfx(const char *numstr, int base, 304unsigned 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 */
372uint16_t xatou16(const char *numstr); 347uint16_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);
379extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix); 355extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);
380extern char *bb_getpwuid(char *name, long uid, int bufsize); 356extern char *bb_getpwuid(char *name, long uid, int bufsize);
381extern char *bb_getgrgid(char *group, long gid, int bufsize); 357extern char *bb_getgrgid(char *group, long gid, int bufsize);
382extern char *bb_askpass(int timeout, const char * prompt);
383/* from chpst */ 358/* from chpst */
384struct bb_uidgid_t { 359struct bb_uidgid_t {
385 uid_t uid; 360 uid_t uid;
@@ -388,49 +363,80 @@ struct bb_uidgid_t {
388extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/); 363extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/);
389 364
390 365
391extern int device_open(const char *device, int mode); 366enum { BB_GETOPT_ERROR = 0x80000000 };
367extern const char *opt_complementary;
368extern const struct option *applet_long_options;
369extern uint32_t option_mask32;
370extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
371
372
373typedef struct llist_s {
374 char *data;
375 struct llist_s *link;
376} llist_t;
377extern void llist_add_to(llist_t **old_head, void *data);
378extern void llist_add_to_end(llist_t **list_head, void *data);
379extern void *llist_pop(llist_t **elm);
380extern void llist_free(llist_t *elm, void (*freeit)(void *data));
381extern llist_t* rev_llist(llist_t *list);
382
383enum {
384 LOGMODE_NONE = 0,
385 LOGMODE_STDIO = 1<<0,
386 LOGMODE_SYSLOG = 1<<1,
387 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
388};
389extern const char *msg_eol;
390extern int logmode;
391extern int die_sleep;
392extern int xfunc_error_retval;
393extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
394extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
395extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
396extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
397extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
398extern void bb_vherror_msg(const char *s, va_list p);
399extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
400extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
401extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN;
402extern void bb_perror_nomsg(void);
403extern 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 */
405extern void bb_verror_msg(const char *s, va_list p, const char *strerr);
406extern void bb_vperror_msg(const char *s, va_list p);
407extern void bb_vinfo_msg(const char *s, va_list p);
408
409
410extern int bb_echo(int argc, char** argv);
411extern int bb_test(int argc, char** argv);
412
413#ifndef BUILD_INDIVIDUAL
414extern struct BB_applet *find_applet_by_name(const char *name);
415extern void run_applet_by_name(const char *name, int argc, char **argv);
416#endif
417
418extern struct mntent *find_mount_point(const char *name, const char *table);
419extern void erase_mtab(const char * name);
420extern unsigned int tty_baud_to_value(speed_t speed);
421extern speed_t tty_value_to_baud(unsigned int value);
422extern void bb_warn_ignoring_args(int n);
423
424extern int get_linux_version_code(void);
392 425
393extern char *query_loop(const char *device); 426extern char *query_loop(const char *device);
394extern int del_loop(const char *device); 427extern int del_loop(const char *device);
395extern int set_loop(char **device, const char *file, unsigned long long offset); 428extern int set_loop(char **device, const char *file, unsigned long long offset);
396 429
397#if (__GLIBC__ < 2)
398extern 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. */
403struct 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};
419extern int sysinfo (struct sysinfo* info);
420
421enum {
422 KILOBYTE = 1024,
423 MEGABYTE = (KILOBYTE*1024),
424 GIGABYTE = (MEGABYTE*1024)
425};
426const char *make_human_readable_str(unsigned long long size, 431const 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
434char *bb_askpass(int timeout, const char * prompt);
429int bb_ask_confirmation(void); 435int bb_ask_confirmation(void);
430int klogctl(int type, char * b, int len); 436int klogctl(int type, char * b, int len);
431 437
432char *xgetcwd(char *cwd); 438extern int bb_parse_mode(const char* s, mode_t* theMode);
433char *xreadlink(const char *path); 439
434char *concat_path_file(const char *path, const char *filename); 440char *concat_path_file(const char *path, const char *filename);
435char *concat_subpath_file(const char *path, const char *filename); 441char *concat_subpath_file(const char *path, const char *filename);
436char *last_char_is(const char *s, int c); 442char *last_char_is(const char *s, int c);
@@ -439,23 +445,14 @@ int execable_file(const char *name);
439char *find_execable(const char *filename); 445char *find_execable(const char *filename);
440int exists_execable(const char *filename); 446int exists_execable(const char *filename);
441 447
442extern USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out); 448USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
443extern int inflate(int in, int out); 449int inflate(int in, int out);
444 450
445extern struct hostent *xgethostbyname(const char *name); 451int create_icmp_socket(void);
446extern struct hostent *xgethostbyname2(const char *name, int af); 452int create_icmp6_socket(void);
447extern int create_icmp_socket(void);
448extern int create_icmp6_socket(void);
449extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
450extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
451
452extern unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port);
453extern 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 454unsigned 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 455void bb_lookup_host(struct sockaddr_in *s_in, const char *host);
457// for details.
458char *dirname(char *path);
459 456
460int bb_make_directory(char *path, long mode, int flags); 457int bb_make_directory(char *path, long mode, int flags);
461 458
@@ -464,6 +461,96 @@ const char *get_signame(int number);
464 461
465char *bb_simplify_path(const char *path); 462char *bb_simplify_path(const char *path);
466 463
464#define FAIL_DELAY 3
465extern void bb_do_delay(int seconds);
466extern void change_identity(const struct passwd *pw);
467extern const char *change_identity_e2str(const struct passwd *pw);
468extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args);
469#ifdef CONFIG_SELINUX
470extern void renew_current_security_context(void);
471extern void set_current_security_context(security_context_t sid);
472#endif
473extern int run_parts(char **args, const unsigned char test_mode, char **env);
474extern int restricted_shell(const char *shell);
475extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw);
476extern int correct_password(const struct passwd *pw);
477extern char *pw_encrypt(const char *clear, const char *salt);
478extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
479extern int compare_string_array(const char * const string_array[], const char *key);
480extern void print_login_issue(const char *issue_file, const char *tty);
481extern void print_login_prompt(void);
482#ifdef BB_NOMMU
483extern void vfork_daemon(int nochdir, int noclose);
484extern void vfork_daemon_rexec(int nochdir, int noclose,
485 int argc, char **argv, char *foreground_opt);
486#endif
487extern int get_terminal_width_height(int fd, int *width, int *height);
488extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *));
489
490int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
491void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
492void 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
503typedef 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;
520procps_status_t* procps_scan(int save_user_arg0);
521long *find_pid_by_name( const char* pidName);
522long *pidlist_reverse(long *pidList);
523
524
525extern const char bb_uuenc_tbl_base64[];
526extern const char bb_uuenc_tbl_std[];
527void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl);
528
529typedef struct _sha1_ctx_t_ {
530 uint32_t count[2];
531 uint32_t hash[5];
532 uint32_t wbuf[16];
533} sha1_ctx_t;
534void sha1_begin(sha1_ctx_t *ctx);
535void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx);
536void *sha1_end(void *resbuf, sha1_ctx_t *ctx);
537
538typedef 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;
547void md5_begin(md5_ctx_t *ctx);
548void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
549void *md5_end(void *resbuf, md5_ctx_t *ctx);
550
551uint32_t *crc32_filltable(int endian);
552
553
467enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ 554enum { /* 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
478extern const char *applet_name; 565extern const char *applet_name;
566extern const char BB_BANNER[];
479 567
480extern const char bb_msg_full_version[]; 568extern const char bb_msg_full_version[];
481extern const char bb_msg_memory_exhausted[]; 569extern const char bb_msg_memory_exhausted[];
@@ -491,6 +579,7 @@ extern const char bb_msg_invalid_arg[];
491extern const char bb_msg_standard_input[]; 579extern const char bb_msg_standard_input[];
492extern const char bb_msg_standard_output[]; 580extern const char bb_msg_standard_output[];
493 581
582extern const char bb_path_mtab_file[];
494extern const char bb_path_nologin_file[]; 583extern const char bb_path_nologin_file[];
495extern const char bb_path_passwd_file[]; 584extern const char bb_path_passwd_file[];
496extern const char bb_path_shadow_file[]; 585extern const char bb_path_shadow_file[];
@@ -506,14 +595,11 @@ extern const char bb_dev_null[];
506#endif 595#endif
507extern char bb_common_bufsiz1[BUFSIZ+1]; 596extern 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
517extern const char bb_default_login_shell[]; 603extern 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
524extern const char bb_path_mtab_file[];
525
526extern 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
578int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
579void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
580void reset_ino_dev_hashtable(void);
581
582char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
583
584#define FAIL_DELAY 3
585extern void bb_do_delay(int seconds);
586extern void change_identity(const struct passwd *pw);
587extern const char *change_identity_e2str(const struct passwd *pw);
588extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args);
589#ifdef CONFIG_SELINUX
590extern void renew_current_security_context(void);
591extern void set_current_security_context(security_context_t sid);
592#endif
593extern int run_parts(char **args, const unsigned char test_mode, char **env);
594extern int restricted_shell(const char *shell);
595extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw);
596extern int correct_password(const struct passwd *pw);
597extern char *pw_encrypt(const char *clear, const char *salt);
598extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
599
600extern void xsetenv(const char *key, const char *value);
601extern int xopen(const char *pathname, int flags);
602extern int xopen3(const char *pathname, int flags, int mode);
603extern off_t xlseek(int fd, off_t offset, int whence);
604
605extern const char bb_uuenc_tbl_base64[];
606extern const char bb_uuenc_tbl_std[];
607extern 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
617typedef 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
635extern procps_status_t * procps_scan(int save_user_arg0);
636extern int compare_string_array(const char * const string_array[], const char *key);
637
638extern void print_login_issue(const char *issue_file, const char *tty);
639extern void print_login_prompt(void);
640
641#ifdef BB_NOMMU
642extern void vfork_daemon(int nochdir, int noclose);
643extern void vfork_daemon_rexec(int nochdir, int noclose,
644 int argc, char **argv, char *foreground_opt);
645#endif
646
647extern int get_terminal_width_height(int fd, int *width, int *height);
648extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *));
649
650typedef struct _sha1_ctx_t_ {
651 uint32_t count[2];
652 uint32_t hash[5];
653 uint32_t wbuf[16];
654} sha1_ctx_t;
655
656void sha1_begin(sha1_ctx_t *ctx);
657void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx);
658void *sha1_end(void *resbuf, sha1_ctx_t *ctx);
659
660typedef 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
670void md5_begin(md5_ctx_t *ctx);
671void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
672void *md5_end(void *resbuf, md5_ctx_t *ctx);
673
674extern 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
681extern 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;