diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-06 18:50:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-06 18:50:05 +0200 |
commit | f8d8aa1cea915ce115345e6e729eddc80e86f021 (patch) | |
tree | abceef94710d221816cf56343b7cadf10de50e5c | |
parent | 87fb72032e6aa6abe5ac8fb05d22f43e8dde557b (diff) | |
download | busybox-w32-f8d8aa1cea915ce115345e6e729eddc80e86f021.tar.gz busybox-w32-f8d8aa1cea915ce115345e6e729eddc80e86f021.tar.bz2 busybox-w32-f8d8aa1cea915ce115345e6e729eddc80e86f021.zip |
libbb: add skip_dev_pfx()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | e2fsprogs/fsck.c | 8 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | init/init.c | 4 | ||||
-rw-r--r-- | libbb/skip_whitespace.c | 7 | ||||
-rw-r--r-- | libbb/utmp.c | 8 | ||||
-rw-r--r-- | loginutils/login.c | 4 | ||||
-rw-r--r-- | util-linux/rtcwake.c | 5 |
7 files changed, 17 insertions, 21 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 0192f3cdb..7c449e3e7 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
@@ -169,12 +169,12 @@ static char *base_device(const char *device) | |||
169 | const char *disk; | 169 | const char *disk; |
170 | int len; | 170 | int len; |
171 | #endif | 171 | #endif |
172 | cp = str = xstrdup(device); | 172 | str = xstrdup(device); |
173 | 173 | ||
174 | /* Skip over /dev/; if it's not present, give up. */ | 174 | /* Skip over "/dev/"; if it's not present, give up */ |
175 | if (strncmp(cp, "/dev/", 5) != 0) | 175 | cp = skip_dev_pfx(str); |
176 | if (cp == str) | ||
176 | goto errout; | 177 | goto errout; |
177 | cp += 5; | ||
178 | 178 | ||
179 | /* | 179 | /* |
180 | * For md devices, we treat them all as if they were all | 180 | * For md devices, we treat them all as if they were all |
diff --git a/include/libbb.h b/include/libbb.h index 357571fd8..976120e72 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -263,6 +263,8 @@ extern void chomp(char *s) FAST_FUNC; | |||
263 | extern void trim(char *s) FAST_FUNC; | 263 | extern void trim(char *s) FAST_FUNC; |
264 | extern char *skip_whitespace(const char *) FAST_FUNC; | 264 | extern char *skip_whitespace(const char *) FAST_FUNC; |
265 | extern char *skip_non_whitespace(const char *) FAST_FUNC; | 265 | extern char *skip_non_whitespace(const char *) FAST_FUNC; |
266 | extern char *skip_dev_pfx(const char *tty_name) FAST_FUNC; | ||
267 | |||
266 | extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC; | 268 | extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC; |
267 | 269 | ||
268 | //TODO: supply a pointer to char[11] buffer (avoid statics)? | 270 | //TODO: supply a pointer to char[11] buffer (avoid statics)? |
diff --git a/init/init.c b/init/init.c index 481f55167..2eb8f1a54 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -568,9 +568,7 @@ static void parse_inittab(void) | |||
568 | goto bad_entry; | 568 | goto bad_entry; |
569 | /* turn .*TTY -> /dev/TTY */ | 569 | /* turn .*TTY -> /dev/TTY */ |
570 | if (tty[0]) { | 570 | if (tty[0]) { |
571 | if (strncmp(tty, "/dev/", 5) == 0) | 571 | tty = concat_path_file("/dev/", skip_dev_pfx(tty)); |
572 | tty += 5; | ||
573 | tty = concat_path_file("/dev/", tty); | ||
574 | } | 572 | } |
575 | new_init_action(1 << action, token[3], tty); | 573 | new_init_action(1 << action, token[3], tty); |
576 | if (tty[0]) | 574 | if (tty[0]) |
diff --git a/libbb/skip_whitespace.c b/libbb/skip_whitespace.c index 7b123261b..f5a61a3cf 100644 --- a/libbb/skip_whitespace.c +++ b/libbb/skip_whitespace.c | |||
@@ -30,3 +30,10 @@ char* FAST_FUNC skip_non_whitespace(const char *s) | |||
30 | 30 | ||
31 | return (char *) s; | 31 | return (char *) s; |
32 | } | 32 | } |
33 | |||
34 | char* FAST_FUNC skip_dev_pfx(const char *tty_name) | ||
35 | { | ||
36 | if (strncmp(tty_name, "/dev/", 5) == 0) | ||
37 | tty_name += 5; | ||
38 | return (char*)tty_name; | ||
39 | } | ||
diff --git a/libbb/utmp.c b/libbb/utmp.c index d6ba336e3..68c358e9a 100644 --- a/libbb/utmp.c +++ b/libbb/utmp.c | |||
@@ -15,14 +15,6 @@ static void touch(const char *filename) | |||
15 | close(open(filename, O_WRONLY | O_CREAT, 0664)); | 15 | close(open(filename, O_WRONLY | O_CREAT, 0664)); |
16 | } | 16 | } |
17 | 17 | ||
18 | // TODO: move to libbb | ||
19 | static const char* skip_dev_pfx(const char *tty_name) | ||
20 | { | ||
21 | if (strncmp(tty_name, "/dev/", 5) == 0) | ||
22 | tty_name += 5; | ||
23 | return tty_name; | ||
24 | } | ||
25 | |||
26 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname) | 18 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname) |
27 | { | 19 | { |
28 | struct utmp utent; | 20 | struct utmp utent; |
diff --git a/loginutils/login.c b/loginutils/login.c index bf21d6121..078cd68ed 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -249,9 +249,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
249 | full_tty = xmalloc_ttyname(STDIN_FILENO); | 249 | full_tty = xmalloc_ttyname(STDIN_FILENO); |
250 | if (!full_tty) | 250 | if (!full_tty) |
251 | full_tty = xstrdup("UNKNOWN"); | 251 | full_tty = xstrdup("UNKNOWN"); |
252 | short_tty = full_tty; | 252 | short_tty = skip_dev_pfx(full_tty); |
253 | if (strncmp(full_tty, "/dev/", 5) == 0) | ||
254 | short_tty += 5; | ||
255 | 253 | ||
256 | if (opt_host) { | 254 | if (opt_host) { |
257 | fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host); | 255 | fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host); |
diff --git a/util-linux/rtcwake.c b/util-linux/rtcwake.c index 66b08e343..b16376655 100644 --- a/util-linux/rtcwake.c +++ b/util-linux/rtcwake.c | |||
@@ -35,9 +35,8 @@ static NOINLINE bool may_wakeup(const char *rtcname) | |||
35 | ssize_t ret; | 35 | ssize_t ret; |
36 | char buf[128]; | 36 | char buf[128]; |
37 | 37 | ||
38 | /* strip the '/dev/' from the rtcname here */ | 38 | /* strip "/dev/" from the rtcname here */ |
39 | if (!strncmp(rtcname, "/dev/", 5)) | 39 | rtcname = skip_dev_pfx(rtcname); |
40 | rtcname += 5; | ||
41 | 40 | ||
42 | snprintf(buf, sizeof(buf), SYS_RTC_PATH, rtcname); | 41 | snprintf(buf, sizeof(buf), SYS_RTC_PATH, rtcname); |
43 | ret = open_read_close(buf, buf, sizeof(buf)); | 42 | ret = open_read_close(buf, buf, sizeof(buf)); |