Exemplo n.º 1
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	int rval, fd;
	int count;
	const int cnum = 141;	/* system call number 141 = getdents */
	size_t size = 0;
	char *dir_name = NULL;
	struct dirent *dirp;

	/* parse standard options */
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}

	setup();		/* global setup */

	/* The following loop checks looping state if -i option given */

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		/* get the current working directory */

		if ((dir_name = getcwd(dir_name, size)) == NULL) {
			tst_brkm(TBROK, cleanup, "Can not get current "
				 "directory name");
		}

		/* allocate some space for the dirent structure */

		if ((dirp =
		     (struct dirent *)malloc(sizeof(struct dirent))) == NULL) {
			tst_brkm(TBROK, cleanup, "malloc failed");
		}

		/* set up count to be equal to the sizeof struct dirent */

		count = (int)sizeof(struct dirent);

		/* set up a bad file descriptor */

		fd = -5;

		/*
		 * here's a case where invoking the system call directly
		 * doesn't seem to work.  getdents.h has an assembly
		 * macro to do the job.
		 *
		 * equivalent to  - getdents(fd, dirp, count);
		 * if we could call getdents that way.
		 */

		rval = GETDENTS_ASM();

		/*
		 * Hopefully we get an error due to the bad file descriptor.
		 */

		if (rval < 0) {	/* call returned an error */
			rval *= -1;
			TEST_ERROR_LOG(rval);

			switch (rval) {
			case EBADF:
				tst_resm(TPASS, "expected failure - errno = %d "
					 "- %s", rval, strerror(rval));
				break;
			default:
				tst_resm(TFAIL, "%s call failed to "
					 "produce EBADF - errno = %d : %s",
					 TCID, rval, strerror(rval));
				break;
			}
		} else {
			tst_resm(TFAIL, "call failed to produce an "
				 "expected error - errno = %d - %s", rval,
				 strerror(rval));
		}

		/*
		 * clean up things in case we are looping
		 */
		free(dir_name);
		dir_name = NULL;

		free(dirp);
	}

	cleanup();

	tst_exit();
}
Exemplo n.º 2
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	int count, rval, fd;
	const int cnum = 141;
	size_t size = 0;
	char *dir_name = NULL;
	struct dirent *dirp;
	struct stat *sbuf;
	char *newfile;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		Tst_count = 0;

		if ((dir_name = getcwd(dir_name, size)) == NULL)
			tst_brkm(TBROK, cleanup, "Can not get current "
				 "directory name");

		if ((dirp = malloc(sizeof(struct dirent))) == NULL)
			tst_brkm(TBROK, cleanup, "malloc failed");

		count = (int)sizeof(struct dirent);

		/* set up some space for a file name */
		if ((newfile = malloc(sizeof(char) * 20)) == NULL)
			tst_brkm(TBROK, cleanup, "newfile malloc failed");

		if ((rval = sprintf(newfile, "getdents03.%d", getpid())) < 0)
			tst_brkm(TBROK, cleanup, "sprintf failed");

		if ((fd = open(newfile, O_CREAT | O_RDWR, 0777)) == -1)
			tst_brkm(TBROK|TERRNO, cleanup, "open of file failed");

		/* set up some space for the stat buffer */
		if ((sbuf = malloc(sizeof(struct stat))) == NULL)
			tst_brkm(TBROK, cleanup, "stat malloc failed");

		/* make sure fd is not a directory */
		if ((rval = fstat(fd, sbuf)) == -1)
			tst_brkm(TBROK, cleanup, "fstat failed");

		if (S_ISDIR(sbuf->st_mode))
			tst_brkm(TBROK, cleanup, "fd is a directory");

		/*
		 * here's a case where invoking the system call directly
		 * doesn't seem to work.  getdents.h has an assembly
		 * macro to do the job.
		 *
		 * equivalent to getdents(fd, dirp, count);
		 */

		rval = GETDENTS_ASM();

		/*
		 * Calling with a non directory file descriptor should give
		 * an ENOTDIR error.
		 */

		if (rval < 0) {
			rval *= -1;
			TEST_ERROR_LOG(rval);

			switch (rval) {
			case ENOTDIR:
				tst_resm(TPASS,
				    "getdents failed as expected with ENOTDIR");
				break;
			default:
				tst_resm(TFAIL|TERRNO,
				    "getdents failed unexpectedly");
				break;
			}
		} else
			tst_resm(TFAIL, "getdents call succeeded unexpectedly");

		free(dir_name);
		dir_name = NULL;

		free(dirp);

		if ((rval = close(fd)) == -1)
			tst_brkm(TBROK, cleanup, "fd close failed");
		if ((rval = unlink(newfile)) == -1)
			tst_brkm(TBROK, cleanup, "file unlink failed");
	}

	cleanup();

	tst_exit();
}
Exemplo n.º 3
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	int count, rval, fd;
	const int cnum = 141;
	size_t size = 0;
	char *dir_name = NULL;
	struct dirent *dirp;
	struct stat *sbuf;
	char *newfile;

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
	}

	setup();		/* global setup */

	/* The following loop checks looping state if -i option given */

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		/* get the current working directory */
		if ((dir_name = getcwd(dir_name, size)) == NULL) {
			tst_brkm(TBROK, cleanup, "Can not get current "
				 "directory name");
		}

		/* allocate some space for the dirent structure */
		if ((dirp =
		     (struct dirent *)malloc(sizeof(struct dirent))) == NULL) {
			tst_brkm(TBROK, cleanup, "malloc failed");
		}

		/* set up count to be equal to the sizeof struct dirent */
		count = (int)sizeof(struct dirent);

		/* Now create a new file and get its file descriptor. */

		/* set up some space for a file name */
		if ((newfile = (char *)malloc(sizeof(char) * 20)) == NULL) {
			tst_brkm(TBROK, cleanup, "newfile malloc failed");
		}

		/* create (hopefully) a unique file name */
		if ((rval = sprintf(newfile, "getdents03.%d", getpid())) < 0) {
			tst_brkm(TBROK, cleanup, "sprintf failed");
		}

		if ((fd = open(newfile, O_CREAT | O_RDWR, 0777)) == -1) {
			perror("file open");
			tst_brkm(TBROK, cleanup, "open of file failed");
		}

		/* set up some space for the stat buffer */
		if ((sbuf = (struct stat *)malloc(sizeof(struct stat))) == NULL) {
			tst_brkm(TBROK, cleanup, "stat malloc failed");
		}

		/* make sure fd is not a directory */
		if ((rval = fstat(fd, sbuf)) == -1) {
			tst_brkm(TBROK, cleanup, "fstat failed");
		}

		if (S_ISDIR(sbuf->st_mode)) {
			tst_brkm(TBROK, cleanup, "fd is a directory");
		}

		/*
		 * here's a case where invoking the system call directly
		 * doesn't seem to work.  getdents.h has an assembly
		 * macro to do the job.
		 *
		 * equivalent to getdents(fd, dirp, count);
		 */

		rval = GETDENTS_ASM();

		/*
		 * Calling with a non directory file descriptor should give
		 * an ENOTDIR error.
		 */

		if (rval < 0) {	/* call returned an error */
			rval *= -1;
			TEST_ERROR_LOG(rval);

			switch (rval) {
			case ENOTDIR:
				tst_resm(TPASS, "expected failure - errno = %d "
					 "- %s", rval, strerror(rval));
				break;
			default:
				tst_resm(TFAIL, "%s call failed to "
					 "produce EBADF - errno = %d : %s",
					 TCID, rval, strerror(rval));
				break;
			}
		} else {
			tst_resm(TFAIL, "call failed to produce an "
				 "expected error - errno = %d - %s", rval,
				 strerror(rval));
		}

		/*
		 * clean up things in case we are looping
		 */
		free(dir_name);
		dir_name = NULL;

		free(dirp);

		if ((rval = close(fd)) == -1) {
			tst_brkm(TBROK, cleanup, "fd close failed");
		}
		if ((rval = unlink(newfile)) == -1) {
			tst_brkm(TBROK, cleanup, "file unlink failed");
		}
	}

	cleanup();

	 /*NOTREACHED*/ return 0;
}
Exemplo n.º 4
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	int rval, fd;
	int count;
	const int cnum = __NR_getdents;
	size_t size = 0;
	char *dir_name = NULL;
	struct dirent *dirp;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		Tst_count = 0;

		if ((dir_name = getcwd(dir_name, size)) == NULL)
			tst_brkm(TBROK, cleanup, "Can not get current "
				 "directory name");

		if ((dirp = malloc(sizeof(struct dirent))) == NULL)
			tst_brkm(TBROK, cleanup, "malloc failed");

		count = (int)sizeof(struct dirent);

		/* set up a bad file descriptor */

		fd = -5;

		/*
		 * here's a case where invoking the system call directly
		 * doesn't seem to work.  getdents.h has an assembly
		 * macro to do the job.
		 *
		 * equivalent to  - getdents(fd, dirp, count);
		 * if we could call getdents that way.
		 */

		rval = GETDENTS_ASM();

		/*
		 * Hopefully we get an error due to the bad file descriptor.
		 */
		if (rval < 0) {
			rval *= -1;
			TEST_ERROR_LOG(rval);

			switch (rval) {
			case EBADF:
				tst_resm(TPASS,
				    "failed as expected with EBADF");
				break;
			default:
				tst_resm(TFAIL|TERRNO,
				    "getdents failed unexpectedly");
				break;
			}
		} else
			tst_resm(TFAIL, "call succeeded unexpectedly");

		free(dir_name);
		dir_name = NULL;

		free(dirp);
	}

	cleanup();

	tst_exit();
}