]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/fileutils.h
1 #ifndef UTIL_LINUX_FILEUTILS
2 #define UTIL_LINUX_FILEUTILS
12 extern int mkstemp_cloexec(char *template);
14 extern int xmkstemp(char **tmpname
, const char *dir
, const char *prefix
);
16 static inline FILE *xfmkstemp(char **tmpname
, const char *dir
, const char *prefix
)
21 fd
= xmkstemp(tmpname
, dir
, prefix
);
25 if (!(ret
= fdopen(fd
, "w+" UL_CLOEXECSTR
))) {
33 static inline FILE *fopen_at(int dir
, const char *filename
,
34 int flags
, const char *mode
)
36 int fd
= openat(dir
, filename
, flags
);
40 return fdopen(fd
, mode
);
44 static inline int is_same_inode(const int fd
, const struct stat
*st
)
48 if (fstat(fd
, &f
) < 0)
50 else if (f
.st_dev
!= st
->st_dev
|| f
.st_ino
!= st
->st_ino
)
55 extern int dup_fd_cloexec(int oldfd
, int lowfd
);
56 extern int get_fd_tabsize(void);
58 extern int mkdir_p(const char *path
, mode_t mode
);
59 extern char *stripoff_last_component(char *path
);
61 /* This is readdir()-like function, but skips "." and ".." directory entries */
62 static inline struct dirent
*xreaddir(DIR *dp
)
66 while ((d
= readdir(dp
))) {
67 if (!strcmp(d
->d_name
, ".") ||
68 !strcmp(d
->d_name
, ".."))
75 #endif /* UTIL_LINUX_FILEUTILS */