📄 symlink01.c
字号:
else tst_resm(TFAIL, "%s %s errno:%d %s", "Expected ENOENT error condition when utime(2) a symbolic", "link which pointed at no object:", errno, strerror(errno)); } else if (cktcsid(tc_ptr->tcid, OPEN)) { if ((open(tc_ptr->fn_arg[1], O_RDWR) == -1) && (errno == ENOENT)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s %s errno:%d %s", "Expected ENOENT error for opening a non-existent object", " file through a symbolic link file was not received,", errno, strerror(errno)); close (TEST_RETURN); } else tst_resm(TBROK, "Unknown test case processing actions declared");}/*********************************************************************** * This routine checks for the return of ELOOP errno from requested * system call * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_ELOOP(tc_ptr)struct all_test_cases *tc_ptr;{ if (cktcsid(tc_ptr->tcid, STAT)) { TEST( stat(tc_ptr->fn_arg[1], &asymlink) ); errno=TEST_ERRNO; if ((TEST_RETURN == -1) && (errno == ELOOP)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, "%s errno:%d %s", "Expected ELOOP errno from stat(2) (nested symb link),", errno, strerror(errno)); else Tst_count++; } else if (cktcsid(tc_ptr->tcid, CHDIR)) { TEST( chdir(tc_ptr->fn_arg[1]) ); errno=TEST_ERRNO; if ((TEST_RETURN == -1) && (errno == ELOOP)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else { tst_resm(TFAIL, "%s errno:%d %s", "Expected ELOOP error condition when chdir(2) a nested symbolic link:", errno, strerror(errno)); chdir(TESTDIR); } } else if (cktcsid(tc_ptr->tcid, LINK)) { TEST ( link(tc_ptr->fn_arg[1], O_FILE) ); errno=TEST_ERRNO; if ((TEST_RETURN == -1) && (errno == ELOOP)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s errno:%d %s", "Expected ELOOP error condition when link(2) a nested symbolic link:", errno, strerror(errno)); } else if (cktcsid(tc_ptr->tcid, CHMOD)) { TEST ( chmod(tc_ptr->fn_arg[1], MODE) ); errno=TEST_ERRNO; if ((TEST_RETURN == -1) && (errno == ELOOP)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s errno:%d %s", "Expected ELOOP error condition when chmod(2) a nested symbolic link:", errno, strerror(errno)); return; } else if (cktcsid(tc_ptr->tcid, UTIME)) { TEST( utime(tc_ptr->fn_arg[1], NULL) ); errno=TEST_ERRNO; if ((TEST_RETURN == -1) && (errno == ELOOP)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s errno:%d %s", "Expected ELOOP error condition when utime(2) a nested symbolic link:", errno, strerror(errno)); } else if (cktcsid(tc_ptr->tcid, OPEN)) { int fd; TEST( open(tc_ptr->fn_arg[1], O_CREAT) ); fd=TEST_RETURN; errno=TEST_ERRNO; if ((fd == -1) && (errno == ELOOP)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s errno:%d %s", "Expected ELOOP error condition when open(2) a nested symbolic link:", errno, strerror(errno)); close (fd); } else tst_resm(TBROK, "Unknown test case processing actions declared");}/*********************************************************************** * This routine checks for the return of ENOTDIR errno from requested * system call * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_ENOTDIR(tc_ptr)struct all_test_cases *tc_ptr;{ if (cktcsid(tc_ptr->tcid, RMDIR)) { TEST( mkdir(tc_ptr->fn_arg[0], MODE) ); errno=TEST_ERRNO; if (TEST_RETURN == -1) tst_resm(TBROK, "mkdir(2) Failure when creating %s", tc_ptr->fn_arg[0]); else if ((rmdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOTDIR)) { if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; rmdir(tc_ptr->fn_arg[0]); } else tst_resm(TFAIL, "%s %s errno:%d %s", "Expected ENOTDIR error for removing a non-existent", "directory through a symbolic link file was not received,", errno, strerror(errno)); } else tst_resm(TBROK, "Unknown test case processing actions declared");}/*********************************************************************** * This routine checks for the return of EXDEV errno from requested * system call * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_EXDEV(tc_ptr)struct all_test_cases *tc_ptr;{ if (cktcsid(tc_ptr->tcid, RENAME)) { TEST( rename(tc_ptr->fn_arg[1], Y_A_S_FILE) ); errno=TEST_ERRNO; if ((TEST_RETURN == -1) && (errno == EXDEV)) { if (see_if_a_symlink(Y_A_S_FILE) == -1) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s %s %s file outside of current file system", "rename(3) returned -1 when trying to move symbolic link file", "outside of current file system, but created", Y_A_S_FILE); } else { tst_resm(TFAIL, "%s %s errno:%d %s", "Expected EXDEV error for renaming an existing symbolic", "link file to a location outside of existing file system,", errno, strerror(errno)); delete_files("/NiCkEr", NULL); } } else tst_resm(TBROK, "Unknown test case processing actions declared");}/*********************************************************************** * This routine checks for the return of ENAMETOOLONG errno from requested * system call * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_ENAMETOOLONG(tc_ptr)struct all_test_cases *tc_ptr;{ int ret; if (cktcsid(tc_ptr->tcid, SYMLINK)) { TEST( symlink(tc_ptr->fn_arg[0], full_path) ); errno=TEST_ERRNO; if ((TEST_RETURN == -1) && (errno == ENAMETOOLONG)) if (see_if_a_symlink(full_path) == -1) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "%s %s %d %s", "symlink(2) returned -1 when trying to create a symbolic", "link file whose name exceeded", (PATH_MAX+1), "characters, but it created the symbolic link file"); else tst_resm(TFAIL, "Expected ENAMETOOLONG error when creating %s symbolic link file with a path exceeding %d characters: errno:%d %s", tc_ptr->fn_arg[1], (PATH_MAX+1), errno, strerror(errno)); } else if (cktcsid(tc_ptr->tcid, READLINK)) { char scratch[PATH_MAX+1]; ret=readlink(full_path, scratch, strlen(full_path)); if (( ret == -1) && (errno == ENAMETOOLONG)) if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; else tst_resm(TFAIL, "Expected ENAMETOOLONG error when reading %s symbolic link file with a path exceeding %d characters: errno:%d %s", tc_ptr->fn_arg[1], (PATH_MAX+1), errno, strerror(errno)); } else tst_resm(TBROK, "Unknown test case processing actions declared");}/*********************************************************************** * This routine checks for the return of EINVAL errno from requested * system call * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_EINVAL(tc_ptr)struct all_test_cases *tc_ptr;{ if (cktcsid(tc_ptr->tcid, READLINK)) { TEST( readlink(tc_ptr->fn_arg[0], test_msg, BUFMAX) ); errno=TEST_ERRNO; if (TEST_RETURN == -1) { if (errno == EINVAL) { if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++; } else tst_resm(TFAIL, "readlink(2) ret:-1, errno:%d, : Exp errno:%d", errno, EINVAL); } else { tst_resm(TFAIL, "readlink(2) did not returned -1 when reading %s", "a file which is not a symbolic link file"); } } else tst_resm(TBROK, "Unknown test case processing actions declared");}/*********************************************************************** * This routine checks out the readlink(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_readlink(tc_ptr)struct all_test_cases *tc_ptr;{ char scratch[PATH_MAX]; int ret; ret=readlink(tc_ptr->fn_arg[1], scratch, strlen(tc_ptr->fn_arg[0])); /*** the TEST macro cannot be used here for some reason ****/ if (ret == -1) { tst_resm(TFAIL, "readlink(2) failure on %s symbolic link file, errno=%d", tc_ptr->fn_arg[1], errno); } else if (strncmp(tc_ptr->fn_arg[0], scratch, strlen(tc_ptr->fn_arg[0])) != 0) { /* Must null terminate scratch because readlink(2) doesn't */ scratch[strlen(tc_ptr->fn_arg[0])] = '\0'; tst_resm(TFAIL, "readlink(2) Error : Expected %s symbolic link file contents but %s actual contents were returned", tc_ptr->fn_arg[0], scratch); } else if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++;}/*********************************************************************** * This routine checks out the stat(2) system call for a successful * invocation * * Argument is pointer to test_objects array of structures of type * all_test_cases ***********************************************************************/voiddo_stat(tc_ptr)struct all_test_cases *tc_ptr;{ if (statter.st_dev != asymlink.st_dev) tst_resm(TFAIL, "stat of symbolic link reference to object device info %ld != stat of object file device info %ld", statter.st_dev, asymlink.st_dev); else if (statter.st_mode != asymlink.st_mode) tst_resm(TFAIL, "stat of symbolic link reference to object file permissions %ld != stat of object file permissions %ld", statter.st_mode, asymlink.st_mode); else if (statter.st_nlink != asymlink.st_nlink) tst_resm(TFAIL, "stat of symbolic link reference to object file link count %ld != stat of object file link count %ld", statter.st_nlink, asymlink.st_nlink); else if (statter.st_uid != asymlink.st_uid) tst_resm(TFAIL, "stat of symbolic link reference to object file uid %ld != stat of object file uid %ld", statter.st_uid, asymlink.st_uid); else if (statter.st_gid != asymlink.st_gid) tst_resm(TFAIL, "stat of symbolic link reference to object file gid %ld != stat of object file gid %ld", statter.st_gid, asymlink.st_gid); else if (statter.st_size != asymlink.st_size) tst_resm(TFAIL, "stat of symbolic link reference to object file size %ld != stat of object file size %ld", statter.st_size, asymlink.st_size); else if (statter.st_atime != asymlink.st_atime) tst_resm(TFAIL, "stat of symbolic link reference to object access time %ld != stat of object file access time %ld", statter.st_atime, asymlink.st_atime); else if (statter.st_mtime != asymlink.st_mtime) tst_resm(TFAIL, "stat of symbolic link reference to object modify time %ld != stat of object file modify time %ld", statter.st_atime, asymlink.st_atime); else if (statter.st_ctime != asymlink.st_ctime) tst_resm(TFAIL, "stat of symbolic link reference to object change time %ld != stat of object file change time %ld", statter.st_atime, asymlink.st_atime); else if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST ) tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]); else Tst_count++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -