void makedevs_main()
{
- int value, fd = 0, line_no, i;
+ int fd = 0, line_no, i;
char *line = NULL;
// Open file and chdir, verbosely
xprintf("rootdir = %s\n", *toys.optargs);
if (toys.optflags & FLAG_d && strcmp(TT.fname, "-")) {
- fd = xopen(TT.fname, O_RDONLY);
+ fd = xopenro(TT.fname);
xprintf("table = %s\n", TT.fname);
} else xprintf("table = <stdin>\n");
xchdir(*toys.optargs);
continue;
} else mode |= (mode_t[]){S_IFIFO, S_IFCHR, S_IFBLK, 0, 0}[i];
- if (*user) {
- struct passwd *usr;
-
- if (!(usr = getpwnam(user)) && isdigit(*user)) {
- sscanf(user, "%u", &value);
- usr = xgetpwuid(value);
- }
- if (!usr) error_exit("bad user '%s'", user);
- uid = usr->pw_uid;
- } else uid = getuid();
-
- if (*group) {
- struct group *grp;
-
- if (!(grp = getgrnam(group)) && isdigit(*group)) {
- sscanf (group, "%u", &value);
- grp = getgrgid(value);
- }
- if (!grp) error_exit("bad group '%s'", group);
- gid = grp->gr_gid;
- } else gid = getgid();
+ uid = *user ? xgetuid(user) : getuid();
+ gid = *group ? xgetgid(group) : getgid();
while (*node == '/') node++; // using relative path
for (i = 0; (!cnt && !i) || i < cnt; i++) {
- if (cnt) {
- snprintf(toybuf, sizeof(toybuf), "%s%u", node, st_val + i);
+ if (cnt>1) {
+ snprintf(toybuf, sizeof(toybuf), "%.999s%u", node, st_val + i);
ptr = toybuf;
} else ptr = node;
perror_msg("line %d: file '%s' does not exist", line_no, ptr);
continue;
}
- } else if (mknod(ptr, mode, makedev(major, minor + i*incr))) {
+ } else if (mknod(ptr, mode, dev_makedev(major, minor + i*incr))) {
perror_msg("line %d: can't create node '%s'", line_no, ptr);
continue;
}