mkstemp.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2013 Free Software
  2. Foundation, Inc.
  3. This file is derived from the one in the GNU C Library.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #if !_LIBC
  15. # include <config.h>
  16. #endif
  17. #include <stdlib.h>
  18. #if !_LIBC
  19. # include "tempname.h"
  20. # define __gen_tempname gen_tempname
  21. # ifndef __GT_FILE
  22. # define __GT_FILE GT_FILE
  23. # endif
  24. #endif
  25. #include <stdio.h>
  26. #ifndef __GT_FILE
  27. # define __GT_FILE 0
  28. #endif
  29. /* Generate a unique temporary file name from XTEMPLATE.
  30. The last six characters of XTEMPLATE must be "XXXXXX";
  31. they are replaced with a string that makes the file name unique.
  32. Then open the file and return a fd.
  33. If you are creating temporary files which will later be removed,
  34. consider using the clean-temp module, which avoids several pitfalls
  35. of using mkstemp directly. */
  36. int
  37. mkstemp (char *xtemplate)
  38. {
  39. return __gen_tempname (xtemplate, 0, 0, __GT_FILE);
  40. }