summaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/ansi/fopen.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:52 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 18:24:51 -0500
commitf5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch)
tree93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/tests/ansi/fopen.c
parentbd5969fc876a10b18613302db7087ef3c40f18e1 (diff)
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/ansi/fopen.c')
-rw-r--r--lib/mlibc/tests/ansi/fopen.c59
1 files changed, 0 insertions, 59 deletions
diff --git a/lib/mlibc/tests/ansi/fopen.c b/lib/mlibc/tests/ansi/fopen.c
deleted file mode 100644
index f4818b2..0000000
--- a/lib/mlibc/tests/ansi/fopen.c
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#ifdef USE_HOST_LIBC
-#define TEST_FILE "fopen-host-libc.tmp"
-#else
-#define TEST_FILE "fopen.tmp"
-#endif
-
-int main() {
- FILE *file;
- char str[] = "mlibc fopen test";
- char str2[] = " mlibc appending";
- char completestr[] = "mlibc fopen test mlibc appending";
- char buffer[100];
- char buffer2[100];
-
- // Clear all the buffers to zero.
- memset(buffer, 0, sizeof(buffer));
- memset(buffer2, 0, sizeof(buffer2));
-
- // Open the file for writing.
- file = fopen(TEST_FILE, "w");
- assert(file);
-
- // Write string minus null terminator, flush and close.
- fwrite(str, 1, sizeof(str) - 1, file);
- fflush(file);
- fclose(file);
-
- // Open the file for reading.
- file = fopen(TEST_FILE, "r");
- assert(file);
-
- // Verify that we read back the written string and close the file.
- assert(fread(buffer, 1, sizeof(str) - 1, file));
- assert(!strcmp(buffer, str));
- fclose(file);
-
- // Open the file in appending mode, append string 2 (minus the null terminator) to the file, flush and close.
- file = fopen(TEST_FILE, "a");
- fwrite(str2, 1, sizeof(str2) - 1, file);
- fflush(file);
- fclose(file);
-
- // Open the file for reading again, verify the contents, close the file and return.
- file = fopen(TEST_FILE, "r");
- assert(fread(buffer2, 1, sizeof(completestr) - 1, file));
- assert(!strcmp(buffer2, completestr));
- fclose(file);
-
- // Check that stdout, stdin and stderr can be closed by the application (issue #12).
- fclose(stdout);
- fclose(stdin);
- fclose(stderr);
-
- return 0;
-}