⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symlink01.c

📁 cygwin, 著名的在win32下模拟unix操作系统的东东
💻 C
📖 第 1 页 / 共 5 页
字号:
char *path1, *path2, *path3;{   if (ck_symlink(path1, path2, path3) == 0)      return(0);   else if ((stat(path3, &statter) == -1) && (errno == ENOENT)) {      TEST_RESULT=TBROK;      sprintf(test_msg, "stat(2) Failure when accessing %s object file ", path3);      return(0);   }   else if ((stat(path2, &asymlink) == -1) && (errno == ENOENT)) {      TEST_RESULT=TBROK;      sprintf(test_msg, "stat(2) Failure when accessing %s symbolic link file ",	path2);      return(0);   }   else if (statter.st_ino != asymlink.st_ino) {      TEST_RESULT=TBROK;      sprintf(test_msg,	"stat(2) Failure when accessing %s object file through %s symbolic link file ",	path3, path2);      return(0);   }   return(1);   }/*********************************************************************** * This routine populates full_path with a pathname whose length exceeds * the PATH_MAX define value in param.h * *      Argument one is a pathname of object file *      Argument two is symbolic link file name *      Argument three is regular file name ***********************************************************************/intcreat_path_max(path1, path2, path3)char *path1, *path2, *path3;{   int ctr, to_go, size, whole_chunks;   char buf [PATH_MAX];   char *cwd;   if ((cwd = getcwd(buf, sizeof (buf))) == NULL)   {      TEST_RESULT=TBROK;      sprintf(test_msg,	"getcwd(3) Failure in setup of %s %s %s test case object elements",	path1, path2, path3);      return(0);   }   size = strlen(cwd);   to_go = PATH_MAX - size;   size = strlen(path1);   whole_chunks = to_go / size;   strcpy(full_path, cwd);   for (ctr=0; ctr < whole_chunks; ctr++) {       strcat(full_path, path1);   }   size= strlen(full_path);   to_go = PATH_MAX - size;   strcat(full_path, "/");   for (ctr=0; ctr < to_go; ctr++)       strcat(full_path, "Z");   return(1);}/*********************************************************************** * This routine checks that full_path's  length exceeds the PATH_MAX * define value in param.h * *      Argument one is a pathname of object file *      Argument two is symbolic link file name *      Argument three is regular file name ***********************************************************************/intck_path_max(path1, path2, path3)char *path1, *path2, *path3;{   if (strlen(full_path) == (PATH_MAX+1))      return(1);   else   {      TEST_RESULT=TBROK;      sprintf(test_msg, "%s %d %s %s %s %s",	"full_path character array length was not", (PATH_MAX+1),	"characters long for test case object elements",	path1, path2, path3);      return(0);   }}/*********************************************************************** * This routine checks if the stat(2) and lstat(2) calls return the same * information when the path is not a symbolic link file * *      Argument one is a pathname of object file *      Argument two is symbolic link file name *      Argument three is regular file name * ***********************************************************************/intck_object(path1, path2, path3)char *path1, *path2, *path3;{    int ret;    if ((ret=see_if_a_symlink(path1)) < 0) {       TEST_RESULT=TFAIL;       sprintf(test_msg,	   "lstat(2) failed to return inode information for a regular object file");       return(0);    }    else if (ret == 1) {       TEST_RESULT=TFAIL;       sprintf(test_msg, 	   "lstat(2) detected a regular object file as a symbolic link file");       return(0);    }    else if (stat(path1, &statter) == -1) {       TEST_RESULT=TBROK;       sprintf(test_msg,	   "stat(2) failed to return inode information for a regular object file");       return(0);    }    else if (bcmp((char *)&statter, (char *)&asymlink, sizeof(statter)) != 0) {       TEST_RESULT=TFAIL;       sprintf(test_msg,	   "lstat(2) and stat(2) do not return same inode information for an object file");       return(0);            }    return(1);}/*********************************************************************** * Main test case processing function * *  Argument is a ptr into the all_tcses array of structures of type tcses ***********************************************************************/intdo_syscalltests(tcs)struct tcses *tcs;{   int ctr, ret;   struct all_test_cases *tc_ptr;   /*    * loop through desired number of test cases    */   for (ctr=0, tc_ptr=tcs->tc_ptr; ctr < TST_TOTAL; ctr++, tc_ptr++) {       if (tc_ptr->test_fail < 0) continue;       Buffer[0]='\0';       /*	* If running all test cases for all tcid, set the TCID if needed.        */       if ( Selectedtests == NULL ) {	   if ( !TCID || strcmp(TCID, tc_ptr->tcid) != 0 ) {               TCID = tc_ptr->tcid;               Tst_count=0;	   }       }       /*        * Insure that we are executing the correct tcs test case        */       if (strcmp(TCID, tc_ptr->tcid) != 0) {          tst_resm(TBROK, "%s TCID attempted to execute %s %d %d test case",	     TCID, tc_ptr->tcid, tc_ptr->test_fail, tc_ptr->errno_val);          continue;       }       TEST_RESULT=TPASS;       delete_files(S_FILE, O_FILE);       /*         * Perform test case setup        */       ret = (tc_ptr->test_setup)(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],	   tc_ptr->fn_arg[2], tc_ptr->errno_val);       /* If an expected error, try it out */       if (tc_ptr->test_fail) {          /*            * Try to perform test verification function           */          if (! (tc_ptr->ck_test)(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],			tc_ptr->fn_arg[2], tc_ptr->errno_val))             tst_resm(TEST_RESULT, test_msg);          else if (tc_ptr->errno_val == EEXIST)             do_EEXIST(tc_ptr);          else if (tc_ptr->errno_val == ENOENT)             do_ENOENT(tc_ptr);          else if (tc_ptr->errno_val == ELOOP)             do_ELOOP(tc_ptr);          else if (tc_ptr->errno_val == ENOTDIR)             do_ENOTDIR(tc_ptr);          else if (tc_ptr->errno_val == EXDEV)             do_EXDEV(tc_ptr);          else if (tc_ptr->errno_val == ENAMETOOLONG)             do_ENAMETOOLONG(tc_ptr);          else if (tc_ptr->errno_val == EINVAL)             do_EINVAL(tc_ptr);          else             tst_resm(TBROK, "Test Case Declaration Error");       }       else if (ret == 1) {  /*  No setup function error */           if (tc_ptr->errno_val != 0)             tst_resm(TBROK, "Test Case Declaration Error");          else {             /*               * Perform test verification function              */             ret=(tc_ptr->ck_test)(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],		tc_ptr->fn_arg[2], tc_ptr->errno_val);             /* Perform requested symbolic link system call test */             if ((cktcsid(tc_ptr->tcid, SYMLINK)) ||				(cktcsid(tc_ptr->tcid, LSTAT))) {                if (ret == 1)                   tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);                   else                   tst_resm(TEST_RESULT, test_msg);             }             else if (ret == 0)                tst_resm(TEST_RESULT, test_msg);             else if (cktcsid(tc_ptr->tcid, READLINK))                do_readlink(tc_ptr);             else if (cktcsid(tc_ptr->tcid, STAT))                do_stat(tc_ptr);             else if (cktcsid(tc_ptr->tcid, CHDIR))                do_chdir(tc_ptr);             else if (cktcsid(tc_ptr->tcid, LINK))                do_link(tc_ptr);             else if (cktcsid(tc_ptr->tcid, UNLINK))                do_unlink(tc_ptr);             else if (cktcsid(tc_ptr->tcid, CHMOD))                do_chmod(tc_ptr);             else if (cktcsid(tc_ptr->tcid, UTIME))                do_utime(tc_ptr);             else if (cktcsid(tc_ptr->tcid, RENAME))                do_rename(tc_ptr);             else if (cktcsid(tc_ptr->tcid, OPEN))                do_open(tc_ptr);             else                tst_resm(TBROK, "Unknown test case processing actions declared");          }       }       else          tst_resm(TBROK, "Test Case Declaration Error");   }   return(0);}/*********************************************************************** * This routine checks for the return of EEXIST errno from requested * system call * *   Argument is pointer to test_objects array of structures of type *   all_test_cases ***********************************************************************/voiddo_EEXIST(tc_ptr)struct all_test_cases *tc_ptr;{    if (cktcsid(tc_ptr->tcid, SYMLINK)) {       TEST( symlink(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1]) );	errno=TEST_ERRNO;       if ((TEST_RETURN == -1) && (errno == EEXIST))	   if ( STD_FUNCTIONAL_TEST )               tst_resm(TPASS, msgs[tc_ptr->pass_msg]);	   else		Tst_count++;       else           tst_resm(TFAIL, "%s %s",		"Expected EEXIST error when creating a symbolic link file",		"which already existed");     }     else if (cktcsid(tc_ptr->tcid, MKDIR)) {	TEST ( mkdir(tc_ptr->fn_arg[1],MODE) );	errno=TEST_ERRNO;        if ((TEST_RETURN == -1) && (errno == EEXIST))	   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",		"Expected EEXIST error when creating a directory by a symbolic",		"link file which pointed at no object file");           rmdir(tc_ptr->fn_arg[1]);        }     }     else if (cktcsid(tc_ptr->tcid, OPEN)) {        TEST( open(tc_ptr->fn_arg[1], (O_EXCL | O_CREAT)) ) 	errno=TEST_ERRNO;        if ((TEST_RETURN == -1) && (errno == EEXIST))	   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 EEXIST error for exclusively opening an 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 ENOENT errno from requested * system call * *   Argument is pointer to test_objects array of structures of type *   all_test_cases ***********************************************************************/voiddo_ENOENT(tc_ptr)struct all_test_cases *tc_ptr;{     if (cktcsid(tc_ptr->tcid, STAT)) {        if ((stat(tc_ptr->fn_arg[1], &asymlink) == -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 stating a non-existent directory",		"through a symbolic link file was not received:",	  	errno, strerror(errno));     }     else if (cktcsid(tc_ptr->tcid, CHDIR)) {        if ((chdir(tc_ptr->fn_arg[1]) == -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 changing to a non-existent",		"directory through a symbolic link file was not received:",		errno, strerror(errno));           chdir(TESTDIR);        }     }     else if (cktcsid(tc_ptr->tcid, LINK)) {        if ((link(tc_ptr->fn_arg[1], "nick") == -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 condition when link(2) a symbolic",		"link which pointed at no object:", errno, strerror(errno));           delete_files("nick", NULL);        }     }     else if (cktcsid(tc_ptr->tcid, CHMOD)) {        if ((chmod(tc_ptr->fn_arg[1], MODE) == -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 condition when chmod(2) a symbolic",		"link which pointed at no object,", errno, strerror(errno));     }     else if (cktcsid(tc_ptr->tcid, UTIME)) {        if ((utime(tc_ptr->fn_arg[1], NULL) == -1) && (errno == ENOENT))	   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 + -