Merge remote-tracking branch 'origin/truncate-n-mkfifo'
This commit is contained in:
@@ -13,6 +13,7 @@ EXPECT_NAMES=\
|
||||
fcntl/create \
|
||||
fcntl/fcntl \
|
||||
fnmatch \
|
||||
futimens \
|
||||
libgen \
|
||||
locale \
|
||||
math \
|
||||
@@ -102,6 +103,8 @@ EXPECT_NAMES=\
|
||||
wchar/wcstod \
|
||||
wchar/wcstok \
|
||||
wchar/wcstol
|
||||
# TODO: Fix these
|
||||
# mkfifo
|
||||
|
||||
# Binaries that may generate varied output
|
||||
NAMES=\
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
char temp[] = "/tmp/stattest-XXXXXX";
|
||||
const char file[] = "/mkfifo_fifo";
|
||||
int len = sizeof(temp) + sizeof(int);
|
||||
char* path = malloc(len * sizeof(char));
|
||||
|
||||
if (path == NULL) {
|
||||
fprintf(stderr, "Could not allocate: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
strncat(path, mktemp(temp), sizeof(temp));
|
||||
strncat(path, file, sizeof(file));
|
||||
if (mkdir(temp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
fprintf(stderr, "mkdir %s: %s\n", temp, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int tmp = open(path, O_CREAT | O_CLOEXEC | O_RDONLY | S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (tmp == -1) {
|
||||
fprintf(stderr, "touch %s: %s\n", path, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (close(tmp) == -1) {
|
||||
fprintf(stderr, "close %s: %s\n", path, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int fd = open(path, 0, 0);
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "open %s: %s\n", path, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const struct timespec times[] = { { .tv_sec = 10 }, { .tv_sec = 20 } };
|
||||
if (futimens(fd, times) == -1) {
|
||||
fprintf(stderr, "futimens: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct stat sb;
|
||||
if (stat(path, &sb) != 0) {
|
||||
fprintf(stderr, "stat: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (sb.st_mtim.tv_sec != 20 || sb.st_mtim.tv_nsec != 0) {
|
||||
fprintf(stderr, "Wrong modified time: %d.%d\n", sb.st_mtim.tv_sec, sb.st_mtim.tv_nsec);
|
||||
exit(1);
|
||||
}
|
||||
// Access times are not flushed to disk, so this check can't be (currently) performed
|
||||
/*
|
||||
* if (sb.st_atim.tv_sec != 10 || sb.st_atim.tv_nsec != 0) {
|
||||
* fprintf(stderr, "Wrong accessed time: %d.%d\n", sb.st_atim.tv_sec, sb.st_atim.tv_nsec);
|
||||
* exit(1);
|
||||
* }
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
char temp[] = "/tmp/stattest-XXXXXX";
|
||||
const char file[] = "/mkfifo_fifo";
|
||||
int len = sizeof(temp) + sizeof(file);
|
||||
char* path = malloc(len * sizeof(char));
|
||||
|
||||
if (path == NULL) {
|
||||
fprintf(stderr, "Could not allocate: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
path = strncat(path, mktemp(temp), sizeof(temp));
|
||||
path = strncat(path, file, sizeof(file));
|
||||
if (mkdir(temp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
fprintf(stderr, "mkdir %s: %s\n", temp, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (mkfifo(path, S_IRUSR) == -1) {
|
||||
fprintf(stderr, "mkfifo %s: %s\n", path, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
struct stat sb;
|
||||
if (stat(path, &sb) != 0) {
|
||||
fprintf(stderr, "stat: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (!(sb.st_mode & S_IFIFO)) {
|
||||
fprintf(stderr, "Not a FIFO: %d\n", sb.st_mode);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,8 @@ int main(void) {
|
||||
int c = close(fd);
|
||||
ERROR_IF(close, c, == -1);
|
||||
UNEXP_IF(close, c, != 0);
|
||||
|
||||
status = truncate("ftruncate.out", 100);
|
||||
ERROR_IF(truncate, status, == -1);
|
||||
UNEXP_IF(truncate, status, != 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user