1 /* @(#)readlinkat.c 1.2 13/10/30 Copyright 2013 J. Schilling */
2 /*
3 * Emulate the behavior of readlinkat(int fd, const char *name, char *lbuf, size_t lbufsize)
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_READLINKAT
40 #ifndef HAVE_READLINK
41 /* ARGSUSED */
42 EXPORT ssize_t
readlinkat(fd,name,lbuf,lbufsize)43 readlinkat(fd, name, lbuf, lbufsize)
44 int fd;
45 const char *name;
46 char *lbuf;
47 size_t lbufsize;
48 {
49 #ifdef ENOSYS
50 seterrno(ENOSYS);
51 #else
52 seterrno(EINVAL);
53 #endif
54 return (-1);
55 }
56 #else
57
58 /* CSTYLED */
59 #define PROTO_DECL , char *lbuf, size_t lbufsize
60 #define KR_DECL char *lbuf; size_t lbufsize;
61 /* CSTYLED */
62 #define KR_ARGS , lbuf, lbufsize
63 #define FUNC_CALL(n) readlink(n, lbuf, lbufsize)
64 #define FLAG_CHECK()
65 #define FUNC_NAME readlinkat
66 #define FUNC_RESULT ssize_t
67
68 #include "at-base.c"
69
70 #endif /* HAVE_READLINK */
71 #endif /* HAVE_READLINKAT */
72