5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
13 #include <_PDCLIB_glue.h>
17 static char tmpname_prefix[4] = {0, 0, 0, 0};
19 extern const _PDCLIB_fileops_t _PDCLIB_fileops;
20 extern void _PDCLIB_w32errno( void );
24 if(!tmpname_prefix[0]) {
25 char namebuf[MAX_PATH+1];
26 DWORD res = GetModuleFileNameA(NULL, namebuf, MAX_PATH+1);
28 char * basename = strrchr(namebuf, '\\');
31 } else basename = namebuf;
33 char* dot = strchr(basename, '.');
36 strncpy(tmpname_prefix, basename, 3);
38 // Error getting file name
39 strcpy(tmpname_prefix, "PDU");
43 char tmpdir[MAX_PATH + 1];
44 DWORD rv = GetTempPathA(MAX_PATH + 1, tmpdir);
50 char name[MAX_PATH + 1];
51 rv = GetTempFileNameA(tmpdir, tmpname_prefix, 0, name);
57 /* OPEN_EXISTING as CreateTempFileName creates the file then closes the
58 handle to it (to avoid race conditions as associated with e.g. tmpnam)
60 HANDLE fd = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
61 FILE_SHARE_DELETE, NULL, OPEN_EXISTING,
62 FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY, NULL);
64 if(fd == INVALID_HANDLE_VALUE) {
69 /* Set the file to delete on close */
72 FILE* fs = _PDCLIB_fvopen(((_PDCLIB_fd_t){fd}), &_PDCLIB_fileops, _PDCLIB_FWRITE | _PDCLIB_FRW, name);
82 #include <_PDCLIB_test.h>