Blame


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