]> git.cworth.org Git - tar/blob - gnu/mknod.c
Imported Upstream version 1.24
[tar] / gnu / mknod.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Create a device inode.
4    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 /* written by Eric Blake */
20
21 #include <config.h>
22
23 #include <sys/stat.h>
24
25 #include <errno.h>
26 #include <string.h>
27
28 #if !HAVE_MKNOD
29 /* Mingw lacks mknod; always fail with ENOSYS.  */
30
31 int
32 mknod (char const *name _GL_UNUSED, mode_t mode _GL_UNUSED,
33        dev_t dev _GL_UNUSED)
34 {
35   errno = ENOSYS;
36   return -1;
37 }
38
39 #else /* HAVE_MKNOD */
40
41 # undef mknod
42
43 /* Create a file system node FILE, with access permissions and file
44    type in MODE, and device type in DEV.  Usually, non-root
45    applications can only create named fifos (mode includes S_IFIFO),
46    with DEV set to 0.  Also work around trailing slash bugs.  */
47
48 int
49 rpl_mknod (char const *name, mode_t mode, dev_t dev)
50 {
51 # if MKFIFO_TRAILING_SLASH_BUG
52   /* Trailing slash only makes sense for directories.  Of course,
53      using mknod to create a directory is not very portable, so it may
54      still fail later on.  */
55   if (!S_ISDIR (mode))
56     {
57       size_t len = strlen (name);
58       if (len && name[len - 1] == '/')
59         {
60           struct stat st;
61           if (stat (name, &st) == 0)
62             errno = EEXIST;
63           return -1;
64         }
65     }
66 # endif
67 # if MKNOD_FIFO_BUG
68   /* POSIX requires mknod to create fifos for non-privileged
69      processes, but BSD implementations fail with EPERM.  */
70   if (S_ISFIFO (mode) && dev == 0)
71     return mkfifo (name, mode & ~S_IFIFO);
72 # endif
73   return mknod (name, mode, dev);
74 }
75
76 #endif /* HAVE_MKNOD */