1 /* Create a temporary file or directory. 2 3 Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc. 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program 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 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://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 /* Generate a temporary file name based on TMPL. TMPL must match the 36 rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix). 37 The name constructed does not exist at the time of the call to 38 gen_tempname. TMPL is overwritten with the result. 39 40 KIND may be one of: 41 GT_NOCREATE: simply verify that the name does not exist 42 at the time of the call. 43 GT_FILE: create a large file using open(O_CREAT|O_EXCL) 44 and return a read-write fd. The file is mode 0600. 45 GT_DIR: create a directory, which will be mode 0700. 46 47 We use a clever algorithm to get hard-to-predict names. */ 48 extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind); 49 50 #endif /* GL_TEMPNAME_H */ 51