/* CONFIG_LFS is on */
# if ULONG_MAX > 0xffffffff
/* "long" is long enough on this system */
+typedef unsigned long uoff_t;
# define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */
# define BB_STRTOOFF bb_strtoul
# define OFF_FMT "l"
# else
/* "long" is too short, need "long long" */
+typedef unsigned long long uoff_t;
# define XATOOFF(a) xatoull_range(a, 0, LLONG_MAX)
# define BB_STRTOOFF bb_strtoull
# define STRTOOFF strtoull
# if UINT_MAX == 0xffffffff
/* While sizeof(off_t) == sizeof(int), off_t is typedef'ed to long anyway.
* gcc will throw warnings on printf("%d", off_t). Crap... */
+typedef unsigned long uoff_t;
# define XATOOFF(a) xatoi_u(a)
# define BB_STRTOOFF bb_strtou
# define STRTOOFF strtol
# define OFF_FMT "l"
# else
+typedef unsigned long uoff_t;
# define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
# define BB_STRTOOFF bb_strtoul
# define STRTOOFF strtol
// Reads byte-by-byte. Useful when it is important to not read ahead.
// Bytes are appended to pfx (which must be malloced, or NULL).
extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC;
-/* Reads block up to *maxsz_p (default: MAX_INT(ssize_t)) */
+/* Reads block up to *maxsz_p (default: INT_MAX - 4095) */
extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC;
-/* Returns NULL if file can't be opened */
+/* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */
extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC;
/* Autodetects .gz etc */
extern int open_zipped(const char *fname) FAST_FUNC;
extern char *bb_get_chunk_with_continuation(FILE *file, int *end, int *lineno) FAST_FUNC;
/* Reads up to (and including) TERMINATING_STRING: */
extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string) FAST_FUNC;
+/* Same, with limited max size, and returns the length (excluding NUL): */
+extern char *xmalloc_fgets_str_len(FILE *file, const char *terminating_string, size_t *maxsz_p) FAST_FUNC;
/* Chops off TERMINATING_STRING from the end: */
extern char *xmalloc_fgetline_str(FILE *file, const char *terminating_string) FAST_FUNC;
/* Reads up to (and including) "\n" or NUL byte: */
* Both of the above will redirect fd 0,1,2 to /dev/null and drop ctty
* (will do setsid()).
*
- * forkexit_or_rexec(argv) = bare-bones "fork + parent exits" on MMU,
+ * fork_or_rexec(argv) = bare-bones "fork" on MMU,
* "vfork + re-exec ourself" on NOMMU. No fd redirection, no setsid().
- * Currently used for setsid only. On MMU ignores argv.
+ * On MMU ignores argv.
*
* Helper for network daemons in foreground mode:
*
DAEMON_ONLY_SANITIZE = 8, /* internal use */
};
#if BB_MMU
- void forkexit_or_rexec(void) FAST_FUNC;
+ pid_t fork_or_rexec(void) FAST_FUNC;
enum { re_execed = 0 };
-# define forkexit_or_rexec(argv) forkexit_or_rexec()
+# define fork_or_rexec(argv) fork_or_rexec()
# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
# define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus)
#else
void re_exec(char **argv) NORETURN FAST_FUNC;
- void forkexit_or_rexec(char **argv) FAST_FUNC;
+ pid_t fork_or_rexec(char **argv) FAST_FUNC;
extern bool re_execed;
int BUG_fork_is_unavailable_on_nommu(void) FAST_FUNC;
int BUG_daemon_is_unavailable_on_nommu(void) FAST_FUNC;
#if ENABLE_FEATURE_EDITING
/* It's NOT just ENABLEd or disabled. It's a number: */
#ifdef CONFIG_FEATURE_EDITING_HISTORY
-#define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0)
+# define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0)
#else
-#define MAX_HISTORY 0
+# define MAX_HISTORY 0
#endif
typedef struct line_input_t {
int flags;
#if MAX_HISTORY
int cnt_history;
int cur_history;
- USE_FEATURE_EDITING_SAVEHISTORY(const char *hist_file;)
+#if ENABLE_FEATURE_EDITING_SAVEHISTORY
+ unsigned cnt_history_in_file;
+ const char *hist_file;
+#endif
char *history[MAX_HISTORY + 1];
#endif
} line_input_t;
FOR_SHELL = DO_HISTORY | SAVE_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
};
line_input_t *new_line_input_t(int flags) FAST_FUNC;
+/* so far static: void free_line_input_t(line_input_t *n) FAST_FUNC; */
/* Returns:
* -1 on read errors or EOF, or on bare Ctrl-D,
* 0 on ctrl-C (the line entered is still returned in 'command'),
PSSCAN_ARGVN = (1 << 16) * (ENABLE_KILLALL
|| ENABLE_PGREP || ENABLE_PKILL
|| ENABLE_PIDOF
- || ENABLE_SESTATUS
+ || ENABLE_SESTATUS
),
USE_SELINUX(PSSCAN_CONTEXT = 1 << 17,)
PSSCAN_START_TIME = 1 << 18,
void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC;
typedef struct sha1_ctx_t {
- uint32_t count[2];
- uint32_t hash[5];
- uint32_t wbuf[16];
+ uint32_t hash[8]; /* 5, +3 elements for sha256 */
+ uint64_t total64;
+ uint8_t wbuffer[64]; /* NB: always correctly aligned for uint64_t */
+ void (*process_block)(struct sha1_ctx_t*) FAST_FUNC;
} sha1_ctx_t;
void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) FAST_FUNC;
void sha1_end(void *resbuf, sha1_ctx_t *ctx) FAST_FUNC;
-typedef struct sha256_ctx_t {
- uint32_t H[8];
- uint32_t total[2]; /* rename to "count"? */
- uint32_t buflen;
- char buffer[128]; /* NB: always correctly aligned for uint32_t */
-} sha256_ctx_t;
+typedef struct sha1_ctx_t sha256_ctx_t;
void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
-void sha256_hash(const void *buffer, size_t len, sha256_ctx_t *ctx) FAST_FUNC;
-void sha256_end(void *resbuf, sha256_ctx_t *ctx) FAST_FUNC;
+#define sha256_hash sha1_hash
+#define sha256_end sha1_end
typedef struct sha512_ctx_t {
- uint64_t H[8];
- uint64_t total[2];
- uint64_t buflen;
- char buffer[256]; /* NB: always correctly aligned for uint64_t */
+ uint64_t hash[8];
+ uint64_t total64[2];
+ uint8_t wbuffer[128]; /* NB: always correctly aligned for uint64_t */
} sha512_ctx_t;
void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
void sha512_hash(const void *buffer, size_t len, sha512_ctx_t *ctx) FAST_FUNC;