]> Git Repo - qemu.git/blame - hw/9pfs/9p-util.h
9pfs: local: lgetxattr: don't follow symlinks
[qemu.git] / hw / 9pfs / 9p-util.h
CommitLineData
6482a961
GK
1/*
2 * 9p utilities
3 *
4 * Copyright IBM, Corp. 2017
5 *
6 * Authors:
7 * Greg Kurz <[email protected]>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12
13#ifndef QEMU_9P_UTIL_H
14#define QEMU_9P_UTIL_H
15
16static inline void close_preserve_errno(int fd)
17{
18 int serrno = errno;
19 close(fd);
20 errno = serrno;
21}
22
23static inline int openat_dir(int dirfd, const char *name)
24{
25 return openat(dirfd, name, O_DIRECTORY | O_RDONLY | O_PATH);
26}
27
28static inline int openat_file(int dirfd, const char *name, int flags,
29 mode_t mode)
30{
31 int fd, serrno, ret;
32
33 fd = openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK,
34 mode);
35 if (fd == -1) {
36 return -1;
37 }
38
39 serrno = errno;
40 /* O_NONBLOCK was only needed to open the file. Let's drop it. */
41 ret = fcntl(fd, F_SETFL, flags);
42 assert(!ret);
43 errno = serrno;
44 return fd;
45}
46
47int relative_openat_nofollow(int dirfd, const char *path, int flags,
48 mode_t mode);
56ad3e54
GK
49ssize_t fgetxattrat_nofollow(int dirfd, const char *path, const char *name,
50 void *value, size_t size);
6482a961
GK
51
52#endif
This page took 0.027161 seconds and 4 git commands to generate.