#include #include #include #include #include #define TEST_MAX_FILES 16356 int main(int argc, const char **argv) { int files[TEST_MAX_FILES]; char filename[256]; int cur; int i; pid_t my_pid; const char *base_name="file_test"; const char *test_file="file_test_trunc"; const char test_output[] ="This is a test"; int parent = 1; int fd; int err; fd = open(test_file, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU); if (fd < 0) { perror("open"); return -1; } err = write(fd, test_output, sizeof(test_output)); if (err != sizeof(test_output)) { if (err < 0) { perror("write"); } else { fprintf(stderr, "Only %d bytes output to file.\n", err); } return -1; } close(fd); for (i = 0; i < 32; i++) { pid_t pid; pid = fork(); if (pid == 0) { parent = 0; break; } } my_pid = getpid(); for (cur = 0; cur < TEST_MAX_FILES; cur++) { sprintf(filename, "%s%d_%d", base_name, my_pid, cur); files[cur] = open(filename, O_TRUNC | O_CREAT | O_RDWR, S_IRWXU); if (files[cur] < 0) { break; } } printf("%d files opened successfully.\n"); if (parent) { fd = open(test_file, O_TRUNC | O_RDWR); if (fd < 0) { printf("Open of \"%s\" failed, as expected.\n", test_file); } else { printf("Open of \"%s\" succeeded. Wierd.\n", test_file); close(fd); } } while(1) { sleep(30); } return 0; }