From bd5969fc876a10b18613302db7087ef3c40f18e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:00 -0500 Subject: lib: Add mlibc Signed-off-by: Ian Moffett --- lib/mlibc/tests/posix/dprintf.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/mlibc/tests/posix/dprintf.c (limited to 'lib/mlibc/tests/posix/dprintf.c') diff --git a/lib/mlibc/tests/posix/dprintf.c b/lib/mlibc/tests/posix/dprintf.c new file mode 100644 index 0000000..4746edb --- /dev/null +++ b/lib/mlibc/tests/posix/dprintf.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +#ifdef USE_HOST_LIBC +#define TEST_FILE "dprintf-host-libc.tmp" +#else +#define TEST_FILE "dprintf.tmp" +#endif + +int main() { + int fd = open(TEST_FILE, O_RDWR | O_CREAT, 0666); + assert(fd > -1); + + int ret = dprintf(fd, "aaa"); + assert(ret == 3); + + // Check if we can read back the same things. + // Also checks to see if the fd is still open, + // which is issue #199. + + off_t seek = lseek(fd, 0, SEEK_SET); + assert(seek == 0); + + char buf[3]; + ssize_t num_read = read(fd, buf, 3); + + assert(num_read == 3); + assert(buf[0] == 'a' + && buf[1] == 'a' + && buf[2] == 'a'); + + // All the tests pass, now we can unlink the file. + ret = unlink(TEST_FILE); + assert(ret == 0); + return 0; +} -- cgit v1.2.3