]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/fileutils.h
su: change error message
[thirdparty/util-linux.git] / include / fileutils.h
CommitLineData
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
11extern int mkstemp_cloexec(char *template);
12
bde91c85 13extern int xmkstemp(char **tmpname, const char *dir, const char *prefix);
6b79eb38 14
bde91c85 15static 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
32static 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
43static 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 54extern int dup_fd_cloexec(int oldfd, int lowfd);
be92327e
KZ
55extern int get_fd_tabsize(void);
56
934530c7 57extern int mkdir_p(const char *path, mode_t mode);
d4eaabc8 58extern char *stripoff_last_component(char *path);
934530c7 59
be92327e 60#endif /* UTIL_LINUX_FILEUTILS */