1 /* Create a device inode.
2 Copyright (C) 2009-2025 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation, either version 3 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* written by Eric Blake */
27 /* Mingw lacks mknod; always fail with ENOSYS. */
30 mknod (_GL_UNUSED
char const *name
, _GL_UNUSED mode_t mode
,
37 #else /* HAVE_MKNOD */
41 /* Create a file system node FILE, with access permissions and file
42 type in MODE, and device type in DEV. Usually, non-root
43 applications can only create named fifos (mode includes S_IFIFO),
44 with DEV set to 0. Also work around trailing slash bugs. */
47 rpl_mknod (char const *name
, mode_t mode
, dev_t dev
)
49 # if MKFIFO_TRAILING_SLASH_BUG
50 /* Trailing slash only makes sense for directories. Of course,
51 using mknod to create a directory is not very portable, so it may
52 still fail later on. */
55 size_t len
= strlen (name
);
56 if (len
&& name
[len
- 1] == '/')
59 if (stat (name
, &st
) == 0 || errno
== EOVERFLOW
)
66 /* POSIX requires mknod to create fifos for non-privileged
67 processes, but BSD implementations fail with EPERM. */
68 if (S_ISFIFO (mode
) && dev
== 0)
69 return mkfifo (name
, mode
& ~S_IFIFO
);
71 return mknod (name
, mode
, dev
);
74 #endif /* HAVE_MKNOD */