ReactOS 0.4.16-dev-927-g467dec4
makepath.cpp File Reference
#include <corecrt_internal_securecrt.h>
#include <mbstring.h>
#include <stdlib.h>
Include dependency graph for makepath.cpp:

Go to the source code of this file.

Functions

static char constprevious_character (char const *const first, char const *const current) throw ()
 
static wchar_t constprevious_character (wchar_t const *, wchar_t const *const current) throw ()
 
template<typename Character >
static errno_t __cdecl cleanup_after_error (_Out_writes_z_(count) Character *const buffer, size_t const count) throw ()
 
template<typename Character >
static errno_t __cdecl common_makepath_s (_Out_writes_z_(result_count) Character *const result_buffer, _In_ size_t const result_count, _In_opt_z_ Character const *const drive, _In_opt_z_ Character const *const directory, _In_opt_z_ Character const *const file_name, _In_opt_z_ Character const *const extension) throw ()
 
void __cdecl _makepath (char *const result_buffer, char const *const drive, char const *const directory, char const *const file_name, char const *const extension)
 
void __cdecl _wmakepath (wchar_t *const result_buffer, wchar_t const *const drive, wchar_t const *const directory, wchar_t const *const file_name, wchar_t const *const extension)
 
errno_t __cdecl _makepath_s (char *const result_buffer, size_t const result_count, char const *const drive, char const *const directory, char const *const file_name, char const *const extension)
 
errno_t __cdecl _wmakepath_s (wchar_t *const result_buffer, size_t const result_count, wchar_t const *const drive, wchar_t const *const directory, wchar_t const *const file_name, wchar_t const *const extension)
 

Function Documentation

◆ _makepath()

void __cdecl _makepath ( char *const  result_buffer,
char const *const  drive,
char const *const  directory,
char const *const  file_name,
char const *const  extension 
)

Definition at line 159 of file makepath.cpp.

166{
168}
#define _CRT_UNBOUNDED_BUFFER_SIZE
result_buffer_count char *const result_buffer
Definition: cvt.cpp:111
errno_t __cdecl _makepath_s(char *const result_buffer, size_t const result_count, char const *const drive, char const *const directory, char const *const file_name, char const *const extension)
Definition: makepath.cpp:183
static LPCWSTR file_name
Definition: protocol.c:147

◆ _makepath_s()

errno_t __cdecl _makepath_s ( char *const  result_buffer,
size_t const  result_count,
char const *const  drive,
char const *const  directory,
char const *const  file_name,
char const *const  extension 
)

Definition at line 183 of file makepath.cpp.

191{
192 return common_makepath_s(result_buffer, result_count, drive, directory, file_name, extension);
193}
static errno_t __cdecl common_makepath_s(_Out_writes_z_(result_count) Character *const result_buffer, _In_ size_t const result_count, _In_opt_z_ Character const *const drive, _In_opt_z_ Character const *const directory, _In_opt_z_ Character const *const file_name, _In_opt_z_ Character const *const extension)
Definition: makepath.cpp:53

Referenced by _makepath().

◆ _wmakepath()

void __cdecl _wmakepath ( wchar_t *const  result_buffer,
wchar_t const *const  drive,
wchar_t const *const  directory,
wchar_t const *const  file_name,
wchar_t const *const  extension 
)

Definition at line 170 of file makepath.cpp.

177{
179}
errno_t __cdecl _wmakepath_s(wchar_t *const result_buffer, size_t const result_count, wchar_t const *const drive, wchar_t const *const directory, wchar_t const *const file_name, wchar_t const *const extension)
Definition: makepath.cpp:195

◆ _wmakepath_s()

errno_t __cdecl _wmakepath_s ( wchar_t *const  result_buffer,
size_t const  result_count,
wchar_t const *const  drive,
wchar_t const *const  directory,
wchar_t const *const  file_name,
wchar_t const *const  extension 
)

Definition at line 195 of file makepath.cpp.

203{
204 return common_makepath_s(result_buffer, result_count, drive, directory, file_name, extension);
205}

Referenced by _wmakepath().

◆ cleanup_after_error()

template<typename Character >
static errno_t __cdecl cleanup_after_error ( _Out_writes_z_(count) Character *const  buffer,
size_t const  count 
)
throw (
)
static

Definition at line 29 of file makepath.cpp.

32{
33 // This is referenced only in the Debug CRT build
35
38 return EINVAL; // This is unreachable
39}
#define EINVAL
Definition: acclib.h:90
#define _RETURN_BUFFER_TOO_SMALL(_String, _Size)
#define _RESET_STRING(_String, _Size)
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325

Referenced by common_makepath_s().

◆ common_makepath_s()

template<typename Character >
static errno_t __cdecl common_makepath_s ( _Out_writes_z_(result_count) Character *const  result_buffer,
_In_ size_t const  result_count,
_In_opt_z_ Character const *const  drive,
_In_opt_z_ Character const *const  directory,
_In_opt_z_ Character const *const  file_name,
_In_opt_z_ Character const *const  extension 
)
throw (
)
static

Definition at line 53 of file makepath.cpp.

61{
62 _VALIDATE_STRING(result_buffer, result_count);
63
64 Character* result_it = result_buffer;
65
66 // For the non-secure makepath functions, result_count is _CRT_UNBOUNDED_BUFFER_SIZE.
67 // In this case, we do not want to perform arithmetic with the result_count. Instead,
68 // we set the result_end to nullptr: result_it will never be a null pointer,
69 // and when we need to perform arithmetic with result_end we can check it for
70 // null first.
71 Character* const result_end = result_count != _CRT_UNBOUNDED_BUFFER_SIZE
72 ? result_buffer + result_count
73 : nullptr;
74
75 CRT_WARNING_DISABLE_PUSH(26015, "Silence prefast about overflow - covered by result_end for secure callers")
76
77 // Copy the drive:
78 if (drive && drive[0] != '\0')
79 {
80 if (result_end != nullptr && result_end - result_it < 2)
81 return cleanup_after_error(result_buffer, result_count);
82
83 *result_it++ = *drive;
84 *result_it++ = ':';
85 }
86
87 // Copy the directory:
88 if (directory && directory[0] != '\0')
89 {
90 Character const* source_it = directory;
91 while (*source_it != '\0')
92 {
93 if ((result_end != nullptr) && (result_it >= result_end))
94 return cleanup_after_error(result_buffer, result_count);
95
96 *result_it++ = *source_it++;
97 }
98
99 // Write a trailing backslash if there isn't one:
100 source_it = previous_character(directory, source_it);
101 if (*source_it != '/' && *source_it != '\\')
102 {
103 if ((result_end != nullptr) && (result_it >= result_end))
104 return cleanup_after_error(result_buffer, result_count);
105
106 *result_it++ = '\\';
107 }
108 }
109
110 // Copy the file name:
111 if (file_name)
112 {
113 Character const* source_it = file_name;
114 while (*source_it != '\0')
115 {
116 if ((result_end != nullptr) && (result_it >= result_end))
117 return cleanup_after_error(result_buffer, result_count);
118
119 *result_it++ = *source_it++;
120 }
121 }
122
123 // Copy the extension:
124 if (extension)
125 {
126 // Add a '.' if one is required:
127 if (extension[0] != '\0' && extension[0] != '.')
128 {
129 if ((result_end != nullptr) && (result_it >= result_end))
130 return cleanup_after_error(result_buffer, result_count);
131
132 *result_it++ = '.';
133 }
134
135 Character const* source_it = extension;
136 while (*source_it != '\0')
137 {
138 if ((result_end != nullptr) && (result_it >= result_end))
139 return cleanup_after_error(result_buffer, result_count);
140
141 *result_it++ = *source_it++;
142 }
143 }
144
145 // Copy the null terminator:
146 if ((result_end != nullptr) && (result_it >= result_end))
147 return cleanup_after_error(result_buffer, result_count);
148
149 *result_it++ = '\0';
150
152
153 _FILL_STRING(result_buffer, result_count, result_it - result_buffer);
154 return 0;
155}
#define _FILL_STRING
#define _VALIDATE_STRING(_String, _Size)
#define CRT_WARNING_DISABLE_PUSH(wn, message)
#define CRT_WARNING_POP
if(dx< 0)
Definition: linetemp.h:194
static char const * previous_character(char const *const first, char const *const current)
Definition: makepath.cpp:14
static errno_t __cdecl cleanup_after_error(_Out_writes_z_(count) Character *const buffer, size_t const count)
Definition: makepath.cpp:29

Referenced by _makepath_s(), and _wmakepath_s().

◆ previous_character() [1/2]

static char const * previous_character ( char const *const  first,
char const *const  current 
)
throw (
)
static

Definition at line 14 of file makepath.cpp.

15{
16 return reinterpret_cast<char const*>(_mbsdec(
17 reinterpret_cast<unsigned char const*>(first),
18 reinterpret_cast<unsigned char const*>(current)));
19}
const GLint * first
Definition: glext.h:5794
_Check_return_ _CRTIMP unsigned char *__cdecl _mbsdec(_In_reads_z_(_Pos-_Start+1) const unsigned char *_Start, _In_z_ const unsigned char *_Pos)
struct task_struct * current
Definition: linux.c:32
#define const
Definition: zconf.h:233

Referenced by common_makepath_s().

◆ previous_character() [2/2]

static wchar_t const * previous_character ( wchar_t const ,
wchar_t const *const  current 
)
throw (
)
static

Definition at line 21 of file makepath.cpp.

22{
23 return current - 1;
24}