diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Kbuild | 13 | ||||
-rw-r--r-- | libbb/git.c | 31 | ||||
-rw-r--r-- | libbb/git.h | 5 | ||||
-rw-r--r-- | libbb/lineedit.c | 2 | ||||
-rw-r--r-- | libbb/mingw.c | 5 | ||||
-rw-r--r-- | libbb/regex.c | 2 | ||||
-rw-r--r-- | libbb/strbuf.c | 11 | ||||
-rw-r--r-- | libbb/strbuf_file.c | 4 | ||||
-rw-r--r-- | libbb/termios.c | 2 | ||||
-rw-r--r-- | libbb/usage.c | 81 |
10 files changed, 52 insertions, 104 deletions
diff --git a/libbb/Kbuild b/libbb/Kbuild index b3560bd0b..1ef67a8b7 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -13,11 +13,17 @@ lib-y += change_identity.o | |||
13 | lib-y += create_icmp6_socket.o | 13 | lib-y += create_icmp6_socket.o |
14 | lib-y += create_icmp_socket.o | 14 | lib-y += create_icmp_socket.o |
15 | lib-y += device_open.o | 15 | lib-y += device_open.o |
16 | lib-y += get_console.o | ||
16 | lib-y += inet_common.o | 17 | lib-y += inet_common.o |
18 | lib-y += inode_hash.o | ||
17 | lib-y += kernel_version.o | 19 | lib-y += kernel_version.o |
18 | lib-y += login.o | 20 | lib-y += login.o |
19 | lib-y += makedev.o | 21 | lib-y += makedev.o |
20 | lib-y += match_fstype.o | 22 | lib-y += match_fstype.o |
23 | lib-y += obscure.o | ||
24 | lib-y += procps.o | ||
25 | lib-y += restricted_shell.o | ||
26 | lib-y += run_shell.o | ||
21 | lib-y += setup_environment.o | 27 | lib-y += setup_environment.o |
22 | lib-y += speed_table.o | 28 | lib-y += speed_table.o |
23 | lib-y += vfork_daemon_rexec.o | 29 | lib-y += vfork_daemon_rexec.o |
@@ -46,7 +52,6 @@ lib-y += fgets_str.o | |||
46 | lib-y += find_pid_by_name.o | 52 | lib-y += find_pid_by_name.o |
47 | lib-y += find_root_device.o | 53 | lib-y += find_root_device.o |
48 | lib-y += full_write.o | 54 | lib-y += full_write.o |
49 | lib-y += get_console.o | ||
50 | lib-y += get_last_path_component.o | 55 | lib-y += get_last_path_component.o |
51 | lib-y += get_line_from_file.o | 56 | lib-y += get_line_from_file.o |
52 | lib-y += getopt32.o | 57 | lib-y += getopt32.o |
@@ -54,7 +59,6 @@ lib-y += herror_msg.o | |||
54 | lib-y += herror_msg_and_die.o | 59 | lib-y += herror_msg_and_die.o |
55 | lib-y += human_readable.o | 60 | lib-y += human_readable.o |
56 | lib-y += info_msg.o | 61 | lib-y += info_msg.o |
57 | lib-y += inode_hash.o | ||
58 | lib-y += isdirectory.o | 62 | lib-y += isdirectory.o |
59 | lib-y += last_char_is.o | 63 | lib-y += last_char_is.o |
60 | lib-y += lineedit.o | 64 | lib-y += lineedit.o |
@@ -64,7 +68,6 @@ lib-y += md5.o | |||
64 | lib-y += messages.o | 68 | lib-y += messages.o |
65 | lib-y += mode_string.o | 69 | lib-y += mode_string.o |
66 | lib-y += mtab_file.o | 70 | lib-y += mtab_file.o |
67 | lib-y += obscure.o | ||
68 | lib-y += parse_mode.o | 71 | lib-y += parse_mode.o |
69 | lib-y += perror_msg.o | 72 | lib-y += perror_msg.o |
70 | lib-y += perror_msg_and_die.o | 73 | lib-y += perror_msg_and_die.o |
@@ -72,12 +75,9 @@ lib-y += perror_nomsg.o | |||
72 | lib-y += perror_nomsg_and_die.o | 75 | lib-y += perror_nomsg_and_die.o |
73 | lib-y += pidfile.o | 76 | lib-y += pidfile.o |
74 | lib-y += process_escape_sequence.o | 77 | lib-y += process_escape_sequence.o |
75 | lib-y += procps.o | ||
76 | lib-y += read.o | 78 | lib-y += read.o |
77 | lib-y += recursive_action.o | 79 | lib-y += recursive_action.o |
78 | lib-y += remove_file.o | 80 | lib-y += remove_file.o |
79 | lib-y += restricted_shell.o | ||
80 | lib-y += run_shell.o | ||
81 | lib-y += safe_strncpy.o | 81 | lib-y += safe_strncpy.o |
82 | lib-y += safe_write.o | 82 | lib-y += safe_write.o |
83 | lib-y += sha1.o | 83 | lib-y += sha1.o |
@@ -140,6 +140,5 @@ lib-$(CONFIG_MINGW32) += strbuf_file.o | |||
140 | lib-$(CONFIG_MINGW32) += strlcpy.o | 140 | lib-$(CONFIG_MINGW32) += strlcpy.o |
141 | lib-$(CONFIG_MINGW32) += termios.o | 141 | lib-$(CONFIG_MINGW32) += termios.o |
142 | lib-$(CONFIG_MINGW32) += trace.o | 142 | lib-$(CONFIG_MINGW32) += trace.o |
143 | lib-$(CONFIG_MINGW32) += usage.o | ||
144 | lib-$(CONFIG_MINGW32) += winansi.o | 143 | lib-$(CONFIG_MINGW32) += winansi.o |
145 | lib-$(CONFIG_MINGW32) += write_or_die.o | 144 | lib-$(CONFIG_MINGW32) += write_or_die.o |
diff --git a/libbb/git.c b/libbb/git.c index 3ca8a9424..668f8c118 100644 --- a/libbb/git.c +++ b/libbb/git.c | |||
@@ -1,13 +1,42 @@ | |||
1 | #include "libbb.h" | 1 | #include "libbb.h" |
2 | #include "git.h" | 2 | #include "git.h" |
3 | 3 | ||
4 | #define die bb_error_msg_and_die | ||
5 | |||
6 | /* | ||
7 | * xwrite() is the same a write(), but it automatically restarts write() | ||
8 | * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT | ||
9 | * GUARANTEE that "len" bytes is written even if the operation is successful. | ||
10 | */ | ||
11 | ssize_t _xwrite(int fd, const void *buf, size_t len) | ||
12 | { | ||
13 | ssize_t nr; | ||
14 | while (1) { | ||
15 | nr = write(fd, buf, len); | ||
16 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
17 | continue; | ||
18 | return nr; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | ssize_t _xread(int fd, void *buf, size_t len) | ||
23 | { | ||
24 | ssize_t nr; | ||
25 | while (1) { | ||
26 | nr = read(fd, buf, len); | ||
27 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
28 | continue; | ||
29 | return nr; | ||
30 | } | ||
31 | } | ||
32 | |||
4 | ssize_t write_in_full(int fd, const void *buf, size_t count) | 33 | ssize_t write_in_full(int fd, const void *buf, size_t count) |
5 | { | 34 | { |
6 | const char *p = buf; | 35 | const char *p = buf; |
7 | ssize_t total = 0; | 36 | ssize_t total = 0; |
8 | 37 | ||
9 | while (count > 0) { | 38 | while (count > 0) { |
10 | ssize_t written = xwrite(fd, p, count); | 39 | ssize_t written = _xwrite(fd, p, count); |
11 | if (written < 0) | 40 | if (written < 0) |
12 | return -1; | 41 | return -1; |
13 | if (!written) { | 42 | if (!written) { |
diff --git a/libbb/git.h b/libbb/git.h index 3274af34d..07ef93bf4 100644 --- a/libbb/git.h +++ b/libbb/git.h | |||
@@ -1,4 +1,7 @@ | |||
1 | ssize_t write_in_full(int fd, const void *buf, size_t count); | 1 | ssize_t write_in_full(int fd, const void *buf, size_t count); |
2 | void *xcalloc(size_t nmemb, size_t size); | ||
3 | ssize_t _xwrite(int fd, const void *buf, size_t len); | ||
4 | ssize_t _xread(int fd, void *buf, size_t len); | ||
2 | 5 | ||
3 | #define alloc_nr(x) (((x)+16)*3/2) | 6 | #define alloc_nr(x) (((x)+16)*3/2) |
4 | 7 | ||
@@ -19,3 +22,5 @@ static inline int is_absolute_path(const char *path) | |||
19 | } | 22 | } |
20 | 23 | ||
21 | #define NORETURN ATTRIBUTE_NORETURN | 24 | #define NORETURN ATTRIBUTE_NORETURN |
25 | #define die bb_error_msg_and_die | ||
26 | #define error(...) fprintf(stderr, __VA_ARGS__) | ||
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index e56dd20b0..a4b0ff045 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -170,7 +170,7 @@ static void input_backward(unsigned num) | |||
170 | if (cmdedit_x >= num) { | 170 | if (cmdedit_x >= num) { |
171 | cmdedit_x -= num; | 171 | cmdedit_x -= num; |
172 | if (num <= 4) { | 172 | if (num <= 4) { |
173 | printf("\b\b\b\b" + (4-num)); | 173 | printf("%s", "\b\b\b\b" + (4-num)); /* "%s" to stop mingw warning */ |
174 | return; | 174 | return; |
175 | } | 175 | } |
176 | printf("\033[%uD", num); | 176 | printf("\033[%uD", num); |
diff --git a/libbb/mingw.c b/libbb/mingw.c index aa1417acf..ab582215b 100644 --- a/libbb/mingw.c +++ b/libbb/mingw.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include "win32.h" | 2 | #include "win32.h" |
3 | #include "strbuf.h" | 3 | #include "strbuf.h" |
4 | #include "run-command.h" | 4 | #include "run-command.h" |
5 | #include "git.h" | ||
5 | 6 | ||
6 | unsigned int _CRT_fmode = _O_BINARY; | 7 | unsigned int _CRT_fmode = _O_BINARY; |
7 | 8 | ||
@@ -131,13 +132,15 @@ int mingw_open (const char *filename, int oflags, ...) | |||
131 | { | 132 | { |
132 | va_list args; | 133 | va_list args; |
133 | unsigned mode; | 134 | unsigned mode; |
135 | int fd; | ||
136 | |||
134 | va_start(args, oflags); | 137 | va_start(args, oflags); |
135 | mode = va_arg(args, int); | 138 | mode = va_arg(args, int); |
136 | va_end(args); | 139 | va_end(args); |
137 | 140 | ||
138 | if (!strcmp(filename, "/dev/null")) | 141 | if (!strcmp(filename, "/dev/null")) |
139 | filename = "nul"; | 142 | filename = "nul"; |
140 | int fd = open(filename, oflags, mode); | 143 | fd = open(filename, oflags, mode); |
141 | if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) { | 144 | if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) { |
142 | DWORD attrs = GetFileAttributes(filename); | 145 | DWORD attrs = GetFileAttributes(filename); |
143 | if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) | 146 | if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) |
diff --git a/libbb/regex.c b/libbb/regex.c index 87b33e466..2cca16934 100644 --- a/libbb/regex.c +++ b/libbb/regex.c | |||
@@ -24,7 +24,9 @@ | |||
24 | #pragma alloca | 24 | #pragma alloca |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #ifndef _GNU_SOURCE | ||
27 | #define _GNU_SOURCE | 28 | #define _GNU_SOURCE |
29 | #endif | ||
28 | 30 | ||
29 | /* We need this for `regex.h', and perhaps for the Emacs include files. */ | 31 | /* We need this for `regex.h', and perhaps for the Emacs include files. */ |
30 | #include <sys/types.h> | 32 | #include <sys/types.h> |
diff --git a/libbb/strbuf.c b/libbb/strbuf.c index d98b0fd41..98659d448 100644 --- a/libbb/strbuf.c +++ b/libbb/strbuf.c | |||
@@ -2,15 +2,6 @@ | |||
2 | #include "strbuf.h" | 2 | #include "strbuf.h" |
3 | #include "git.h" | 3 | #include "git.h" |
4 | 4 | ||
5 | int prefixcmp(const char *str, const char *prefix) | ||
6 | { | ||
7 | for (; ; str++, prefix++) | ||
8 | if (!*prefix) | ||
9 | return 0; | ||
10 | else if (*str != *prefix) | ||
11 | return (unsigned char)*prefix - (unsigned char)*str; | ||
12 | } | ||
13 | |||
14 | /* | 5 | /* |
15 | * Used as the default ->buf value, so that people can always assume | 6 | * Used as the default ->buf value, so that people can always assume |
16 | * buf is non NULL and ->buf is NUL terminated even for a freshly | 7 | * buf is non NULL and ->buf is NUL terminated even for a freshly |
@@ -275,7 +266,7 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint) | |||
275 | for (;;) { | 266 | for (;;) { |
276 | ssize_t cnt; | 267 | ssize_t cnt; |
277 | 268 | ||
278 | cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1); | 269 | cnt = _xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1); |
279 | if (cnt < 0) { | 270 | if (cnt < 0) { |
280 | if (oldalloc == 0) | 271 | if (oldalloc == 0) |
281 | strbuf_release(sb); | 272 | strbuf_release(sb); |
diff --git a/libbb/strbuf_file.c b/libbb/strbuf_file.c index fb2ba7966..cdacf5344 100644 --- a/libbb/strbuf_file.c +++ b/libbb/strbuf_file.c | |||
@@ -31,14 +31,14 @@ int sfprintf(struct strbuf_file *sf, const char *fmt, ...) | |||
31 | len = vsnprintf(sb.buf + sb.len, sb.alloc - sb.len, fmt, ap); | 31 | len = vsnprintf(sb.buf + sb.len, sb.alloc - sb.len, fmt, ap); |
32 | va_end(ap); | 32 | va_end(ap); |
33 | if (len < 0) | 33 | if (len < 0) |
34 | die("your vsnprintf is broken"); | 34 | bb_error_msg_and_die("your vsnprintf is broken"); |
35 | if (len > strbuf_avail(&sb)) { | 35 | if (len > strbuf_avail(&sb)) { |
36 | strbuf_grow(&sb, len); | 36 | strbuf_grow(&sb, len); |
37 | va_start(ap, fmt); | 37 | va_start(ap, fmt); |
38 | len = vsnprintf(sb.buf + sb.len, sb.alloc - sb.len, fmt, ap); | 38 | len = vsnprintf(sb.buf + sb.len, sb.alloc - sb.len, fmt, ap); |
39 | va_end(ap); | 39 | va_end(ap); |
40 | if (len > strbuf_avail(&sb)) { | 40 | if (len > strbuf_avail(&sb)) { |
41 | die("this should not happen, your snprintf is broken"); | 41 | bb_error_msg_and_die("this should not happen, your snprintf is broken"); |
42 | } | 42 | } |
43 | } | 43 | } |
44 | strbuf_setlen(&sb, sb.len + len); | 44 | strbuf_setlen(&sb, sb.len + len); |
diff --git a/libbb/termios.c b/libbb/termios.c index 1291bf785..04eee7ced 100644 --- a/libbb/termios.c +++ b/libbb/termios.c | |||
@@ -260,7 +260,7 @@ int wincon_read(int fd, char *buf, int size) | |||
260 | static int initialized = 0; | 260 | static int initialized = 0; |
261 | 261 | ||
262 | if (fd != 0) | 262 | if (fd != 0) |
263 | die("wincon_read is for stdin only"); | 263 | bb_error_msg_and_die("wincon_read is for stdin only"); |
264 | if (cin == INVALID_HANDLE_VALUE || is_cygwin_tty(fd)) | 264 | if (cin == INVALID_HANDLE_VALUE || is_cygwin_tty(fd)) |
265 | return safe_read(fd, buf, size); | 265 | return safe_read(fd, buf, size); |
266 | if (!initialized) { | 266 | if (!initialized) { |
diff --git a/libbb/usage.c b/libbb/usage.c deleted file mode 100644 index 86bf68e21..000000000 --- a/libbb/usage.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* | ||
2 | * GIT - The information manager from hell | ||
3 | * | ||
4 | * Copyright (C) Linus Torvalds, 2005 | ||
5 | */ | ||
6 | #include "libbb.h" | ||
7 | #include "git.h" | ||
8 | |||
9 | static void report(const char *prefix, const char *err, va_list params) | ||
10 | { | ||
11 | char msg[1024]; | ||
12 | vsnprintf(msg, sizeof(msg), err, params); | ||
13 | fprintf(stderr, "%s%s\n", prefix, msg); | ||
14 | } | ||
15 | |||
16 | static NORETURN void usage_builtin(const char *err) | ||
17 | { | ||
18 | fprintf(stderr, "usage: %s\n", err); | ||
19 | exit(129); | ||
20 | } | ||
21 | |||
22 | static NORETURN void die_builtin(const char *err, va_list params) | ||
23 | { | ||
24 | report("fatal: ", err, params); | ||
25 | exit(128); | ||
26 | } | ||
27 | |||
28 | static void error_builtin(const char *err, va_list params) | ||
29 | { | ||
30 | report("error: ", err, params); | ||
31 | } | ||
32 | |||
33 | static void warn_builtin(const char *warn, va_list params) | ||
34 | { | ||
35 | report("warning: ", warn, params); | ||
36 | } | ||
37 | |||
38 | /* If we are in a dlopen()ed .so write to a global variable would segfault | ||
39 | * (ugh), so keep things static. */ | ||
40 | static void (*usage_routine)(const char *err) NORETURN = usage_builtin; | ||
41 | static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin; | ||
42 | static void (*error_routine)(const char *err, va_list params) = error_builtin; | ||
43 | static void (*warn_routine)(const char *err, va_list params) = warn_builtin; | ||
44 | |||
45 | void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN) | ||
46 | { | ||
47 | die_routine = routine; | ||
48 | } | ||
49 | |||
50 | void usage(const char *err) | ||
51 | { | ||
52 | usage_routine(err); | ||
53 | } | ||
54 | |||
55 | void die(const char *err, ...) | ||
56 | { | ||
57 | va_list params; | ||
58 | |||
59 | va_start(params, err); | ||
60 | die_routine(err, params); | ||
61 | va_end(params); | ||
62 | } | ||
63 | |||
64 | int error(const char *err, ...) | ||
65 | { | ||
66 | va_list params; | ||
67 | |||
68 | va_start(params, err); | ||
69 | error_routine(err, params); | ||
70 | va_end(params); | ||
71 | return -1; | ||
72 | } | ||
73 | |||
74 | void warning(const char *warn, ...) | ||
75 | { | ||
76 | va_list params; | ||
77 | |||
78 | va_start(params, warn); | ||
79 | warn_routine(warn, params); | ||
80 | va_end(params); | ||
81 | } | ||