1 /* @(#)fchmodat.c 1.2 14/06/03 Copyright 2014 J. Schilling */
2 /*
3 * Emulate the behavior of fchmodat(int fd, const char *name, mode_t mode, int flag)
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) 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/stat.h>
34 #include <schily/maxpath.h>
35 #include <schily/errno.h>
36 #include <schily/standard.h>
37 #include <schily/schily.h>
38 #include "at-defs.h"
39
40 #ifndef HAVE_FCHMODAT
41 #ifndef HAVE_CHMOD
42 /* ARGSUSED */
43 #ifdef PROTOTYPES
44 EXPORT int
fchmodat(int fd,const char * name,mode_t mode)45 fchmodat(int fd, const char *name, mode_t mode)
46 #else
47 EXPORT int
48 fchmodat(fd, name, mode)
49 int fd;
50 const char *name;
51 mode_t mode;
52 #endif
53 {
54 #ifdef ENOSYS
55 seterrno(ENOSYS);
56 #else
57 seterrno(EINVAL);
58 #endif
59 return (-1);
60 }
61 #else /* HAVE_CHMOD */
62
63 /* CSTYLED */
64 #define PROTO_DECL , mode_t mode, int flag
65 #define KR_DECL mode_t mode; int flag;
66 /* CSTYLED */
67 #define KR_ARGS , mode, flag
68 #define FUNC_CALL(n) (flag & AT_SYMLINK_NOFOLLOW ? \
69 lchmod(n, mode) : chmod(n, mode))
70 #define FLAG_CHECK() if (flag & ~(AT_SYMLINK_NOFOLLOW)) { \
71 seterrno(EINVAL); \
72 return (-1); \
73 }
74
75 #define FUNC_NAME fchmodat
76 #define FUNC_RESULT int
77
78 #include "at-base.c"
79
80 #endif /* HAVE_CHMOD */
81 #endif /* HAVE_FCHMODDAT */
82