-
Notifications
You must be signed in to change notification settings - Fork 0
/
__openat_2.c
58 lines (44 loc) · 1.1 KB
/
__openat_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright 2021-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <dlfcn.h>
#include <fcntl.h>
#include "iamroot.h"
#ifdef __GLIBC__
static int (*sym)(int, const char *, int);
hidden int next___openat_2(int dfd, const char *path, int oflags)
{
if (!sym)
sym = dlsym(RTLD_NEXT, "__openat_2");
if (!sym)
return __dl_set_errno_and_perror(ENOSYS, -1);
return sym(dfd, path, oflags);
}
int __openat_2(int dfd, const char *path, int oflags)
{
const int errno_save = errno;
int atflags = 0, ret = -1;
char buf[PATH_MAX];
ssize_t siz;
if (oflags & O_NOFOLLOW)
atflags = AT_SYMLINK_NOFOLLOW;
siz = path_resolution(dfd, path, buf, sizeof(buf), atflags);
if (siz == -1)
goto exit;
ret = next___openat_2(dfd, buf, oflags);
if (ret >= 0 && __setfd(ret, buf))
errno = errno_save;
exit:
__debug("%s(dfd: %i <-> '%s', path: '%s' -> '%s', oflags: 0%o) -> %i\n",
__func__, dfd, __fpath(dfd), path, buf, oflags, ret);
return ret;
}
#ifdef _LARGEFILE64_SOURCE
weak_alias(__openat_2, __openat64_2);
#endif
#endif