diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-05-03 15:55:07 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2022-05-03 15:55:07 +0000 |
commit | 3b7c0bc774e8eaf08457369cb3e23b70f042ec17 (patch) | |
tree | 880b56d561d58f897dd5c321a0f1e952babf3cb8 /tmpfd.c | |
download | hydrasect-3b7c0bc774e8eaf08457369cb3e23b70f042ec17.tar hydrasect-3b7c0bc774e8eaf08457369cb3e23b70f042ec17.tar.gz hydrasect-3b7c0bc774e8eaf08457369cb3e23b70f042ec17.tar.bz2 hydrasect-3b7c0bc774e8eaf08457369cb3e23b70f042ec17.tar.lz hydrasect-3b7c0bc774e8eaf08457369cb3e23b70f042ec17.tar.xz hydrasect-3b7c0bc774e8eaf08457369cb3e23b70f042ec17.tar.zst hydrasect-3b7c0bc774e8eaf08457369cb3e23b70f042ec17.zip |
Initial commit
Diffstat (limited to 'tmpfd.c')
-rw-r--r-- | tmpfd.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tmpfd.c b/tmpfd.c new file mode 100644 index 0000000..193fa90 --- /dev/null +++ b/tmpfd.c @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is> +// SPDX-License-Identifier: EUPL-1.2 + +#include <stdio.h> +#include <unistd.h> + +int tmpfd(void) +{ + int fd = -1; + FILE *f = tmpfile(); + if (!f) + return -1; + if ((fd = fileno(f)) != -1) + fd = dup(fd); + fclose(f); + return fd; +} |