提交 e9e4016d 编写于 作者: D dhy308

add fault tolerant for getcwd()

Issue: I63QQ9
Test: libc-test pass
Signed-off-by: Ndhy308 <tony.gan@huawei.com>
上级 12c45ec0
......@@ -33,6 +33,10 @@ void readdir_r_0100(void)
{
char name[128] = {0};
char *cwd = getcwd(name, sizeof(name));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
DIR *dir = opendir(name);
if (dir == NULL) {
t_error("%s failed: opendir. name = %s\n", __func__, name);
......
......@@ -34,6 +34,11 @@ void rewinddir_0100(void)
{
char name[128] = {0};
char *cwd = getcwd(name, sizeof(name));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
DIR *dir = opendir(name);
if (dir == NULL) {
t_error("%s failed: opendir. name = %s\n", __func__, name);
......
......@@ -33,6 +33,11 @@ void scandir_0100(void)
struct dirent **namelist;
char name[128] = {0};
char *cwd = getcwd(name, sizeof(name));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
int n = scandir(name, &namelist, NULL, alphasort);
if (n < 0) {
t_error("%s failed: scandir. n = %d\n", __func__, n);
......@@ -55,6 +60,11 @@ void scandir_0200(void)
struct dirent **namelist;
char name[128] = {0};
char *cwd = getcwd(name, sizeof(name));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
int n = scandir(name, &namelist, NULL, versionsort);
if (n < 0) {
t_error("%s failed: scandir. n = %d\n", __func__, n);
......@@ -77,6 +87,11 @@ void scandir_0300(void)
struct dirent **namelist;
char name[128] = {0};
char *cwd = getcwd(name, sizeof(name));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
int n = scandir(name, &namelist, filter, versionsort);
if (n < 0) {
t_error("%s failed: scandir. n = %d\n", __func__, n);
......
......@@ -25,6 +25,10 @@ void ftok_0100(void)
{
char dir_path[128] = {0};
char *cwd = getcwd(dir_path, sizeof(dir_path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(dir_path, "/ftok");
key_t result = ftok(dir_path, 1);
EXPECT_NE("ftok_0100", result, -1);
......
......@@ -31,6 +31,10 @@ void semtimedop_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT);
......
......@@ -34,7 +34,15 @@ void copy_file_range_0100(void)
char path_in[128] = {0};
char path_out[128] = {0};
char *cwd = getcwd(path_in, sizeof(path_in));
if (!cwd) {
t_error("%s getcwd path_in failed\n", __func__);
return;
}
cwd = getcwd(path_out, sizeof(path_out));
if (!cwd) {
t_error("%s getcwd path_out failed\n", __func__);
return;
}
strcat(path_in, "/file_in.txt");
strcat(path_out, "/file_out.txt");
......@@ -115,7 +123,15 @@ void copy_file_range_0300(void)
char path_in[128] = {0};
char path_out[128] = {0};
char *cwd = getcwd(path_in, sizeof(path_in));
if (!cwd) {
t_error("%s getcwd path_in failed\n", __func__);
return;
}
cwd = getcwd(path_out, sizeof(path_out));
if (!cwd) {
t_error("%s getcwd path_out failed\n", __func__);
return;
}
strcat(path_in, "/file_in.txt");
strcat(path_out, "/file_out.txt");
......
......@@ -33,6 +33,10 @@ void removexattr_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT);
......
......@@ -31,7 +31,15 @@ void sendfile_0100(void)
char fromfile[128] = {0};
char tofile[128] = {0};
char *cwd = getcwd(fromfile, sizeof(fromfile));
if (!cwd) {
t_error("%s getcwd fromfile failed\n", __func__);
return;
}
cwd = getcwd(tofile, sizeof(tofile));
if (!cwd) {
t_error("%s getcwd tofile failed\n", __func__);
return;
}
strcat(fromfile, "/fromfile.txt");
strcat(tofile, "/tofile.txt");
......
......@@ -33,6 +33,10 @@ void setxattr_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT);
......
......@@ -33,7 +33,15 @@ void splice_0100(void)
char fromfile[128] = {0};
char tofile[128] = {0};
char *cwd = getcwd(fromfile, sizeof(fromfile));
if (!cwd) {
t_error("%s getcwd fromfile failed\n", __func__);
return;
}
cwd = getcwd(tofile, sizeof(tofile));
if (!cwd) {
t_error("%s getcwd tofile failed\n", __func__);
return;
}
strcat(fromfile, "/fromfile.txt");
strcat(tofile, "/tofile.txt");
......
......@@ -29,6 +29,10 @@ void swapoff_0100(void)
{
char dir_path[128] = {0};
char *cwd = getcwd(dir_path, sizeof(dir_path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
errno = 0;
char cmd[256] = {0};
......
......@@ -29,6 +29,10 @@ void swapon_0100(void)
{
char dir_path[128] = {0};
char *cwd = getcwd(dir_path, sizeof(dir_path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
errno = 0;
char cmd[256] = {0};
......
......@@ -29,6 +29,10 @@ void sync_file_range_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/sync_file_range.txt");
errno = 0;
......@@ -76,6 +80,10 @@ void sync_file_range_0300(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/sync_file_range.txt");
errno = 0;
......@@ -107,6 +115,10 @@ void sync_file_range_0400(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/sync_file_range.txt");
errno = 0;
......
......@@ -29,6 +29,10 @@ void syncfs_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/syncfs.txt");
errno = 0;
......
......@@ -76,6 +76,10 @@ void tee_0200(void)
char *text = "Hello";
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result;
......
......@@ -32,6 +32,10 @@ void mincore_0100(void)
struct stat st;
char pathname[128] = {0};
char *cwd = getcwd(pathname, sizeof(pathname));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(pathname, "/mincore");
int ret = stat(pathname, &st);
......
......@@ -30,6 +30,10 @@ void fchmodat_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test.txt");
int fd;
......@@ -56,6 +60,10 @@ void fchmodat_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test.txt");
int fd;
......
......@@ -86,6 +86,10 @@ void fstatat_0300(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/fstatattest.txt");
struct stat st;
......
......@@ -32,6 +32,10 @@ void lstat_0100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/stattest.txt");
const char str[] = "this is a sample!";
......@@ -55,6 +59,10 @@ void lstat_time64_0100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/stattest.txt");
const char str[] = "this is a sample!";
......@@ -91,7 +99,15 @@ void lstat_0300(void)
char ptr[128] = {0};
char ptrlink[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd file failed\n", __func__);
return;
}
cwd = getcwd(ptrlink, sizeof(ptrlink));
if (!cwd) {
t_error("%s getcwd link failed\n", __func__);
return;
}
strcat(ptr, "/tests.txt");
strcat(ptrlink, "/tests.txt.soft");
struct stat buf[3];
......
......@@ -27,6 +27,10 @@ void mknod_0100(void)
{
char pathname[128] = {0};
char *cwd = getcwd(pathname, sizeof(pathname));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(pathname, "/mknod");
int ret = mknod(pathname, TEST_MODE, 0);
......
......@@ -33,6 +33,10 @@ void utimensat_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT);
......@@ -85,6 +89,10 @@ void utimensat_time64_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT);
......
......@@ -27,6 +27,10 @@ void __fwritable_0100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
FILE *fptr = fopen(ptr, "w+");
......@@ -47,6 +51,10 @@ void __fwritable_0200(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
FILE *fptr = fopen(ptr, "r");
......
......@@ -31,6 +31,10 @@ void __fwriting_0100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
FILE *fptr = fopen(ptr, "w");
......@@ -49,6 +53,10 @@ void __fwriting_0200(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
const char *wrstring = "helloworld";
......@@ -69,6 +77,10 @@ void __fwriting_0300(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
char abc[100] = {0};
......
......@@ -24,6 +24,10 @@ void fputc_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/fputc.txt");
FILE *fptr = fopen(path, "w");
......@@ -41,6 +45,10 @@ void fputc_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/fputc.txt");
FILE *fptr = fopen(path, "r");
......
......@@ -25,6 +25,10 @@ void freopen_0100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/freopen.txt");
FILE *fp;
......
......@@ -28,6 +28,10 @@ void getline_0100(void)
size_t len = 0;
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test.txt");
FILE *fp = fopen(path, "w+");
......@@ -53,6 +57,10 @@ void getline_0200(void)
size_t len = 0;
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fp = fopen(path, "w+");
EXPECT_PTRNE("getline_0100", fp, NULL);
......@@ -74,6 +82,10 @@ void getline_0300(void)
char *line = NULL;
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fp = fopen(path, "w+");
EXPECT_PTRNE("getline_0100", fp, NULL);
......
......@@ -31,6 +31,10 @@ void setbuf_0100(void)
char buf[BUFSIZ] = {0};
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+");
errno = 0;
......@@ -60,6 +64,10 @@ void setbuf_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+");
......
......@@ -29,6 +29,10 @@ void setbuffer_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fp = fopen(path, "w+");
char buf[BUFSIZ] = {0};
......@@ -64,6 +68,10 @@ void setbuffer_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+");
......
......@@ -29,6 +29,10 @@ void setlinebuf_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+");
char buffer[BUFSIZ];
......
......@@ -25,6 +25,10 @@ void setvbuf_0100(void)
char buff[1024] = {0};
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fptr = fopen(path, "w+");
EXPECT_PTRNE("setvbuf_0100", fptr, NULL);
......@@ -46,6 +50,10 @@ void setvbuf_0200(void)
char buff[1024] = {0};
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fptr = fopen(path, "w+");
EXPECT_PTRNE("setvbuf_0100", fptr, NULL);
......
......@@ -34,6 +34,10 @@ void ungetwc_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *file = fopen(path, "a+");
if (!file) {
......
......@@ -39,6 +39,10 @@ void vfscanf_0100(void)
char buffer[BUFSIZ];
char file[128] = {0};
char *cwd = getcwd(file, sizeof(file));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(file, "/vfscanf.txt");
fp = fopen(file, "w+");
if (fp == NULL) {
......@@ -77,6 +81,10 @@ void vfscanf_0200(void)
char buffer[BUFSIZ];
char file[128] = {0};
char *cwd = getcwd(file, sizeof(file));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(file, "/vfscanf.txt");
fp = fopen(file, "w+");
if (fp == NULL) {
......@@ -115,6 +123,10 @@ void vfscanf_0300(void)
int val2 = 0;
char file[128] = {0};
char *cwd = getcwd(file, sizeof(file));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(file, "/vfscanf.txt");
fp = fopen(file, "w+");
if (fp == NULL) {
......
......@@ -37,6 +37,10 @@ void acct_0200(void)
{
char filePath[128] = {0};
char *cwd = getcwd(filePath, sizeof(filePath));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(filePath, "/accttest.txt");
int result = acct(filePath);
......
......@@ -26,6 +26,10 @@ void exit_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "cd %s; ./exittest01", path);
system(cmd);
......@@ -60,6 +64,10 @@ void exit_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "cd %s; ./exittest02", path);
system(cmd);
......
......@@ -31,6 +31,10 @@ void faccessat_0100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_0100", fd >= 0);
......@@ -49,6 +53,10 @@ void faccessat_0200(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = -1;
int isExist = faccessat(fd, ptr, F_OK, 0);
......@@ -66,6 +74,10 @@ void faccessat_0300(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00040);
EXPECT_TRUE("faccessat_0300", fd >= 0);
......@@ -84,6 +96,10 @@ void faccessat_0400(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00020);
EXPECT_TRUE("faccessat_0400", fd >= 0);
......@@ -102,6 +118,10 @@ void faccessat_0500(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00010);
char cmd[256] = {0};
......@@ -123,6 +143,10 @@ void faccessat_0600(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_0600", fd >= 0);
......@@ -141,6 +165,10 @@ void faccessat_0700(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00070);
EXPECT_TRUE("faccessat_0700", fd >= 0);
......@@ -159,6 +187,10 @@ void faccessat_0800(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_0800", fd >= 0);
......@@ -177,6 +209,10 @@ void faccessat_0900(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00070);
EXPECT_TRUE("faccessat_0900", fd >= 0);
......@@ -197,6 +233,10 @@ void faccessat_1000(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00070);
EXPECT_TRUE("faccessat_1000", fd >= 0);
......@@ -216,6 +256,10 @@ void faccessat_1100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_1100", fd >= 0);
......
......@@ -27,6 +27,10 @@ void fchownat_0100(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/fchownattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("fchownat_0100", fd >= 0);
......@@ -50,6 +54,10 @@ void fchownat_0200(void)
{
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/fchownattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("fchownat_0200", fd >= 0);
......
......@@ -28,6 +28,10 @@ void getpid_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/ps.txt");
char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "ps -eo command,pid | grep -E \"PID|getpid\" > %s", path);
......
......@@ -27,6 +27,10 @@ void lchown_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/lchown");
int ret = lchown(path, TEST_ID_VALUE, TEST_ID_VALUE);
EXPECT_EQ("lchown_0100", ret, CMPFLAG);
......
......@@ -54,6 +54,10 @@ void readlinkat_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd file failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = create_file(path);
if (result != 0) {
......@@ -63,6 +67,10 @@ void readlinkat_0100(void)
char linkpath[128] = {0};
cwd = getcwd(linkpath, sizeof(linkpath));
if (!cwd) {
t_error("%s getcwd link failed\n", __func__);
return;
}
strcat(linkpath, "/linkfile.txt");
remove(linkpath);
......@@ -101,6 +109,10 @@ void readlinkat_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd file failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = create_file(path);
if (result != 0) {
......@@ -110,6 +122,10 @@ void readlinkat_0200(void)
char dirname[128] = {0};
cwd = getcwd(dirname, sizeof(dirname));
if (!cwd) {
t_error("%s getcwd dir failed\n", __func__);
return;
}
DIR *dir = opendir(dirname);
if (dir == NULL) {
t_error("%s failed: dirname = %s\n", __func__, dirname);
......@@ -123,6 +139,10 @@ void readlinkat_0200(void)
char linkpath[128] = {0};
cwd = getcwd(linkpath, sizeof(linkpath));
if (!cwd) {
t_error("%s getcwd link failed\n", __func__);
return;
}
strcat(linkpath, "/linkfile.txt");
remove(linkpath);
......
......@@ -30,6 +30,10 @@ void readv_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT);
......
......@@ -35,6 +35,10 @@ void truncate_0100(void)
{
char path_n[128] = {0};
char *cwd = getcwd(path_n, sizeof(path_n));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path_n, "/files.txt");
FILE *f = fopen(path_n, "a");
if (f == NULL) {
......@@ -60,6 +64,10 @@ void truncate_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "a");
if (f == NULL) {
......@@ -105,6 +113,10 @@ void truncate_0300(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = truncate(path, nlen);
if (result == 0) {
......
......@@ -28,6 +28,10 @@ void unlink_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_unlink.txt");
int fd = open(path, O_CREAT);
int error_code = -1;
......@@ -51,6 +55,10 @@ void unlink_0200(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/unexist_test_unlink.txt");
int result = unlink(path);
int error_code = -1;
......
......@@ -27,6 +27,10 @@ void unlinkat_0100(void)
{
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_CREAT, 0664);
......@@ -49,6 +53,10 @@ void unlinkat_0200(void)
errno = 0;
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
if (result == 0) {
......
......@@ -29,6 +29,10 @@ void write_0100(void)
const char *msg = "This is a c test code for write function";
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = strlen(msg);
char buf[1024] = {0};
......@@ -65,6 +69,10 @@ void write_0200(void)
const char *msg = "This is a c test code for write function";
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = 0;
int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664);
......@@ -90,6 +98,10 @@ void write_0300(void)
const char *msg = "This is a c test code for write function";
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = strlen(msg) + 1;
int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664);
......@@ -115,6 +127,10 @@ void write_0400(void)
const char *msg = "This is a c test code for write function";
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = strlen(msg);
int fd = open(path, O_RDWR);
......@@ -136,6 +152,10 @@ void write_0500(void)
const char *msg = NULL;
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = 1;
int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册