diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:52 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-07 18:24:51 -0500 |
commit | f5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch) | |
tree | 93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/tests/posix/open_memstream.c | |
parent | bd5969fc876a10b18613302db7087ef3c40f18e1 (diff) |
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/posix/open_memstream.c')
-rw-r--r-- | lib/mlibc/tests/posix/open_memstream.c | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/lib/mlibc/tests/posix/open_memstream.c b/lib/mlibc/tests/posix/open_memstream.c deleted file mode 100644 index 0347003..0000000 --- a/lib/mlibc/tests/posix/open_memstream.c +++ /dev/null @@ -1,65 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - -#define WRITE_NO 1024 - -int main() { - size_t size; - char *buf; - - FILE *fp = open_memstream(&buf, &size); - assert(fp); - - char c = 'A'; - for (size_t i = 0; i < WRITE_NO; i++) - assert(fwrite(&c, sizeof(char), 1, fp) == 1); - - // Flush the file to update the pointers. - assert(!fflush(fp)); - - assert(size == WRITE_NO); - for (size_t i = 0; i < size; i++) - assert(buf[i] == c); - - // Check if the stream maintains a null-bye at the end. - assert(buf[size] == '\0'); - - // Stream should be expanded, size should be == 2*WRITE_NO. - assert(!fseek(fp, WRITE_NO, SEEK_END)); - assert(!fflush(fp)); - assert(size == 2*WRITE_NO); - assert(buf[size] == '\0'); - - // Check if it's filled with zero's. - for (size_t i = WRITE_NO; i < size; i++) - assert(buf[i] == '\0'); - - // Go back and overwrite the 0's with 'B'. - assert(!fseek(fp, -WRITE_NO, SEEK_CUR)); - c = 'B'; - for (size_t i = 0; i < WRITE_NO; i++) - assert(fwrite(&c, sizeof(char), 1, fp) == 1); - - // Check if that happened. - assert(size == 2*WRITE_NO); - for (size_t i = WRITE_NO; i < size; i++) - assert(buf[i] == c); - assert(buf[size] == '\0'); - - // Go to the front and write 'B'. - assert(!fseek(fp, 0, SEEK_SET)); - for (size_t i = 0; i < WRITE_NO; i++) - assert(fwrite(&c, sizeof(char), 1, fp) == 1); - - // Check if that happened. - assert(size == 2*WRITE_NO); - for (size_t i = 0; i < size; i++) - assert(buf[i] == c); - assert(buf[size] == '\0'); - - // Close the file, we have tested everything. - assert(!fclose(fp)); - free(buf); - return 0; -} |