mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-27 08:00:11 +00:00
Finally use strtoul() to convert the major an minor numbers, so
proper error-checking can be done, and octal and hexadecimal numbers are allowed.
This commit is contained in:
parent
bf6dfc7b35
commit
ce6bb53745
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17302
@ -90,6 +90,13 @@ the node corresponds to on the device; for example,
|
||||
a subunit may be a filesystem partition
|
||||
or a tty line.
|
||||
.El
|
||||
.Pp
|
||||
Major and minor device numbers can be given using the normal C
|
||||
notation, so that a leading
|
||||
.Ql 0x
|
||||
indicates a hexadecimal number, and a leading
|
||||
.Ql 0
|
||||
will cause the number to be interpreted as octal.
|
||||
.Sh SEE ALSO
|
||||
.Xr mknod 2 ,
|
||||
.Xr MAKEDEV 8
|
||||
|
@ -54,7 +54,8 @@ main(argc, argv)
|
||||
{
|
||||
extern int errno;
|
||||
u_short mode;
|
||||
char *strerror();
|
||||
u_int32_t major, minor;
|
||||
char *endp;
|
||||
|
||||
if (argc != 5) {
|
||||
(void)fprintf(stderr,
|
||||
@ -73,7 +74,20 @@ main(argc, argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (mknod(argv[1], mode, makedev(atoi(argv[3]), atoi(argv[4]))) < 0) {
|
||||
major = strtoul(argv[3], &endp, 0);
|
||||
if (*endp != '\0' || major >= 256) {
|
||||
(void)fprintf(stderr,
|
||||
"mknod: bad major number.\n");
|
||||
exit(1);
|
||||
}
|
||||
minor = strtoul(argv[4], &endp, 0);
|
||||
if (*endp != '\0') {
|
||||
(void)fprintf(stderr,
|
||||
"mknod: bad minor number.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (mknod(argv[1], mode, makedev(major, minor)) < 0) {
|
||||
(void)fprintf(stderr,
|
||||
"mknod: %s: %s\n", argv[1], strerror(errno));
|
||||
exit(1);
|
||||
|
Loading…
Reference in New Issue
Block a user