tempname.h 2.3 KB

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