slight code simplification, seeing that clear_meta(NULL) is fine
[got-portable.git] / include / got_opentemp.h
blobf593c2654e3b83e7aaf1b5fa2a6a2f3311675648
1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* Utilities for opening temporary files. */
19 #ifndef GOT_TMPDIR
20 #define GOT_TMPDIR /tmp
21 #endif
22 #define GOT_STRINGIFY_TMP(x) #x
23 #define GOT_STRINGVAL_TMP(x) GOT_STRINGIFY_TMP(x)
24 #define GOT_TMPDIR_STR GOT_STRINGVAL_TMP(GOT_TMPDIR)
26 /* Open a file descriptor to a new temporary file for writing.
27 * The file is not visible in the filesystem. */
28 int got_opentempfd(void);
30 /* Open a new temporary file for writing.
31 * The file is not visible in the filesystem. */
32 FILE *got_opentemp(void);
34 /* Open a new temporary file for writing.
35 * The file is visible in the filesystem. */
36 const struct got_error *got_opentemp_named(char **, FILE **, const char *,
37 const char *);
39 /* Like got_opentemp_named() but returns a file descriptor instead of a FILE. */
40 const struct got_error *got_opentemp_named_fd(char **, int *, const char *,
41 const char *);
43 /* Truncate a file. This is useful for re-using open temporary files. */
44 const struct got_error *got_opentemp_truncate(FILE *);
46 /* Truncate a file via a file descriptor. */
47 const struct got_error *got_opentemp_truncatefd(int);