3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
11 #include <_PDCLIB_glue.h>
15 static char tmpname_prefix[4] = {0, 0, 0, 0};
17 extern const _PDCLIB_fileops_t _PDCLIB_fileops;
18 extern void _PDCLIB_w32errno( void );
22 if(!tmpname_prefix[0]) {
23 char namebuf[MAX_PATH+1];
24 DWORD res = GetModuleFileNameA(NULL, namebuf, MAX_PATH+1);
26 char * basename = strrchr(namebuf, '\\');
29 } else basename = namebuf;
31 char* dot = strchr(basename, '.');
34 strncpy(tmpname_prefix, basename, 3);
36 // Error getting file name
37 strcpy(tmpname_prefix, "PDU");
41 char tmpdir[MAX_PATH + 1];
42 DWORD rv = GetTempPathA(MAX_PATH + 1, tmpdir);
48 char name[MAX_PATH + 1];
49 rv = GetTempFileNameA(tmpdir, tmpname_prefix, 0, name);
55 /* OPEN_EXISTING as CreateTempFileName creates the file then closes the
56 handle to it (to avoid race conditions as associated with e.g. tmpnam)
58 HANDLE fd = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
59 FILE_SHARE_DELETE, NULL, OPEN_EXISTING,
60 FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY, NULL);
62 if(fd == INVALID_HANDLE_VALUE) {
67 /* Set the file to delete on close */
70 FILE* fs = _PDCLIB_fvopen(((_PDCLIB_fd_t){fd}), &_PDCLIB_fileops, _PDCLIB_FWRITE | _PDCLIB_FRW, name);
80 #include <_PDCLIB_test.h>