diff --git a/libc-test/src/functionalext/common/filepath_util.h b/libc-test/src/functionalext/common/filepath_util.h new file mode 100644 index 0000000000000000000000000000000000000000..0cd0e363e88dd4f6b923b562c0cd1533c476808c --- /dev/null +++ b/libc-test/src/functionalext/common/filepath_util.h @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __FUNCTIONALEXT_FILEPATH_UTIL_H__ +#define __FUNCTIONALEXT_FILEPATH_UTIL_H__ + +#include +#include +#include + +#include "test.h" + +#define STR_SLASH "/" +#define STR_FILE_TXT "file.txt" +#define STR_FILE_LINK_TXT "linkfile.txt" +#define STR_FILE_IN_TXT "file_in.txt" +#define STR_FILE_OUT_TXT "file_out.txt" +#define STR_FILE_FROM_TXT "fromfile.txt" +#define STR_FILE_TO_TXT "tofile.txt" +#define STR_FILE_SWAP "swapfile" +#define STR_FILE_SYNC_TXT "sync_file_range.txt" +#define STR_TEST_TXT "test.txt" +#define STR_STAT_TEST_TXT "stattest.txt" +#define STR_FREAD_TEST_TXT "Freadtest.txt" +#define STR_FPUTC_TXT "fputc.txt" +#define STR_VFSCANF_TXT "vfscanf.txt" +#define STR_FACCESSAT_TEST_TXT "faccessattest.txt" +#define STR_FCHOWNAT_TEST_TXT "fchownattest.txt" +#define STR_WRITE_TEST_TXT "test_write.txt" + +#define FILE_ABSOLUTE_PATH(file_name, path) do { \ + if(!getcwd(path, sizeof(path))) { \ + t_error("%s getcwd for path failed\n", __func__); \ + return; \ + } \ + strncat(path, STR_SLASH, 1); \ + strncat(path, file_name, strlen(file_name)); \ +} while (0) + +#define FILE_ABSOLUTE_DIR(path) do { \ + if(!getcwd(path, sizeof(path))) { \ + t_error("%s getcwd for dir failed\n", __func__); \ + return; \ + } \ +} while (0) + +#endif diff --git a/libc-test/src/functionalext/supplement/dirent/readdir_r.c b/libc-test/src/functionalext/supplement/dirent/readdir_r.c index e40ce9497d70c091c43bf61a359cec249caa74fa..dcaa3ab3addb2f739422e1805fcb32ee9eae6e7e 100644 --- a/libc-test/src/functionalext/supplement/dirent/readdir_r.c +++ b/libc-test/src/functionalext/supplement/dirent/readdir_r.c @@ -17,7 +17,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" void handler(int sig) { @@ -31,12 +31,8 @@ void handler(int sig) */ 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; - } + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); DIR *dir = opendir(name); if (dir == NULL) { t_error("%s failed: opendir. name = %s\n", __func__, name); diff --git a/libc-test/src/functionalext/supplement/dirent/rewinddir.c b/libc-test/src/functionalext/supplement/dirent/rewinddir.c index 860e4e70940d0776f3493810fa9d5577c3d98f5c..f39a4e414888cc31042f103dcd821e9a5cdcdf31 100644 --- a/libc-test/src/functionalext/supplement/dirent/rewinddir.c +++ b/libc-test/src/functionalext/supplement/dirent/rewinddir.c @@ -18,7 +18,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" void handler(int sig) { @@ -32,13 +32,8 @@ void handler(int sig) */ void rewinddir_0100(void) { - char name[128] = {0}; - char *cwd = getcwd(name, sizeof(name)); - if (!cwd) { - t_error("%s getcwd failed\n", __func__); - return; - } - + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); DIR *dir = opendir(name); if (dir == NULL) { t_error("%s failed: opendir. name = %s\n", __func__, name); diff --git a/libc-test/src/functionalext/supplement/dirent/scandir.c b/libc-test/src/functionalext/supplement/dirent/scandir.c index 255c809f23ddbe51d4e25076c1266c7548720215..cb3a799c6dc23f28ac53cb85baae9b1b9f58e6a6 100644 --- a/libc-test/src/functionalext/supplement/dirent/scandir.c +++ b/libc-test/src/functionalext/supplement/dirent/scandir.c @@ -16,7 +16,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" int filter(const struct dirent *entry) { @@ -31,12 +31,8 @@ int filter(const struct dirent *entry) 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; - } + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); int n = scandir(name, &namelist, NULL, alphasort); if (n < 0) { @@ -58,12 +54,8 @@ void scandir_0100(void) 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; - } + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); int n = scandir(name, &namelist, NULL, versionsort); if (n < 0) { @@ -85,13 +77,8 @@ void scandir_0200(void) 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; - } - + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); int n = scandir(name, &namelist, filter, versionsort); if (n < 0) { t_error("%s failed: scandir. n = %d\n", __func__, n); diff --git a/libc-test/src/functionalext/supplement/ipc/ftok.c b/libc-test/src/functionalext/supplement/ipc/ftok.c index 14832036ebb82667f1866352be19806d0b149f69..d28a51ad7bff367984bc91c8b1e457c8e6604131 100755 --- a/libc-test/src/functionalext/supplement/ipc/ftok.c +++ b/libc-test/src/functionalext/supplement/ipc/ftok.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" /* * @tc.name : ftok_0100 @@ -23,14 +24,9 @@ */ 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); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("ftok", path); + key_t result = ftok(path, 1); EXPECT_NE("ftok_0100", result, -1); } diff --git a/libc-test/src/functionalext/supplement/ipc/semtimedop.c b/libc-test/src/functionalext/supplement/ipc/semtimedop.c index d638c57d984af97b9f92ebe72832dd9fca1b78d4..dca870d64b54aef6c2aeaaa4e4c70aedfd1c4e93 100644 --- a/libc-test/src/functionalext/supplement/ipc/semtimedop.c +++ b/libc-test/src/functionalext/supplement/ipc/semtimedop.c @@ -18,7 +18,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" extern int __semtimedop_time64(int, struct sembuf *, size_t, const struct timespec *); @@ -29,14 +29,8 @@ extern int __semtimedop_time64(int, struct sembuf *, size_t, const struct timesp */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); if (fd < 0) { t_error("%s failed: fd = %d\n", __func__, fd); diff --git a/libc-test/src/functionalext/supplement/linux/copy_file_range.c b/libc-test/src/functionalext/supplement/linux/copy_file_range.c index 9b1eb42c7a969ef50038ac9e886a1d6e0f1cd917..8f28c563d6a336d175f122744c1afc8c7c4a4fc2 100644 --- a/libc-test/src/functionalext/supplement/linux/copy_file_range.c +++ b/libc-test/src/functionalext/supplement/linux/copy_file_range.c @@ -17,7 +17,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" const char *str = "Hello"; @@ -31,20 +31,10 @@ void copy_file_range_0100(void) int fd_in, fd_out, wlen, result; char buffer[BUFSIZ]; - 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"); + char path_in[PATH_MAX] = {0}; + char path_out[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); + FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out); fd_in = open(path_in, O_RDWR | O_CREAT); if (fd_in == -1) { @@ -120,21 +110,11 @@ void copy_file_range_0300(void) int fd_in, fd_out, wlen, result; char buffer[BUFSIZ]; - 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"); - + char path_in[PATH_MAX] = {0}; + char path_out[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); + FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out); + fd_in = open(path_in, O_WRONLY | O_CREAT); if (fd_in == -1) { t_error("%s open path_in failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/linux/removexattr.c b/libc-test/src/functionalext/supplement/linux/removexattr.c index c75f8e9372d104b62780c6994cb10dc2d9e59a40..71e92991a5e1c1dc787d723fcb0f9d39c64ded56 100644 --- a/libc-test/src/functionalext/supplement/linux/removexattr.c +++ b/libc-test/src/functionalext/supplement/linux/removexattr.c @@ -19,7 +19,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" const char *name = "user.foo"; const char *value = "bar"; @@ -31,14 +31,8 @@ const char *value = "bar"; */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); if (fd < 0) { t_error("%s failed: fd = %d\n", __func__, fd); diff --git a/libc-test/src/functionalext/supplement/linux/sendfile.c b/libc-test/src/functionalext/supplement/linux/sendfile.c index 3769e6f37c9e0c5c51bdfbef2f5fe4639c4e95c1..017934ad8a3a582bfeb0c1eb46ffe737308f1637 100644 --- a/libc-test/src/functionalext/supplement/linux/sendfile.c +++ b/libc-test/src/functionalext/supplement/linux/sendfile.c @@ -19,7 +19,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" /** * @tc.name : sendfile_0100 @@ -28,20 +28,10 @@ */ 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"); + char fromfile[PATH_MAX] = {0}; + char tofile[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile); + FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile); FILE *f = fopen(fromfile, "w+"); const char src[] = "A"; diff --git a/libc-test/src/functionalext/supplement/linux/setxattr.c b/libc-test/src/functionalext/supplement/linux/setxattr.c index c7e9172d2a6863558e8f2aa120c1762378eac1b3..60981eec651565d922e57146ab90779bdcfe13ad 100644 --- a/libc-test/src/functionalext/supplement/linux/setxattr.c +++ b/libc-test/src/functionalext/supplement/linux/setxattr.c @@ -19,7 +19,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" const char *name = "user.foo"; const char *value = "bar"; @@ -31,14 +31,8 @@ const char *value = "bar"; */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); if (fd < 0) { t_error("%s failed: fd = %d\n", __func__, fd); diff --git a/libc-test/src/functionalext/supplement/linux/splice.c b/libc-test/src/functionalext/supplement/linux/splice.c index cad803b735c74a728006cd4e73a51cd6278c9c5e..ef00033aa69ac1765100f0a7c2e9da558cd4ce3b 100644 --- a/libc-test/src/functionalext/supplement/linux/splice.c +++ b/libc-test/src/functionalext/supplement/linux/splice.c @@ -19,7 +19,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" const char *path = "/proc/version"; @@ -30,20 +30,10 @@ const char *path = "/proc/version"; */ 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"); + char fromfile[PATH_MAX] = {0}; + char tofile[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile); + FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile); int fromfd = open(fromfile, O_RDWR | O_CREAT); if (fromfd < 0) { diff --git a/libc-test/src/functionalext/supplement/linux/swapoff.c b/libc-test/src/functionalext/supplement/linux/swapoff.c index f84e9a83bfdd7f7f438d4b010cc24d14b3e1c555..f774d5c727e81ea808da3e6307f153821533d8d4 100644 --- a/libc-test/src/functionalext/supplement/linux/swapoff.c +++ b/libc-test/src/functionalext/supplement/linux/swapoff.c @@ -17,8 +17,8 @@ #include #include #include -#include -#include "test.h" + +#include "filepath_util.h" /** * @tc.name : swapoff_0100 @@ -27,22 +27,19 @@ */ 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; - } - + char dir_path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(dir_path); errno = 0; - char cmd[256] = {0}; + char cmd[PATH_MAX] = {0}; snprintf(cmd, sizeof(cmd), "cd %s; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile", dir_path); system(cmd); - strcat(dir_path, "/swapfile"); - int result = swapon(dir_path, SWAP_FLAG_PREFER); + + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SWAP, path); + int result = swapon(path, SWAP_FLAG_PREFER); if (result == -1) { t_error("%s swapon failed\n", __func__); - remove(dir_path); + remove(path); return; } if (errno == ENOSYS) { @@ -50,7 +47,7 @@ void swapoff_0100(void) return; } - result = swapoff(dir_path); + result = swapoff(path); if (result == -1) { t_error("%s swapoff failed", __func__); } diff --git a/libc-test/src/functionalext/supplement/linux/swapon.c b/libc-test/src/functionalext/supplement/linux/swapon.c index e81f62dab08ce0575460e8f662cd65aa2d4e0737..c0dd521386637cff4fa28f4f55e171660ce00982 100644 --- a/libc-test/src/functionalext/supplement/linux/swapon.c +++ b/libc-test/src/functionalext/supplement/linux/swapon.c @@ -17,8 +17,8 @@ #include #include #include -#include -#include "test.h" + +#include "filepath_util.h" /** * @tc.name : swapon_0100 @@ -27,22 +27,19 @@ */ 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; - } - + char dir_path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(dir_path); errno = 0; - char cmd[256] = {0}; + char cmd[PATH_MAX] = {0}; snprintf(cmd, sizeof(cmd), "cd %s; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile", dir_path); system(cmd); - strcat(dir_path, "/swapfile"); - int result = swapon(dir_path, SWAP_FLAG_PREFER); + + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SWAP, path); + int result = swapon(path, SWAP_FLAG_PREFER); if (result == -1) { t_error("%s swapon failed\n", __func__); - remove(dir_path); + remove(path); } if (errno == ENOSYS) { diff --git a/libc-test/src/functionalext/supplement/linux/sync_file_range.c b/libc-test/src/functionalext/supplement/linux/sync_file_range.c index 219792a650a5ee1a95c3d00f26acd4bdd588d5cf..824a9975b9e9cade713eca9cecf5cb9fafa9f449 100644 --- a/libc-test/src/functionalext/supplement/linux/sync_file_range.c +++ b/libc-test/src/functionalext/supplement/linux/sync_file_range.c @@ -17,8 +17,8 @@ #include #include #include -#include -#include "test.h" + +#include "filepath_util.h" /** * @tc.name : sync_file_range_0100 @@ -27,16 +27,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; int result, fd; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { @@ -78,17 +72,11 @@ void sync_file_range_0200(void) */ 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; int result, fd; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { t_error("%s open failed\n", __func__); @@ -113,17 +101,11 @@ void sync_file_range_0300(void) */ 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; int result, fd; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { t_error("%s open failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/linux/syncfs.c b/libc-test/src/functionalext/supplement/linux/syncfs.c index 571dd446c0fe8dee0f8cf11a5aaaf428c139bbbc..9f92349f7b64c66a4e229faf3c29bf60c72ad77c 100644 --- a/libc-test/src/functionalext/supplement/linux/syncfs.c +++ b/libc-test/src/functionalext/supplement/linux/syncfs.c @@ -17,8 +17,8 @@ #include #include #include -#include -#include "test.h" + +#include "filepath_util.h" /** * @tc.name : syncfs_0100 @@ -27,15 +27,9 @@ */ 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; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("syncfs.txt", path); int fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { t_error("%s open failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/linux/tee.c b/libc-test/src/functionalext/supplement/linux/tee.c index 22f0175f70a107011f6882645fc90c36f803a835..3c21bd72dd961421a84fe7851618d85ea0a6b190 100644 --- a/libc-test/src/functionalext/supplement/linux/tee.c +++ b/libc-test/src/functionalext/supplement/linux/tee.c @@ -17,7 +17,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" #define BUFF_SIZE (20) @@ -74,14 +74,9 @@ void tee_0200(void) { char buf[BUFF_SIZE]; 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; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (fd < 0) { diff --git a/libc-test/src/functionalext/supplement/mman/mincore.c b/libc-test/src/functionalext/supplement/mman/mincore.c index 6614ff231fe974a5fe985960a467b13c454b58b8..b954174d0cead1386947c4d5e9b81d7dac3e5a0d 100755 --- a/libc-test/src/functionalext/supplement/mman/mincore.c +++ b/libc-test/src/functionalext/supplement/mman/mincore.c @@ -19,6 +19,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" #define TEST_SIZE 4096 @@ -30,14 +31,9 @@ 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"); - + char pathname[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("mincore", pathname); + int ret = stat(pathname, &st); EXPECT_EQ("mincore_0100", ret, CMPFLAG); if (ret != 0) { diff --git a/libc-test/src/functionalext/supplement/stat/fchmodat.c b/libc-test/src/functionalext/supplement/stat/fchmodat.c index 765d90cff1d44746aab02a0929829651d9ec7521..216aa97ab7ce886fd1698b2d672eec915353dba0 100755 --- a/libc-test/src/functionalext/supplement/stat/fchmodat.c +++ b/libc-test/src/functionalext/supplement/stat/fchmodat.c @@ -16,6 +16,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" int success = 36863; int SUCCESS = 33279; @@ -28,16 +29,10 @@ int failed = -1; */ 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; struct stat buf; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_TEST_TXT, path); fd = open(path, O_RDWR | O_CREAT); int result = fchmodat(fd, path, @@ -58,16 +53,10 @@ void fchmodat_0100(void) */ 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; struct stat buf; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_TEST_TXT, path); fd = open(path, O_RDWR | O_CREAT); int result = fchmodat(fd, path, diff --git a/libc-test/src/functionalext/supplement/stat/fstatat.c b/libc-test/src/functionalext/supplement/stat/fstatat.c index c6bd2d3b0d603f4579a0cbadf68026c2381762cf..631a9adb3335685fc119c49ba7cc737e8ef8d1ef 100644 --- a/libc-test/src/functionalext/supplement/stat/fstatat.c +++ b/libc-test/src/functionalext/supplement/stat/fstatat.c @@ -17,6 +17,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" const int SUCCESS = 0; @@ -84,13 +85,8 @@ void fstatat_0200(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("fstatattest.txt", ptr); struct stat st; int fd = open(ptr, O_RDWR | O_CREAT); diff --git a/libc-test/src/functionalext/supplement/stat/lstat.c b/libc-test/src/functionalext/supplement/stat/lstat.c index f27bfa3188e61fab1d43260e205f9ab3942e4283..47479fd9cc204643471bde773c71eee3a9104da0 100755 --- a/libc-test/src/functionalext/supplement/stat/lstat.c +++ b/libc-test/src/functionalext/supplement/stat/lstat.c @@ -18,6 +18,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" extern int __lstat_time64(const char *__restrict, struct stat *__restrict); @@ -30,13 +31,8 @@ typedef void (*TEST_FUN)(); */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_STAT_TEST_TXT, ptr); const char str[] = "this is a sample!"; FILE *fptr = fopen(ptr, "w+"); @@ -57,13 +53,8 @@ void lstat_0100(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_STAT_TEST_TXT, ptr); const char str[] = "this is a sample!"; FILE *fptr = fopen(ptr, "w+"); @@ -85,7 +76,7 @@ void lstat_time64_0100(void) void lstat_0200(void) { struct stat statbuff; - int32_t back = lstat("test.txt", &statbuff); + int32_t back = lstat(STR_TEST_TXT, &statbuff); EXPECT_EQ("lstat_0200", back, -1); } @@ -96,24 +87,14 @@ void lstat_0200(void) */ 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]; + char ptr[PATH_MAX] = {0}; + char ptrlink[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("tests.txt", ptr); + FILE_ABSOLUTE_PATH("tests.txt.soft", ptrlink); FILE *fptr = fopen(ptr, "w+"); - char cmd[256] = {0}; + char cmd[PATH_MAX] = {0}; snprintf(cmd, sizeof(cmd), "ln -s %s %s", ptr, ptrlink); system(cmd); struct stat statbuff; diff --git a/libc-test/src/functionalext/supplement/stat/mknod.c b/libc-test/src/functionalext/supplement/stat/mknod.c index f5b35ec1f5f56d9b2559a9a32a2434e0d91cccb6..0dff1c6e75b4a385ba90cf1f130718d84ac0aed7 100755 --- a/libc-test/src/functionalext/supplement/stat/mknod.c +++ b/libc-test/src/functionalext/supplement/stat/mknod.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" #define TEST_MODE 0666 @@ -25,14 +26,8 @@ */ 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"); - + char pathname[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("mknod", pathname); int ret = mknod(pathname, TEST_MODE, 0); EXPECT_EQ("mknod_0100", ret, ERREXPECT); } diff --git a/libc-test/src/functionalext/supplement/stat/utimensat.c b/libc-test/src/functionalext/supplement/stat/utimensat.c index 93b34ae114c73a9d4f1a9f5c376d510e25ee45a9..86274c9b67a11899f6c5809348932a4bae1be16c 100644 --- a/libc-test/src/functionalext/supplement/stat/utimensat.c +++ b/libc-test/src/functionalext/supplement/stat/utimensat.c @@ -17,8 +17,7 @@ #include #include #include -#include -#include "test.h" +#include "filepath_util.h" const long sec = 123840; @@ -31,14 +30,8 @@ extern int __utimensat_time64(int, const char *, const struct timespec [2], int) */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; @@ -87,14 +80,8 @@ void utimensat_0200(void) */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; diff --git a/libc-test/src/functionalext/supplement/stdio/__fwritable.c b/libc-test/src/functionalext/supplement/stdio/__fwritable.c index ce87a8f821ae04e74e4a2ed100eda708e08e4e0f..667654dcce1faf39d4cdce5d45dd0ff80d7e19e2 100644 --- a/libc-test/src/functionalext/supplement/stdio/__fwritable.c +++ b/libc-test/src/functionalext/supplement/stdio/__fwritable.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" const int32_t NUM_ZERO = 0; @@ -25,14 +26,8 @@ const int32_t NUM_ZERO = 0; */ 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"); - + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w+"); if (!fptr) { t_error("%s fopen failed\n", __func__); @@ -49,14 +44,8 @@ void __fwritable_0100(void) */ 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"); - + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "r"); if (!fptr) { t_error("%s fopen failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/stdio/__fwriting.c b/libc-test/src/functionalext/supplement/stdio/__fwriting.c index 964460cb9b8bc713d9ad87ff900f8379ead1fc1c..35a5a41be9f3e010f70b7ced904c7be5d0b0956c 100644 --- a/libc-test/src/functionalext/supplement/stdio/__fwriting.c +++ b/libc-test/src/functionalext/supplement/stdio/__fwriting.c @@ -19,6 +19,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" const int32_t NUM_ZERO = 0; @@ -29,14 +30,8 @@ const int32_t NUM_ZERO = 0; */ 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"); - + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w"); int result = __fwriting(fptr); EXPECT_NE("__fwriting_0100", result, NUM_ZERO); @@ -51,15 +46,9 @@ void __fwriting_0100(void) */ 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"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w+"); fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); int result = __fwriting(fptr); @@ -75,16 +64,10 @@ void __fwriting_0200(void) */ 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}; const char *wrstring = "helloworld"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w+"); fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); fseek(fptr, 0, SEEK_SET); diff --git a/libc-test/src/functionalext/supplement/stdio/fputc.c b/libc-test/src/functionalext/supplement/stdio/fputc.c index 9e490026fe75f7658479db3213d6af5e362ae4a3..f4b504a7cd32df339cb633e315ff665b95ed7c1f 100644 --- a/libc-test/src/functionalext/supplement/stdio/fputc.c +++ b/libc-test/src/functionalext/supplement/stdio/fputc.c @@ -14,6 +14,7 @@ */ #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : fputc_0100 @@ -22,14 +23,8 @@ */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path); FILE *fptr = fopen(path, "w"); int Exit = fputc('a', fptr); EXPECT_EQ("fputc_0100", Exit, 97); @@ -43,14 +38,8 @@ void fputc_0100(void) */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path); FILE *fptr = fopen(path, "r"); int Exit = fputc('a', fptr); EXPECT_EQ("fputc_0200", Exit, EOF); diff --git a/libc-test/src/functionalext/supplement/stdio/freopen.c b/libc-test/src/functionalext/supplement/stdio/freopen.c index 1b219430be2ebfc68fa90f5d730b52c851fe2946..742d907caca402ffae4ce7bc6cfe0441560ab121 100644 --- a/libc-test/src/functionalext/supplement/stdio/freopen.c +++ b/libc-test/src/functionalext/supplement/stdio/freopen.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : freopen_0100 @@ -23,13 +24,8 @@ */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("freopen.txt", ptr); FILE *fp; fp = freopen(ptr, "w+", stdin); diff --git a/libc-test/src/functionalext/supplement/stdio/getline.c b/libc-test/src/functionalext/supplement/stdio/getline.c index 195faa59570dc6919978a9552654d2e6cd9f2563..3e74f6b4caf6eb237dab1da7c1e52dbcac52add2 100644 --- a/libc-test/src/functionalext/supplement/stdio/getline.c +++ b/libc-test/src/functionalext/supplement/stdio/getline.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : getline_0100 @@ -26,15 +27,9 @@ void getline_0100(void) char *wrstring = "helloworld"; char *line = NULL; 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+"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_TEST_TXT, ptr); + FILE *fp = fopen(ptr, "w+"); EXPECT_PTRNE("getline_0100", fp, NULL); fwrite(wrstring, sizeof(char), strlen(wrstring), fp); fseek(fp, 0, SEEK_SET); @@ -44,7 +39,7 @@ void getline_0100(void) EXPECT_STREQ("getline_0100", line, "helloworld"); fclose(fp); - remove(path); + remove(ptr); } /** @@ -55,21 +50,16 @@ void getline_0100(void) 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+"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, ptr); + FILE *fp = fopen(ptr, "w+"); EXPECT_PTRNE("getline_0100", fp, NULL); ssize_t read = getline(NULL, &len, fp); EXPECT_EQ("getline_0200", read, -1); fclose(fp); - remove(path); + remove(ptr); } /** @@ -80,20 +70,15 @@ void getline_0200(void) 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+"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, ptr); + FILE *fp = fopen(ptr, "w+"); EXPECT_PTRNE("getline_0100", fp, NULL); ssize_t read = getline(&line, 0, fp); EXPECT_EQ("getline_0300", read, -1); fclose(fp); - remove(path); + remove(ptr); } int main(int argc, char *argv[]) diff --git a/libc-test/src/functionalext/supplement/stdio/setbuf.c b/libc-test/src/functionalext/supplement/stdio/setbuf.c index 8aaeb9823b0d3fa3d9420bee7e84bc5265dcd883..98f1409d16f50008f1d62000a08a32d2c5bb6583 100644 --- a/libc-test/src/functionalext/supplement/stdio/setbuf.c +++ b/libc-test/src/functionalext/supplement/stdio/setbuf.c @@ -17,7 +17,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" const char *str = "Hello"; @@ -29,13 +29,8 @@ const char *str = "Hello"; 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); errno = 0; setbuf(f, buf); @@ -62,13 +57,8 @@ void setbuf_0100(void) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); errno = 0; diff --git a/libc-test/src/functionalext/supplement/stdio/setbuffer.c b/libc-test/src/functionalext/supplement/stdio/setbuffer.c index b98ed8f7edc03fd4acec7d89285b406d00faf92d..1413f143a62c7b1b43b5fc7d474952b01fe25a99 100644 --- a/libc-test/src/functionalext/supplement/stdio/setbuffer.c +++ b/libc-test/src/functionalext/supplement/stdio/setbuffer.c @@ -16,7 +16,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" const char *str = "Hello"; @@ -27,13 +27,8 @@ const char *str = "Hello"; */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *fp = fopen(path, "w+"); char buf[BUFSIZ] = {0}; errno = 0; @@ -66,13 +61,8 @@ void setbuffer_0100(void) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); errno = 0; diff --git a/libc-test/src/functionalext/supplement/stdio/setlinebuf.c b/libc-test/src/functionalext/supplement/stdio/setlinebuf.c index 15bdbb7d7f69448af9547cc0ef2e8b3b6f35c5e3..635b4db007bb45ad62fa7c407f836d2325f52050 100644 --- a/libc-test/src/functionalext/supplement/stdio/setlinebuf.c +++ b/libc-test/src/functionalext/supplement/stdio/setlinebuf.c @@ -16,7 +16,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" const char *str = "Hello"; @@ -27,13 +27,8 @@ const char *str = "Hello"; */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); char buffer[BUFSIZ]; errno = 0; diff --git a/libc-test/src/functionalext/supplement/stdio/setvbuf.c b/libc-test/src/functionalext/supplement/stdio/setvbuf.c index c1c6eb38efc7fb6b164da2c20b11e210526a0c3d..6a15f29b4f837b488278e3e21f7ae1fa9acc8b61 100644 --- a/libc-test/src/functionalext/supplement/stdio/setvbuf.c +++ b/libc-test/src/functionalext/supplement/stdio/setvbuf.c @@ -14,6 +14,7 @@ */ #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : setvbuf_0100 @@ -23,13 +24,8 @@ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *fptr = fopen(path, "w+"); EXPECT_PTRNE("setvbuf_0100", fptr, NULL); @@ -48,13 +44,8 @@ void setvbuf_0100(void) 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *fptr = fopen(path, "w+"); EXPECT_PTRNE("setvbuf_0100", fptr, NULL); diff --git a/libc-test/src/functionalext/supplement/stdio/ungetwc.c b/libc-test/src/functionalext/supplement/stdio/ungetwc.c index 342f6397d5c8c297e114713dc6224467652c577a..9f245c7d2d206fcf34aa84767bdf46db42eb7af5 100644 --- a/libc-test/src/functionalext/supplement/stdio/ungetwc.c +++ b/libc-test/src/functionalext/supplement/stdio/ungetwc.c @@ -17,8 +17,8 @@ #include #include #include -#include -#include "test.h" + +#include "filepath_util.h" void handler(int sig) { @@ -32,13 +32,8 @@ void handler(int sig) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *file = fopen(path, "a+"); if (!file) { t_error("%s failed: fopen\n", __func__); diff --git a/libc-test/src/functionalext/supplement/stdio/vfscanf.c b/libc-test/src/functionalext/supplement/stdio/vfscanf.c index 6f025b92b86ec6dc7e73db71af7398e9a4de67be..9611c7c20c554ee2222496c5ec6ebc20a8cac8bd 100644 --- a/libc-test/src/functionalext/supplement/stdio/vfscanf.c +++ b/libc-test/src/functionalext/supplement/stdio/vfscanf.c @@ -16,7 +16,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" int readFile(FILE *stream, char *fmt, ...) { @@ -37,13 +37,8 @@ void vfscanf_0100(void) FILE *fp = NULL; int val = 0; 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"); + char file[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file); fp = fopen(file, "w+"); if (fp == NULL) { t_error("%s fopen failed\n", __func__); @@ -79,13 +74,8 @@ void vfscanf_0200(void) FILE *fp = NULL; char val[BUFSIZ]; 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"); + char file[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file); fp = fopen(file, "w+"); if (fp == NULL) { t_error("%s fopen failed\n", __func__); @@ -121,13 +111,8 @@ void vfscanf_0300(void) FILE *fp = NULL; int val1 = 0; 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"); + char file[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file); fp = fopen(file, "w+"); if (fp == NULL) { t_error("%s fopen failed", __func__); diff --git a/libc-test/src/functionalext/supplement/unistd/acct.c b/libc-test/src/functionalext/supplement/unistd/acct.c index 3bed3206fb5e6760a5d5be41af259b45e5888b75..9286d752a6e6d9a4a0f989042638023da69715f5 100644 --- a/libc-test/src/functionalext/supplement/unistd/acct.c +++ b/libc-test/src/functionalext/supplement/unistd/acct.c @@ -16,6 +16,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : acct_0100 @@ -35,14 +36,8 @@ void acct_0100(void) */ 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"); - + char filePath[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("accttest.txt", filePath); int result = acct(filePath); EXPECT_EQ("acct_0300", result, -1); remove(filePath); diff --git a/libc-test/src/functionalext/supplement/unistd/exit.c b/libc-test/src/functionalext/supplement/unistd/exit.c index 0a9702a595213fbfda11f075ce7874c3c4618d33..6cd8c218830082f475abf4904c826e60061a4ae4 100755 --- a/libc-test/src/functionalext/supplement/unistd/exit.c +++ b/libc-test/src/functionalext/supplement/unistd/exit.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" /* * @tc.name : exit_0100 @@ -24,13 +25,9 @@ */ 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}; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(path); + char cmd[PATH_MAX] = {0}; snprintf(cmd, sizeof(cmd), "cd %s; ./exittest01", path); system(cmd); @@ -62,13 +59,9 @@ void exit_0100(void) */ 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}; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(path); + char cmd[PATH_MAX] = {0}; snprintf(cmd, sizeof(cmd), "cd %s; ./exittest02", path); system(cmd); diff --git a/libc-test/src/functionalext/supplement/unistd/faccessat.c b/libc-test/src/functionalext/supplement/unistd/faccessat.c index 2b74cef20784ae81aa14df47668263f0597b5aef..a732e015e74cf320d1a467e6a6c382a715c92bde 100644 --- a/libc-test/src/functionalext/supplement/unistd/faccessat.c +++ b/libc-test/src/functionalext/supplement/unistd/faccessat.c @@ -17,6 +17,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" typedef void (*TEST_FUN)(); const int SUCCESS = 0; @@ -29,13 +30,8 @@ const int FAILED = -1; */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_0100", fd >= 0); int isExist = faccessat(fd, ptr, F_OK, 0); @@ -51,13 +47,8 @@ void faccessat_0100(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = -1; int isExist = faccessat(fd, ptr, F_OK, 0); EXPECT_EQ("faccessat_0200", isExist, FAILED); @@ -72,13 +63,8 @@ void faccessat_0200(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00040); EXPECT_TRUE("faccessat_0300", fd >= 0); int isRead = faccessat(fd, ptr, R_OK, 0); @@ -94,13 +80,8 @@ void faccessat_0300(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00020); EXPECT_TRUE("faccessat_0400", fd >= 0); int isWrite = faccessat(fd, ptr, W_OK, 0); @@ -116,13 +97,8 @@ void faccessat_0400(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00010); char cmd[256] = {0}; snprintf(cmd, sizeof(cmd), "chmod 777 %s", ptr); @@ -141,13 +117,8 @@ void faccessat_0500(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_0600", fd >= 0); int isExecute = faccessat(fd, ptr, X_OK, 0); @@ -163,13 +134,8 @@ void faccessat_0600(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00070); EXPECT_TRUE("faccessat_0700", fd >= 0); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); @@ -185,13 +151,8 @@ void faccessat_0700(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_0800", fd >= 0); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); @@ -207,13 +168,8 @@ void faccessat_0800(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00070); EXPECT_TRUE("faccessat_0900", fd >= 0); int ret = faccessat(fd, ptr, R_OK, AT_SYMLINK_NOFOLLOW); @@ -231,13 +187,8 @@ void faccessat_0900(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00070); EXPECT_TRUE("faccessat_1000", fd >= 0); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); @@ -254,13 +205,8 @@ void faccessat_1000(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_1100", fd >= 0); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); diff --git a/libc-test/src/functionalext/supplement/unistd/fchownat.c b/libc-test/src/functionalext/supplement/unistd/fchownat.c index 9b31da5dd3153d1357b016be57fa5ed918fd4d61..e20599c1454fbdeef443697bd1fb54cedc9d34aa 100644 --- a/libc-test/src/functionalext/supplement/unistd/fchownat.c +++ b/libc-test/src/functionalext/supplement/unistd/fchownat.c @@ -17,6 +17,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : fchownat_0100 @@ -25,13 +26,8 @@ */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("fchownat_0100", fd >= 0); int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); @@ -52,13 +48,8 @@ void fchownat_0100(void) */ 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"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("fchownat_0200", fd >= 0); int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); diff --git a/libc-test/src/functionalext/supplement/unistd/getpid.c b/libc-test/src/functionalext/supplement/unistd/getpid.c index a6ddf86830ec0e38f37ff5167351009adcb1b541..439ae457e711827a14b34b3241ec50206fef28b5 100755 --- a/libc-test/src/functionalext/supplement/unistd/getpid.c +++ b/libc-test/src/functionalext/supplement/unistd/getpid.c @@ -18,6 +18,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : getpid_0100 @@ -26,19 +27,14 @@ */ 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); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("ps.txt", ptr); + char cmd[PATH_MAX] = {0}; + snprintf(cmd, sizeof(cmd), "ps -eo command,pid | grep -E \"PID|getpid\" > %s", ptr); system(cmd); char abc[256] = {0}; bool successflag = false; - FILE *fptr = fopen(path, "r"); + FILE *fptr = fopen(ptr, "r"); if (fptr) { while (!feof(fptr)) { fread(abc, sizeof(abc), 1, fptr); @@ -58,7 +54,7 @@ void getpid_0100(void) } EXPECT_TRUE("getpid_0100", successflag); fclose(fptr); - remove(path); + remove(ptr); } int main(int argc, char *argv[]) diff --git a/libc-test/src/functionalext/supplement/unistd/lchown.c b/libc-test/src/functionalext/supplement/unistd/lchown.c index 2c5b5f62e207568fdf08e5fe7dbe97cb219a9902..32823bf30a0ad87ea60deefdd7d79b16e8efd37c 100755 --- a/libc-test/src/functionalext/supplement/unistd/lchown.c +++ b/libc-test/src/functionalext/supplement/unistd/lchown.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" #define TEST_ID_VALUE 100 @@ -25,14 +26,9 @@ */ 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); + char pathname[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("lchown", pathname); + int ret = lchown(pathname, TEST_ID_VALUE, TEST_ID_VALUE); EXPECT_EQ("lchown_0100", ret, CMPFLAG); } diff --git a/libc-test/src/functionalext/supplement/unistd/readlinkat.c b/libc-test/src/functionalext/supplement/unistd/readlinkat.c index dd4658780865b2633d8d901693a2d7ea7c7bfc59..803e7b90e6daa2479cc721aaa18928ca15c25317 100644 --- a/libc-test/src/functionalext/supplement/unistd/readlinkat.c +++ b/libc-test/src/functionalext/supplement/unistd/readlinkat.c @@ -19,7 +19,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" const char buf[] = "hello"; const char *filename = "./file.txt"; @@ -52,26 +52,16 @@ int create_file(char *path) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int result = create_file(path); if (result != 0) { t_error("%s failed: result = %d\n", __func__, result); return; } - char linkpath[128] = {0}; - cwd = getcwd(linkpath, sizeof(linkpath)); - if (!cwd) { - t_error("%s getcwd link failed\n", __func__); - return; - } - strcat(linkpath, "/linkfile.txt"); + char linkpath[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_LINK_TXT, linkpath); remove(linkpath); result = symlink(path, linkpath); @@ -107,25 +97,16 @@ void readlinkat_0100(void) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int result = create_file(path); if (result != 0) { t_error("%s failed: result = %d\n", __func__, result); return; } - char dirname[128] = {0}; - cwd = getcwd(dirname, sizeof(dirname)); - if (!cwd) { - t_error("%s getcwd dir failed\n", __func__); - return; - } + char dirname[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(dirname); DIR *dir = opendir(dirname); if (dir == NULL) { t_error("%s failed: dirname = %s\n", __func__, dirname); @@ -137,13 +118,8 @@ void readlinkat_0200(void) t_error("%s failed: fd = %d\n", __func__, fd); } - char linkpath[128] = {0}; - cwd = getcwd(linkpath, sizeof(linkpath)); - if (!cwd) { - t_error("%s getcwd link failed\n", __func__); - return; - } - strcat(linkpath, "/linkfile.txt"); + char linkpath[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_LINK_TXT, linkpath); remove(linkpath); result = symlinkat(filename, fd, linkfilename); diff --git a/libc-test/src/functionalext/supplement/unistd/readv.c b/libc-test/src/functionalext/supplement/unistd/readv.c index 384de790821b367968ef016a4626ae7e9c94ea68..d2ae41689e5909dd59edb8fa4fff9486a3920cee 100644 --- a/libc-test/src/functionalext/supplement/unistd/readv.c +++ b/libc-test/src/functionalext/supplement/unistd/readv.c @@ -19,7 +19,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" /** * @tc.name : readv_0100 @@ -28,13 +28,8 @@ */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); char buf1[] = "hello"; diff --git a/libc-test/src/functionalext/supplement/unistd/truncate.c b/libc-test/src/functionalext/supplement/unistd/truncate.c index b0e48c8463f1e63b4a4f726d300d5aec7c0b900d..2486a7f10498402c254b5a89fd0226dc623347ca 100644 --- a/libc-test/src/functionalext/supplement/unistd/truncate.c +++ b/libc-test/src/functionalext/supplement/unistd/truncate.c @@ -18,7 +18,7 @@ #include #include -#include "test.h" +#include "filepath_util.h" const int nlen = -1; const int vlen = 5; @@ -33,13 +33,8 @@ const char *content = "Hello world!"; */ 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"); + char path_n[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("files.txt", path_n); FILE *f = fopen(path_n, "a"); if (f == NULL) { t_error("%s failed: fopen\n", __func__); @@ -62,13 +57,8 @@ void truncate_0100(void) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "a"); if (f == NULL) { t_error("%s failed: fopen\n", __func__); @@ -111,13 +101,8 @@ void truncate_0200(void) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int result = truncate(path, nlen); if (result == 0) { t_error("%s failed: result = %d\n", __func__, result); diff --git a/libc-test/src/functionalext/supplement/unistd/unlink.c b/libc-test/src/functionalext/supplement/unistd/unlink.c index 8be799a612586f6888b391510438dea07bd6c954..2149e60226a5d8f42c5d1c54a5511b2eceef6f3b 100644 --- a/libc-test/src/functionalext/supplement/unistd/unlink.c +++ b/libc-test/src/functionalext/supplement/unistd/unlink.c @@ -17,7 +17,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" /** * @tc.name : unlink_0100 @@ -26,13 +26,8 @@ */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("test_unlink.txt", path); int fd = open(path, O_CREAT); int error_code = -1; if (fd == error_code) { @@ -53,13 +48,8 @@ void unlink_0100(void) */ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("unexist_test_unlink.txt", path); int result = unlink(path); int error_code = -1; if (result != error_code) { diff --git a/libc-test/src/functionalext/supplement/unistd/unlinkat.c b/libc-test/src/functionalext/supplement/unistd/unlinkat.c index b01aaecaca69c8c4848421c77927aeac3a0ff227..ad9bfff2b1b3ba31ca2e1506f9474850dc285ab6 100644 --- a/libc-test/src/functionalext/supplement/unistd/unlinkat.c +++ b/libc-test/src/functionalext/supplement/unistd/unlinkat.c @@ -15,8 +15,8 @@ #include #include -#include -#include "test.h" + +#include "filepath_util.h" /** * @tc.name : unlinkat_0100 @@ -25,14 +25,8 @@ */ 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"); - + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_CREAT, 0664); int result = unlinkat(fd, path, 0); @@ -51,13 +45,8 @@ void unlinkat_0100(void) 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int result = unlinkat(AT_FDCWD, path, AT_REMOVEDIR); if (result == 0) { t_error("%s failed: result = %d\n", __func__, result); diff --git a/libc-test/src/functionalext/supplement/unistd/write.c b/libc-test/src/functionalext/supplement/unistd/write.c index 124babfd444f1f0a41960359532a8e5f82312ec4..aa665ac0b9b3bcfeac81425c2c1427cbe943d6c5 100644 --- a/libc-test/src/functionalext/supplement/unistd/write.c +++ b/libc-test/src/functionalext/supplement/unistd/write.c @@ -17,7 +17,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" /** * @tc.name : write_0100 @@ -27,13 +27,8 @@ 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = strlen(msg); char buf[1024] = {0}; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); @@ -67,13 +62,8 @@ void write_0100(void) 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = 0; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); if (fd == -1) { @@ -96,13 +86,8 @@ void write_0200(void) 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = strlen(msg) + 1; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); if (fd == -1) { @@ -125,13 +110,8 @@ void write_0300(void) 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = strlen(msg); int fd = open(path, O_RDWR); int result = write(fd, msg, len); @@ -150,13 +130,8 @@ void write_0400(void) 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"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = 1; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); if (fd == -1) {