| 1 | /* Create a temporary file or directory. | 
|---|
| 2 |  | 
|---|
| 3 | Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc. | 
|---|
| 4 |  | 
|---|
| 5 | This file is free software: you can redistribute it and/or modify | 
|---|
| 6 | it under the terms of the GNU Lesser General Public License as | 
|---|
| 7 | published by the Free Software Foundation; either version 2.1 of the | 
|---|
| 8 | License, or (at your option) any later version. | 
|---|
| 9 |  | 
|---|
| 10 | This file is distributed in the hope that it will be useful, | 
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 13 | GNU Lesser General Public License for more details. | 
|---|
| 14 |  | 
|---|
| 15 | You should have received a copy of the GNU Lesser General Public License | 
|---|
| 16 | along with this program.  If not, see <https://www.gnu.org/licenses/>.  */ | 
|---|
| 17 |  | 
|---|
| 18 | /* header written by Eric Blake */ | 
|---|
| 19 |  | 
|---|
| 20 | #ifndef GL_TEMPNAME_H | 
|---|
| 21 | # define GL_TEMPNAME_H | 
|---|
| 22 |  | 
|---|
| 23 | # include <stdio.h> | 
|---|
| 24 |  | 
|---|
| 25 | # ifdef __GT_FILE | 
|---|
| 26 | #  define GT_FILE     __GT_FILE | 
|---|
| 27 | #  define GT_DIR      __GT_DIR | 
|---|
| 28 | #  define GT_NOCREATE __GT_NOCREATE | 
|---|
| 29 | # else | 
|---|
| 30 | #  define GT_FILE     0 | 
|---|
| 31 | #  define GT_DIR      1 | 
|---|
| 32 | #  define GT_NOCREATE 2 | 
|---|
| 33 | # endif | 
|---|
| 34 |  | 
|---|
| 35 | #ifdef __cplusplus | 
|---|
| 36 | extern "C" { | 
|---|
| 37 | #endif | 
|---|
| 38 |  | 
|---|
| 39 | /* Generate a temporary file name based on TMPL.  TMPL must match the | 
|---|
| 40 | rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix). | 
|---|
| 41 | The name constructed does not exist at the time of the call to | 
|---|
| 42 | gen_tempname.  TMPL is overwritten with the result. | 
|---|
| 43 |  | 
|---|
| 44 | KIND may be one of: | 
|---|
| 45 | GT_NOCREATE:         simply verify that the name does not exist | 
|---|
| 46 | at the time of the call. | 
|---|
| 47 | GT_FILE:             create a large file using open(O_CREAT|O_EXCL) | 
|---|
| 48 | and return a read-write fd.  The file is mode 0600. | 
|---|
| 49 | GT_DIR:              create a directory, which will be mode 0700. | 
|---|
| 50 |  | 
|---|
| 51 | */ | 
|---|
| 52 | extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind); | 
|---|
| 53 | /* Similar, except X_SUFFIX_LEN gives the number of Xs.  */ | 
|---|
| 54 | extern int gen_tempname_len (char *tmpl, int suffixlen, int flags, int kind, | 
|---|
| 55 | size_t x_suffix_len); | 
|---|
| 56 |  | 
|---|
| 57 | /* Similar to gen_tempname, but TRYFUNC is called for each temporary | 
|---|
| 58 | name to try.  If TRYFUNC returns a non-negative number, TRY_GEN_TEMPNAME | 
|---|
| 59 | returns with this value.  Otherwise, if errno is set to EEXIST, another | 
|---|
| 60 | name is tried, or else TRY_GEN_TEMPNAME returns -1. */ | 
|---|
| 61 | extern int try_tempname (char *tmpl, int suffixlen, void *args, | 
|---|
| 62 | int (*tryfunc) (char *, void *)); | 
|---|
| 63 | /* Similar, except X_SUFFIX_LEN gives the number of Xs.  */ | 
|---|
| 64 | extern int try_tempname_len (char *tmpl, int suffixlen, void *args, | 
|---|
| 65 | int (*tryfunc) (char *, void *), | 
|---|
| 66 | size_t x_suffix_len); | 
|---|
| 67 |  | 
|---|
| 68 | #ifdef __cplusplus | 
|---|
| 69 | } | 
|---|
| 70 | #endif | 
|---|
| 71 |  | 
|---|
| 72 | #endif /* GL_TEMPNAME_H */ | 
|---|