X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=toys%2Fother%2Fmakedevs.c;h=5e6a9822e411b4ce8652cfc6d0cb72dafd3052ab;hb=3d64b0cc95c5957e53474c3e50f143c61a057104;hp=f6e7ece95d411be47aab9f06c74234b8e99fd063;hpb=9bf93edd68742bbc9e814ec49c8a3a31ca8d3fff;p=android-x86%2Fexternal-toybox.git diff --git a/toys/other/makedevs.c b/toys/other/makedevs.c index f6e7ece9..5e6a9822 100644 --- a/toys/other/makedevs.c +++ b/toys/other/makedevs.c @@ -41,13 +41,13 @@ GLOBALS( 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 = \n"); xchdir(*toys.optargs); @@ -78,33 +78,14 @@ void makedevs_main() 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; @@ -118,7 +99,7 @@ void makedevs_main() 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; }