const char *disk;
int len;
#endif
- cp = str = xstrdup(device);
+ str = xstrdup(device);
- /* Skip over /dev/; if it's not present, give up. */
- if (strncmp(cp, "/dev/", 5) != 0)
+ /* Skip over "/dev/"; if it's not present, give up */
+ cp = skip_dev_pfx(str);
+ if (cp == str)
goto errout;
- cp += 5;
/*
* For md devices, we treat them all as if they were all
extern void trim(char *s) FAST_FUNC;
extern char *skip_whitespace(const char *) FAST_FUNC;
extern char *skip_non_whitespace(const char *) FAST_FUNC;
+extern char *skip_dev_pfx(const char *tty_name) FAST_FUNC;
+
extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC;
//TODO: supply a pointer to char[11] buffer (avoid statics)?
goto bad_entry;
/* turn .*TTY -> /dev/TTY */
if (tty[0]) {
- if (strncmp(tty, "/dev/", 5) == 0)
- tty += 5;
- tty = concat_path_file("/dev/", tty);
+ tty = concat_path_file("/dev/", skip_dev_pfx(tty));
}
new_init_action(1 << action, token[3], tty);
if (tty[0])
return (char *) s;
}
+
+char* FAST_FUNC skip_dev_pfx(const char *tty_name)
+{
+ if (strncmp(tty_name, "/dev/", 5) == 0)
+ tty_name += 5;
+ return (char*)tty_name;
+}
close(open(filename, O_WRONLY | O_CREAT, 0664));
}
-// TODO: move to libbb
-static const char* skip_dev_pfx(const char *tty_name)
-{
- if (strncmp(tty_name, "/dev/", 5) == 0)
- tty_name += 5;
- return tty_name;
-}
-
void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname)
{
struct utmp utent;
full_tty = xmalloc_ttyname(STDIN_FILENO);
if (!full_tty)
full_tty = xstrdup("UNKNOWN");
- short_tty = full_tty;
- if (strncmp(full_tty, "/dev/", 5) == 0)
- short_tty += 5;
+ short_tty = skip_dev_pfx(full_tty);
if (opt_host) {
fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host);
ssize_t ret;
char buf[128];
- /* strip the '/dev/' from the rtcname here */
- if (!strncmp(rtcname, "/dev/", 5))
- rtcname += 5;
+ /* strip "/dev/" from the rtcname here */
+ rtcname = skip_dev_pfx(rtcname);
snprintf(buf, sizeof(buf), SYS_RTC_PATH, rtcname);
ret = open_read_close(buf, buf, sizeof(buf));