ReactOS 0.4.16-dev-853-g88d9285
tmpfile.cpp File Reference
#include <corecrt_internal_stdio.h>
#include <sys/stat.h>
Include dependency graph for tmpfile.cpp:

Go to the source code of this file.

Namespaces

namespace  anonymous_namespace{tmpfile.cpp}
 

Enumerations

enum class  anonymous_namespace{tmpfile.cpp}::buffer_id { anonymous_namespace{tmpfile.cpp}::tmpnam , anonymous_namespace{tmpfile.cpp}::tmpfile , anonymous_namespace{tmpfile.cpp}::tmpnam_s , anonymous_namespace{tmpfile.cpp}::count }
 

Functions

void __cdecl __acrt_stdio_free_tmpfile_name_buffers_nolock ()
 
static char *&__cdecl get_tmpfile_buffer_pointer_nolock (buffer_id const id, char) throw ()
 
static wchar_t *&__cdecl get_tmpfile_buffer_pointer_nolock (buffer_id const id, wchar_t) throw ()
 
template<typename Character >
 _Success_ (return !=nullptr) static Character *__cdecl get_tmpfile_buffer_nolock(buffer_id const id) throw ()
 
template<typename Character >
 _Success_ (return==true) static bool __cdecl initialize_tmpfile_buffer_nolock(buffer_id const buffer_id) throw ()
 
_In_ size_t const file_name_count throw ()
 
static char **__cdecl get_tmpnam_ptd_buffer (char) throw ()
 
static wchar_t **__cdecl get_tmpnam_ptd_buffer (wchar_t) throw ()
 
 _Success_ (return==0) static errno_t __cdecl common_tmpfile_nolock(_Out_ FILE **const stream
 
errno_t __cdecl tmpnam_s (char *const result_buffer, size_t const result_buffer_count)
 
errno_t __cdecl _wtmpnam_s (wchar_t *const result_buffer, size_t const result_buffer_count)
 
char *__cdecl tmpnam (char *const result_buffer)
 
wchar_t *__cdecl _wtmpnam (wchar_t *const result_buffer)
 
FILE *__cdecl tmpfile ()
 
errno_t __cdecl tmpfile_s (FILE **const stream)
 
void __acrt_force_use_of_tmpfile ()
 

Variables

static charnarrow_tmpfile_buffer_pointers [static_cast< size_t >(buffer_id::count)]
 
static wchar_twide_tmpfile_buffer_pointers [static_cast< size_t >(buffer_id::count)]
 
size_t const result_buffer_count
 
_In_ size_t const _In_ buffer_id const buffer_id
 
unsigned __acrt_tmpfile_used
 

Function Documentation

◆ __acrt_force_use_of_tmpfile()

void __acrt_force_use_of_tmpfile ( )

Definition at line 507 of file tmpfile.cpp.

508 {
510 }
unsigned __acrt_tmpfile_used
Definition: tmpfile.cpp:505

◆ __acrt_stdio_free_tmpfile_name_buffers_nolock()

void __cdecl __acrt_stdio_free_tmpfile_name_buffers_nolock ( )

Definition at line 49 of file tmpfile.cpp.

50{
52 {
53 _free_crt(p);
54 p = nullptr;
55 }
56
57 for (wchar_t*& p : wide_tmpfile_buffer_pointers)
58 {
59 _free_crt(p);
60 p = nullptr;
61 }
62}
GLfloat GLfloat p
Definition: glext.h:8902
#define _free_crt
static wchar_t * wide_tmpfile_buffer_pointers[static_cast< size_t >(buffer_id::count)]
Definition: tmpfile.cpp:47
static char * narrow_tmpfile_buffer_pointers[static_cast< size_t >(buffer_id::count)]
Definition: tmpfile.cpp:46

Referenced by __acrt_uninitialize_tmpfile(), and __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0().

◆ _Success_() [1/3]

template<typename Character >
_Success_ ( return = nullptr) const
throw (
)

Definition at line 75 of file tmpfile.cpp.

77{
78 Character*& buffer_pointer = get_tmpfile_buffer_pointer_nolock(id, Character());
79 if (!buffer_pointer)
80 {
81 buffer_pointer = _calloc_crt_t(Character, L_tmpnam).detach();
82 }
83
84 return buffer_pointer;
85}
#define L_tmpnam
Definition: stdio.h:49
static char *&__cdecl get_tmpfile_buffer_pointer_nolock(buffer_id const id, char)
Definition: tmpfile.cpp:64

◆ _Success_() [2/3]

_Success_ ( return  = = 0) const

◆ _Success_() [3/3]

template<typename Character >
_Success_ ( return  = true) const
throw (
)

Definition at line 88 of file tmpfile.cpp.

90{
91 typedef __acrt_stdio_char_traits<Character> stdio_traits;
92
93 Character* const buffer = get_tmpfile_buffer_nolock<Character>(buffer_id);
94 size_t const buffer_count = L_tmpnam;
95
96 if (!buffer)
97 {
98 return false;
99 }
100
101 // The temporary path must be short enough so that we can append a file name
102 // of the form [buffer id][process id].[unique id], which is at most 21
103 // characters in length (plus we must leave room for the null terminator).
104 // 1 Buffer Id ("s", "t", or "u")
105 // 7 Base-36 Process Id (maximum: "1z141z3")
106 // 13 Base-36 Unique File Id (maximum: "3w5e11264sgsf")
107 DWORD const max_supported_temp_path_length = buffer_count - 22;
108
109 // Generate the path prefix; make sure it ends with a slash or backslash:
110 // CRT_REFACTOR TODO We need to use the WinRT temp path logic here.
111 DWORD const temp_path_length = stdio_traits::get_temp_path(static_cast<DWORD>(buffer_count), buffer);
112 if (temp_path_length == 0 || temp_path_length > max_supported_temp_path_length)
113 {
114 buffer[0] = '\0';
115 return false;
116 }
117
118 Character* tail = buffer + temp_path_length;
119
120 auto tail_count = [&](){ return buffer_count - (tail - buffer); };
121
122 // Append the buffer identifier part of the file name:
123 switch (buffer_id)
124 {
125 case buffer_id::tmpnam: *tail++ = sizeof(Character) == 1 ? 's' : 'v'; break;
126 case buffer_id::tmpfile: *tail++ = sizeof(Character) == 1 ? 't' : 'w'; break;
127 case buffer_id::tmpnam_s: *tail++ = sizeof(Character) == 1 ? 'u' : 'x'; break;
128 }
129
130 // Append the process identifier part of the file name:
131 _ERRCHECK(stdio_traits::ulltot_s(GetCurrentProcessId(), tail, tail_count(), 36));
132 tail += stdio_traits::tcslen(tail);
133
134 // Append the dot part of the file name and the initial unique id:
135 *tail++ = '.';
136 *tail++ = '0';
137 *tail++ = '\0';
138
139 return true;
140}
struct outqueuenode * tail
Definition: adnsresfilter.c:66
#define _ERRCHECK(e)
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
size_t const buffer_count
Definition: xtoa.cpp:36

◆ _wtmpnam()

wchar_t *__cdecl _wtmpnam ( wchar_t *const  result_buffer)

Definition at line 474 of file tmpfile.cpp.

475{
476 wchar_t* result = nullptr;
478 return result;
479}
result_buffer_count char *const result_buffer
Definition: cvt.cpp:111
GLuint64EXT * result
Definition: glext.h:11304

◆ _wtmpnam_s()

errno_t __cdecl _wtmpnam_s ( wchar_t *const  result_buffer,
size_t const  result_buffer_count 
)

Definition at line 457 of file tmpfile.cpp.

461{
462 wchar_t* result = nullptr;
465}
#define EINVAL
Definition: acclib.h:90
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
size_t const result_buffer_count
Definition: tmpfile.cpp:196

◆ get_tmpfile_buffer_pointer_nolock() [1/2]

static char *&__cdecl get_tmpfile_buffer_pointer_nolock ( buffer_id const  id,
char   
)
throw (
)
static

Definition at line 64 of file tmpfile.cpp.

65{
66 return narrow_tmpfile_buffer_pointers[static_cast<size_t>(id)];
67}
GLuint id
Definition: glext.h:5910

Referenced by _Success_().

◆ get_tmpfile_buffer_pointer_nolock() [2/2]

static wchar_t *&__cdecl get_tmpfile_buffer_pointer_nolock ( buffer_id const  id,
wchar_t   
)
throw (
)
static

Definition at line 69 of file tmpfile.cpp.

70{
71 return wide_tmpfile_buffer_pointers[static_cast<size_t>(id)];
72}

◆ get_tmpnam_ptd_buffer() [1/2]

static char **__cdecl get_tmpnam_ptd_buffer ( char  )
throw (
)
static

Definition at line 172 of file tmpfile.cpp.

173{
175 if (ptd == nullptr)
176 return nullptr;
177
178 return &ptd->_tmpnam_narrow_buffer;
179}
__acrt_ptd *__cdecl __acrt_getptd_noexit(void)
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355

◆ get_tmpnam_ptd_buffer() [2/2]

static wchar_t **__cdecl get_tmpnam_ptd_buffer ( wchar_t  )
throw (
)
static

Definition at line 181 of file tmpfile.cpp.

182{
184 if (ptd == nullptr)
185 return nullptr;
186
187 return &ptd->_tmpnam_wide_buffer;
188}

◆ throw()

_In_ size_t const file_name_count throw ( )

Definition at line 149 of file tmpfile.cpp.

150{
151 typedef __acrt_stdio_char_traits<Character> stdio_traits;
152
153 Character* const dot = reinterpret_cast<Character*>(stdio_traits::tcsrchr(file_name, '.'));
154 _VALIDATE_RETURN_NOERRNO(dot != nullptr, false);
155 _VALIDATE_RETURN_NOERRNO(dot >= file_name, false);
156 _VALIDATE_RETURN_NOERRNO(file_name_count > static_cast<size_t>(dot - file_name), false);
157
158 Character* const unique_id = dot + 1;
159 size_t const unique_id_count = file_name_count - (unique_id - file_name);
160
161 uint64_t const next_identifier = stdio_traits::tcstoull(unique_id, nullptr, 36) + 1;
162 if (next_identifier == 0)
163 return false;
164
165#pragma warning(disable:__WARNING_POSTCONDITION_NULLTERMINATION_VIOLATION) // 26036 Prefast doesn't understand perfect forwarding.
166 _ERRCHECK(stdio_traits::ulltot_s(next_identifier, unique_id, unique_id_count, 36));
167 return true;
168}
UINT64 uint64_t
Definition: types.h:77
#define _VALIDATE_RETURN_NOERRNO(expr, retexpr)
static LPCWSTR file_name
Definition: protocol.c:147

◆ tmpfile()

◆ tmpfile_s()

errno_t __cdecl tmpfile_s ( FILE **const  stream)

Definition at line 495 of file tmpfile.cpp.

496{
497 return common_tmpfile(stream, _SH_DENYRW);
498}
#define _SH_DENYRW
Definition: share.h:14

◆ tmpnam()

char *__cdecl tmpnam ( char *const  result_buffer)

Definition at line 467 of file tmpfile.cpp.

468{
469 char* result = nullptr;
471 return result;
472}

◆ tmpnam_s()

errno_t __cdecl tmpnam_s ( char *const  result_buffer,
size_t const  result_buffer_count 
)

Definition at line 447 of file tmpfile.cpp.

451{
452 char* result = nullptr;
455}

Variable Documentation

◆ __acrt_tmpfile_used

unsigned __acrt_tmpfile_used

Definition at line 505 of file tmpfile.cpp.

Referenced by __acrt_force_use_of_tmpfile().

◆ buffer_id

_In_ size_t const _In_ buffer_id const buffer_id

Definition at line 283 of file tmpfile.cpp.

◆ narrow_tmpfile_buffer_pointers

char* narrow_tmpfile_buffer_pointers[static_cast< size_t >(buffer_id::count)]
static

◆ result_buffer_count

_In_ size_t const result_buffer_count

Definition at line 196 of file tmpfile.cpp.

Referenced by __acrt_fp_format(), _In_range_(), _wtmpnam_s(), if(), throw(), and tmpnam_s().

◆ wide_tmpfile_buffer_pointers

wchar_t* wide_tmpfile_buffer_pointers[static_cast< size_t >(buffer_id::count)]
static