]>
Commit | Line | Data |
---|---|---|
6b79eb38 SK |
1 | #ifndef UTIL_LINUX_FILEUTILS |
2 | #define UTIL_LINUX_FILEUTILS | |
3 | ||
372112e9 KZ |
4 | #include <stdio.h> |
5 | #include <fcntl.h> | |
6 | #include <unistd.h> | |
3f684db0 | 7 | #include <sys/stat.h> |
372112e9 KZ |
8 | |
9 | #include "c.h" | |
10 | ||
4d751c00 RM |
11 | extern int mkstemp_cloexec(char *template); |
12 | ||
bde91c85 | 13 | extern int xmkstemp(char **tmpname, const char *dir, const char *prefix); |
6b79eb38 | 14 | |
bde91c85 | 15 | static inline FILE *xfmkstemp(char **tmpname, const char *dir, const char *prefix) |
7961acce SK |
16 | { |
17 | int fd; | |
18 | FILE *ret; | |
f272b32c | 19 | |
bde91c85 | 20 | fd = xmkstemp(tmpname, dir, prefix); |
f272b32c | 21 | if (fd == -1) |
7961acce | 22 | return NULL; |
f272b32c | 23 | |
7e3729e7 | 24 | if (!(ret = fdopen(fd, "w+" UL_CLOEXECSTR))) { |
7961acce SK |
25 | close(fd); |
26 | return NULL; | |
27 | } | |
28 | return ret; | |
29 | } | |
be92327e | 30 | |
dc049516 | 31 | #ifdef HAVE_OPENAT |
1a048dc5 RM |
32 | static inline FILE *fopen_at(int dir, const char *filename, |
33 | int flags, const char *mode) | |
34 | { | |
35 | int fd = openat(dir, filename, flags); | |
36 | if (fd < 0) | |
37 | return NULL; | |
38 | ||
39 | return fdopen(fd, mode); | |
40 | } | |
dc049516 | 41 | #endif |
1a048dc5 | 42 | |
3f684db0 SK |
43 | static inline int is_same_inode(const int fd, const struct stat *st) |
44 | { | |
45 | struct stat f; | |
46 | ||
47 | if (fstat(fd, &f) < 0) | |
48 | return 0; | |
49 | else if (f.st_dev != st->st_dev || f.st_ino != st->st_ino) | |
50 | return 0; | |
51 | return 1; | |
52 | } | |
53 | ||
8e86d93d | 54 | extern int dup_fd_cloexec(int oldfd, int lowfd); |
be92327e KZ |
55 | extern int get_fd_tabsize(void); |
56 | ||
934530c7 | 57 | extern int mkdir_p(const char *path, mode_t mode); |
d4eaabc8 | 58 | extern char *stripoff_last_component(char *path); |
934530c7 | 59 | |
be92327e | 60 | #endif /* UTIL_LINUX_FILEUTILS */ |