]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/fileutils.h
2 * No copyright is claimed. This code is in the public domain; do with
5 #ifndef UTIL_LINUX_FILEUTILS
6 #define UTIL_LINUX_FILEUTILS
16 extern int mkstemp_cloexec(char *template);
18 extern int xmkstemp(char **tmpname
, const char *dir
, const char *prefix
);
20 static inline FILE *xfmkstemp(char **tmpname
, const char *dir
, const char *prefix
)
25 fd
= xmkstemp(tmpname
, dir
, prefix
);
29 if (!(ret
= fdopen(fd
, "w+" UL_CLOEXECSTR
))) {
37 static inline FILE *fopen_at(int dir
, const char *filename
,
38 int flags
, const char *mode
)
40 int fd
= openat(dir
, filename
, flags
);
46 ret
= fdopen(fd
, mode
);
53 static inline int is_same_inode(const int fd
, const struct stat
*st
)
57 if (fstat(fd
, &f
) < 0)
59 else if (f
.st_dev
!= st
->st_dev
|| f
.st_ino
!= st
->st_ino
)
64 extern int dup_fd_cloexec(int oldfd
, int lowfd
);
65 extern unsigned int get_fd_tabsize(void);
67 extern int ul_mkdir_p(const char *path
, mode_t mode
);
68 extern char *stripoff_last_component(char *path
);
70 /* This is readdir()-like function, but skips "." and ".." directory entries */
71 static inline struct dirent
*xreaddir(DIR *dp
)
75 while ((d
= readdir(dp
))) {
76 if (!strcmp(d
->d_name
, ".") ||
77 !strcmp(d
->d_name
, ".."))
85 #ifdef HAVE_SYS_SYSCALL_H
86 # include <sys/syscall.h>
88 # if !defined(HAVE_CLOSE_RANGE) && defined(SYS_close_range)
89 # include <sys/types.h>
90 static inline int close_range(unsigned int first
, unsigned int last
, int flags
)
92 return syscall(SYS_close_range
, first
, last
, flags
);
94 # define HAVE_CLOSE_RANGE 1
95 # endif /* SYS_close_range */
97 # if !defined(HAVE_STATX) && defined(HAVE_STRUCT_STATX) && defined(SYS_statx)
98 static inline int statx(int fd
, const char *restrict path
, int flags
,
99 unsigned int mask
, struct statx
*stx
)
101 return syscall(SYS_statx
, fd
, path
, flags
, mask
, stx
);
103 # define HAVE_STATX 1
104 # endif /* SYS_statx */
106 #endif /* HAVE_SYS_SYSCALL_H */
109 extern void ul_close_all_fds(unsigned int first
, unsigned int last
);
111 #define UL_COPY_READ_ERROR (-1)
112 #define UL_COPY_WRITE_ERROR (-2)
113 int ul_copy_file(int from
, int to
);
116 extern int ul_reopen(int fd
, int flags
);
118 #endif /* UTIL_LINUX_FILEUTILS */