tmpfileplus.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* $Id: tmpfileplus.h $ */
  2. /*
  3. * $Date: 2016-06-01 03:31Z $
  4. * $Revision: 2.0.0 $
  5. * $Author: dai $
  6. */
  7. /*
  8. * This Source Code Form is subject to the terms of the Mozilla Public
  9. * License, v. 2.0. If a copy of the MPL was not distributed with this
  10. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  11. *
  12. * Copyright (c) 2012-16 David Ireland, DI Management Services Pty Ltd
  13. * <http://www.di-mgt.com.au/contact/>.
  14. */
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18. #ifndef TMPFILEPLUS_H_
  19. #define TMPFILEPLUS_H_
  20. #include <stdio.h>
  21. /** Create a unique temporary file.
  22. @param dir (optional) directory to create file. If NULL use default TMP directory.
  23. @param prefix (optional) prefix for file name. If NULL use "tmp.".
  24. @param pathname (optional) pointer to a buffer to receive the temp filename.
  25. Allocated using `malloc()`; user to free. Ignored if NULL.
  26. @param keep If `keep` is nonzero and `pathname` is not NULL, then keep the file after closing.
  27. Otherwise file is automatically deleted when closed.
  28. @return Pointer to stream opened in binary read/write (w+b) mode, or a null pointer on error.
  29. @exception ENOMEM Not enough memory to allocate filename.
  30. */
  31. FILE *tmpfileplus(const char *dir, const char *prefix, char **pathname, int keep);
  32. /** Create a unique temporary file with filename stored in a fixed-length buffer.
  33. @param dir (optional) directory to create file. If NULL use default directory.
  34. @param prefix (optional) prefix for file name. If NULL use "tmp.".
  35. @param pathnamebuf (optional) buffer to receive full pathname of temporary file. Ignored if NULL.
  36. @param pathsize Size of buffer to receive filename and its terminating null character.
  37. @param keep If `keep` is nonzero and `pathname` is not NULL, then keep the file after closing.
  38. Otherwise file is automatically deleted when closed.
  39. @return Pointer to stream opened in binary read/write (w+b) mode, or a null pointer on error.
  40. @exception E2BIG Resulting filename is too big for the buffer `pathnamebuf`.
  41. */
  42. FILE *tmpfileplus_f(const char *dir, const char *prefix, char *pathnamebuf, size_t pathsize, int keep);
  43. #define TMPFILE_KEEP 1
  44. #endif /* end TMPFILEPLUS_H_ */