Use preprocessor conditionals to check if makedev() is present

makedev() is not portable and is typically implemented as a
macro.  If it exists use it, otherwise silently ignore character
and block devices.
This commit is contained in:
sin 2014-01-28 16:54:41 +00:00
parent 203b52c38a
commit c83aef2cda
1 changed files with 2 additions and 0 deletions

2
tar.c
View File

@ -245,12 +245,14 @@ unarchive(char *fname, int l, char b[Blksiz])
break; break;
case CHARDEV: case CHARDEV:
case BLOCKDEV: case BLOCKDEV:
#ifdef makedev
mode = strtoul(h->mode, 0, 8); mode = strtoul(h->mode, 0, 8);
major = strtoul(h->major, 0, 8); major = strtoul(h->major, 0, 8);
minor = strtoul(h->mode, 0, 8); minor = strtoul(h->mode, 0, 8);
type = (h->type == CHARDEV) ? S_IFCHR : S_IFBLK; type = (h->type == CHARDEV) ? S_IFCHR : S_IFBLK;
if(mknod(fname, type | mode, makedev(major, minor))) if(mknod(fname, type | mode, makedev(major, minor)))
perror(fname); perror(fname);
#endif
break; break;
case FIFO: case FIFO:
mode = strtoul(h->mode, 0, 8); mode = strtoul(h->mode, 0, 8);