Merge "Add mkfifoat(3)."

This commit is contained in:
Elliott Hughes 2014-10-24 02:57:11 +00:00 committed by Gerrit Code Review
commit a4c0b75671
3 changed files with 21 additions and 1 deletions

View File

@ -28,6 +28,12 @@
#include <sys/stat.h>
#include <fcntl.h>
int mkfifo(const char* path, mode_t mode) {
return mknod(path, (mode & ~S_IFMT) | S_IFIFO, 0);
return mkfifoat(AT_FDCWD, path, mode);
}
int mkfifoat(int fd, const char* path, mode_t mode) {
return mknodat(fd, path, (mode & ~S_IFMT) | S_IFIFO, 0);
}

View File

@ -181,6 +181,7 @@ mode_t umask(mode_t mode) {
#endif /* defined(__BIONIC_FORTIFY) */
extern int mkfifo(const char*, mode_t);
extern int mkfifoat(int, const char*, mode_t);
extern int fchmodat(int, const char*, mode_t, int);
extern int mkdirat(int, const char*, mode_t);

View File

@ -55,6 +55,18 @@ TEST(sys_stat, futimens_EBADF) {
ASSERT_EQ(EBADF, errno);
}
TEST(sys_stat, mkfifo_failure) {
errno = 0;
ASSERT_EQ(-1, mkfifo("/", 0666));
ASSERT_EQ(EEXIST, errno);
}
TEST(sys_stat, mkfifoat_failure) {
errno = 0;
ASSERT_EQ(-1, mkfifoat(-2, "x", 0666));
ASSERT_EQ(EBADF, errno);
}
TEST(sys_stat, mkfifo) {
if (getuid() == 0) {
// Racy but probably sufficient way to get a suitable filename.
@ -70,6 +82,7 @@ TEST(sys_stat, mkfifo) {
ASSERT_TRUE(S_ISFIFO(sb.st_mode));
unlink(path.c_str());
} else {
// SELinux policy forbids us from creating FIFOs. http://b/17646702.
GTEST_LOG_(INFO) << "This test only performs a test when run as root.";
}
}