From e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad Mon Sep 17 00:00:00 2001 From: klaar36 Date: Fri, 20 Mar 2015 17:30:24 +0100 Subject: Initial Pintos --- src/examples/create_remove_file.c | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/examples/create_remove_file.c (limited to 'src/examples/create_remove_file.c') diff --git a/src/examples/create_remove_file.c b/src/examples/create_remove_file.c new file mode 100644 index 0000000..93f191e --- /dev/null +++ b/src/examples/create_remove_file.c @@ -0,0 +1,58 @@ +/* klaar@ida +*/ + +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + char buf[40]; + char ref[40]; + int loops; + int i, n; + int fd; + + if (argc != 3) + { + printf("%s: bad arguments\n", argv[0]); + return 1; + } + + loops = atoi(argv[2]); + + for (i = 0; i < loops; ++i) + { + if ( create(argv[1], 500) ) + { + snprintf(ref, 40, "file '%s' iteration %d", argv[1], i); + fd = open(argv[1]); + remove(argv[1]); + + write(fd, ref, strlen(ref)); + seek(fd, 0); + for (n = 0; n < 100; ++n) + ; + read(fd, buf, 40); + close(fd); + + if (strcmp(ref, buf) != 0) + { + printf("%s: ERROR bad file content\n", argv[0]); + printf("%s: written : '%s'\n", argv[0], ref); + printf("%s: read back: '%s'\n", argv[0], buf); + exit(1); + } + + if ( (i * 10000 / loops) % 1000 == 0 ) + printf("%s: %d%% done\n", argv[0], (i * 100 / loops)); + } + else + { + printf("%s: ERROR create '%s' failed\n", argv[0], argv[1]); + exit(1); + } + } + return 0; +} -- cgit v1.2.1