1 /* @(#)symlinkat.c 1.3 13/10/30 Copyright 2013 J. Schilling */
2 /*
3 * Emulate the behavior of symlinkat(const char *content, int fd, const char *name)
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 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_SYMLINKAT
40 #ifndef HAVE_SYMLINK
41 /* ARGSUSED */
42 EXPORT int
symlinkat(content,fd,name)43 symlinkat(content, fd, name)
44 const char *content;
45 int fd;
46 const char *name;
47 {
48 #ifdef ENOSYS
49 seterrno(ENOSYS);
50 #else
51 seterrno(EINVAL);
52 #endif
53 return (-1);
54 }
55 #else
56
57 EXPORT int rev_symlink __PR((const char *name, const char *content));
58 EXPORT int rev_symlinkat __PR((int fd, const char *name, const char *content));
59
60 EXPORT int
rev_symlink(name,content)61 rev_symlink(name, content)
62 const char *name;
63 const char *content;
64 {
65 return (symlink(content, name));
66 }
67
68 /* CSTYLED */
69 #define PROTO_DECL , const char *content
70 #define KR_DECL const char *content;
71 /* CSTYLED */
72 #define KR_ARGS , content
73 #define FUNC_CALL(n) rev_symlink(n, content)
74 #define FLAG_CHECK()
75 #define FUNC_NAME rev_symlinkat
76 #define FUNC_RESULT int
77
78 #include "at-base.c"
79
80 EXPORT int
symlinkat(content,fd,name)81 symlinkat(content, fd, name)
82 const char *content;
83 int fd;
84 const char *name;
85 {
86 return (rev_symlinkat(fd, name, content));
87 }
88
89 #endif /* HAVE_SYMLINK */
90 #endif /* HAVE_SYMLINKAT */
91