From 7988979a722b4cdf287b2093956a76a3f19b9897 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Mon, 24 Oct 2016 20:22:12 +0200 Subject: add uClibc-ng test directory --- test/stdlib/test-mkostemp-O_CLOEXEC.c | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/stdlib/test-mkostemp-O_CLOEXEC.c (limited to 'test/stdlib/test-mkostemp-O_CLOEXEC.c') diff --git a/test/stdlib/test-mkostemp-O_CLOEXEC.c b/test/stdlib/test-mkostemp-O_CLOEXEC.c new file mode 100644 index 0000000..9ff229a --- /dev/null +++ b/test/stdlib/test-mkostemp-O_CLOEXEC.c @@ -0,0 +1,45 @@ +#define _XOPEN_SOURCE_EXTENDED +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined __ARCH_USE_MMU__ +# define fork vfork +#endif + +int main(int argc, char *argv[]) { + int fd, status; + char buff[5]; + char template[] = "/tmp/test-mkostemp.XXXXXX"; + + fd = mkostemp(template, O_CLOEXEC); + unlink(template); + + snprintf(buff, 5, "%d", fd); + + if(!fork()) + if(execl("./test-mkostemp-child", "test-mkostemp-child", buff, NULL) == -1) + exit(EXIT_FAILURE); + + wait(&status); + + memset(buff, 0, 5); + lseek(fd, 0, SEEK_SET); + errno = 0; + if(read(fd, buff, 5) == -1) + exit(EXIT_FAILURE); + + if(!strncmp(buff, "test", 5)) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); + + close(fd); + exit(EXIT_SUCCESS); +} -- cgit v1.2.3