1 /* @(#)mknodat.c 1.4 14/05/01 Copyright 2013-2014 J. Schilling */
2 /*
3 * Emulate the behavior of mknodat(int fd, const char *name, mode_t mode, dev_t dev)
4 *
5 * Note that emulation methods that do not use the /proc filesystem are
6 * not MT safe. In the non-MT-safe case, we do:
7 *
8 * savewd()/fchdir()/open(name)/restorewd()
9 *
10 * Errors may force us to abort the program as our caller is not expected
11 * to know that we do more than a simple open() here and that the
12 * working directory may be changed by us.
13 *
14 * Copyright (c) 2013-2014 J. Schilling
15 */
16 /*
17 * The contents of this file are subject to the terms of the
18 * Common Development and Distribution License, Version 1.0 only
19 * (the "License"). You may not use this file except in compliance
20 * with the License.
21 *
22 * See the file CDDL.Schily.txt in this distribution for details.
23 * A copy of the CDDL is also available via the Internet at
24 * http://www.opensource.org/licenses/cddl1.txt
25 *
26 * When distributing Covered Code, include this CDDL HEADER in each
27 * file and include the License file CDDL.Schily.txt from this distribution.
28 */
29
30 #include <schily/unistd.h>
31 #include <schily/types.h>
32 #include <schily/fcntl.h>
33 #include <schily/maxpath.h>
34 #include <schily/errno.h>
35 #include <schily/standard.h>
36 #include <schily/schily.h>
37 #include "at-defs.h"
38
39 #ifndef HAVE_MKNODAT
40 #ifndef HAVE_MKNOD
41 /* ARGSUSED */
42 #ifdef PROTOTYPES
43 EXPORT int
mknodat(int fd,const char * name,mode_t mode,dev_t dev)44 mknodat(int fd, const char *name, mode_t mode, dev_t dev)
45 #else
46 EXPORT int
47 mknodat(fd, name, mode, dev)
48 int fd;
49 const char *name;
50 mode_t mode;
51 dev_t dev;
52 #endif
53 {
54 #ifdef ENOSYS
55 seterrno(ENOSYS);
56 #else
57 seterrno(EINVAL);
58 #endif
59 return (-1);
60 }
61 #else /* HAVE_MKNOD */
62
63 /* CSTYLED */
64 #define PROTO_DECL , mode_t mode, dev_t dev
65 #define KR_DECL mode_t mode; dev_t dev;
66 /* CSTYLED */
67 #define KR_ARGS , mode, dev
68 #define FUNC_CALL(n) mknod(n, mode, dev)
69 #define FLAG_CHECK()
70 #define FUNC_NAME mknodat
71 #define FUNC_RESULT int
72
73 #include "at-base.c"
74
75 #endif /* HAVE_MKNOD */
76 #endif /* HAVE_MKNODAT */
77