tempname.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Create a temporary file or directory.
  2. Copyright (C) 2006, 2009-2013 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 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 General Public License for more details.
  11. You should have received a copy of the GNU 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. /* Generate a temporary file name based on TMPL. TMPL must match the
  27. rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
  28. The name constructed does not exist at the time of the call to
  29. gen_tempname. TMPL is overwritten with the result.
  30. KIND may be one of:
  31. GT_NOCREATE: simply verify that the name does not exist
  32. at the time of the call.
  33. GT_FILE: create a large file using open(O_CREAT|O_EXCL)
  34. and return a read-write fd. The file is mode 0600.
  35. GT_DIR: create a directory, which will be mode 0700.
  36. We use a clever algorithm to get hard-to-predict names. */
  37. extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
  38. #endif /* GL_TEMPNAME_H */