8000 minix/test/test25.c at v3.1.2a · i-spark/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
726 lines (644 loc) · 23.2 KB

test25.c

File metadata and controls

726 lines (644 loc) · 23.2 KB
}
}
/* Clean up the noread and nowrite files. */
System("rm -rf noread nowrite");
/* Test the O_EXCL flag. */
System("echo > exists");
if (open("exists", O_RDWR | O_CREAT | O_EXCL, 0777) != -1) e(30);
if (errno != EEXIST) e(31);
if (open("exists", O_RDONLY | O_CREAT | O_EXCL, 0777) != -1) e(32);
if (errno != EEXIST) e(33);
if (open("exists", O_WRONLY | O_CREAT | O_EXCL, 0777) != -1) e(34);
if (errno != EEXIST) e(35);
fd = open("exists", O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0777);
if (fd != -1) e(36);
if (errno != EEXIST) e(37);
fd = open("exists", O_RDONLY | O_CREAT | O_EXCL | O_TRUNC, 0777);
if (fd != -1) e(38);
if (errno != EEXIST) e(39);
fd = open("exists", O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0777);
if (fd != -1) e(40);
if (errno != EEXIST) e(41);
/* Test ToLongName and ToLongPath */
if ((fd = open(ToLongName, O_RDWR | O_CREAT, 0777)) != 3) e(45);
if (close(fd) != 0) e(46);
ToLongPath[PATH_MAX - 2] = '/';
ToLongPath[PATH_MAX - 1] = 'a';
if ((fd = open(ToLongPath, O_RDWR | O_CREAT, 0777)) != -1) e(47);
if (errno != ENAMETOOLONG) e(48);
if (close(fd) != -1) e(49);
ToLongPath[PATH_MAX - 1] = '/';
}
void makelongnames()
{
register int i;
memset(MaxName, 'a', NAME_MAX);
MaxName[NAME_MAX] = '\0';
for (i = 0; i < PATH_MAX - 1; i++) { /* idem path */
MaxPath[i++] = '.';
MaxPath[i] = '/';
}
MaxPath[PATH_MAX - 1] = '\0';
strcpy(ToLongName, MaxName); /* copy them Max to ToLong */
strcpy(ToLongPath, MaxPath);
ToLongName[NAME_MAX] = 'a';
ToLongName[NAME_MAX + 1] = '\0'; /* extend ToLongName by one too many */
ToLongPath[PATH_MAX - 1] = '/';
ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */
}
void e(n)
int n;
{
int err_num = errno; /* Save in case printf clobbers it. */
printf("Subtest %d, error %d errno=%d: ", subtest, n, errno);
errno = err_num;
perror("");
if (errct++ > MAX_ERROR) {
printf("Too many errors; test aborted\n");
chdir("..");
system("rm -rf DIR*");
exit(1);
}
errno = 0;
}
void quit()
{
Chdir("..");
System("rm -rf DIR_25");
if (errct == 0) {
printf("ok\n");
exit(0);
} else {
printf("%d errors\n", errct);
exit(1);
}
}
0