Blame lib/tempname.h

Packit 33f14e
/* Create a temporary file or directory.
Packit 33f14e
Packit 33f14e
   Copyright (C) 2006, 2009-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
/* header written by Eric Blake */
Packit 33f14e
Packit 33f14e
#ifndef GL_TEMPNAME_H
Packit 33f14e
# define GL_TEMPNAME_H
Packit 33f14e
Packit 33f14e
# include <stdio.h>
Packit 33f14e
Packit 33f14e
# ifdef __GT_FILE
Packit 33f14e
#  define GT_FILE     __GT_FILE
Packit 33f14e
#  define GT_DIR      __GT_DIR
Packit 33f14e
#  define GT_NOCREATE __GT_NOCREATE
Packit 33f14e
# else
Packit 33f14e
#  define GT_FILE     0
Packit 33f14e
#  define GT_DIR      1
Packit 33f14e
#  define GT_NOCREATE 2
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
#ifdef __cplusplus
Packit 33f14e
extern "C" {
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
/* Generate a temporary file name based on TMPL.  TMPL must match the
Packit 33f14e
   rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
Packit 33f14e
   The name constructed does not exist at the time of the call to
Packit 33f14e
   gen_tempname.  TMPL is overwritten with the result.
Packit 33f14e
Packit 33f14e
   KIND may be one of:
Packit 33f14e
   GT_NOCREATE:         simply verify that the name does not exist
Packit 33f14e
                        at the time of the call.
Packit 33f14e
   GT_FILE:             create a large file using open(O_CREAT|O_EXCL)
Packit 33f14e
                        and return a read-write fd.  The file is mode 0600.
Packit 33f14e
   GT_DIR:              create a directory, which will be mode 0700.
Packit 33f14e
Packit 33f14e
   We use a clever algorithm to get hard-to-predict names. */
Packit 33f14e
extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
Packit 33f14e
Packit 33f14e
/* Similar to gen_tempname, but TRYFUNC is called for each temporary
Packit 33f14e
   name to try.  If TRYFUNC returns a non-negative number, TRY_GEN_TEMPNAME
Packit 33f14e
   returns with this value.  Otherwise, if errno is set to EEXIST, another
Packit 33f14e
   name is tried, or else TRY_GEN_TEMPNAME returns -1. */
Packit 33f14e
extern int try_tempname (char *tmpl, int suffixlen, void *args,
Packit 33f14e
                         int (*tryfunc) (char *, void *));
Packit 33f14e
Packit 33f14e
#ifdef __cplusplus
Packit 33f14e
}
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
#endif /* GL_TEMPNAME_H */