ReactOS 0.4.16-dev-852-gcfcc8d8
getpath.cpp File Reference
#include <corecrt_internal.h>
#include <stddef.h>
Include dependency graph for getpath.cpp:

Go to the source code of this file.

Functions

template<typename Character >
 _Success_ (return !=0) static Character *__cdecl common_getpath(_In_z_ Character const *const delimited_paths
 
 _Out_writes_z_ (result_count) Character *const result
 
size_t const result_count throw ()
 
char *__cdecl __acrt_getpath (char const *const delimited_paths, char *const result, size_t const result_count)
 
wchar_t *__cdecl __acrt_wgetpath (wchar_t const *const delimited_paths, wchar_t *const result, size_t const result_count)
 

Function Documentation

◆ __acrt_getpath()

char *__cdecl __acrt_getpath ( char const *const  delimited_paths,
char *const  result,
size_t const  result_count 
)

Definition at line 143 of file getpath.cpp.

148{
149 return common_getpath(delimited_paths, result, result_count);
150}
GLuint64EXT * result
Definition: glext.h:11304

◆ __acrt_wgetpath()

wchar_t *__cdecl __acrt_wgetpath ( wchar_t const *const  delimited_paths,
wchar_t *const  result,
size_t const  result_count 
)

Definition at line 152 of file getpath.cpp.

157{
158 return common_getpath(delimited_paths, result, result_count);
159}

◆ _Out_writes_z_()

_Out_writes_z_ ( result_count  ) const

◆ _Success_()

template<typename Character >
_Success_ ( return = 0) const

◆ throw()

size_t const result_count throw ( )

Definition at line 68 of file getpath.cpp.

69{
70 _VALIDATE_RETURN_NOEXC(result != nullptr, EINVAL, nullptr);
71
72 if (result_count > 0)
73 {
74 result[0] = '\0';
75 }
76
77 _VALIDATE_RETURN_NOEXC(result_count > 1, EINVAL, nullptr);
78
79 Character const* source_it = delimited_paths;
80
81 // Skip past any leading semicolons:
82 while (*source_it == ';')
83 {
84 ++source_it;
85 }
86
87 Character const* const source_first = source_it;
88
89 Character* result_it = result;
90 Character* const result_last = result + result_count - 1; // Leave room for \0
91
92#pragma warning(suppress:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 Prefast is confused.
93 while (*source_it != '\0' && *source_it != ';')
94 {
95 if (*source_it == '"')
96 {
97 // We found a quote; copy all characters until we reach the matching
98 // end quote or the end of the string:
99 ++source_it; // Advance past opening quote
100
101 while (*source_it != '\0' && *source_it != '"')
102 {
103#pragma warning(suppress:__WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY) // 26015 Prefast is confused.
104 *result_it++ = *source_it++;
105 if (result_it == result_last)
106 {
107 *result_it = '\0';
108 errno = ERANGE;
109 return nullptr;
110 }
111 }
112
113 if (*source_it != '\0')
114 {
115 ++source_it; // Advance past closing quote
116 }
117 }
118 else
119 {
120 *result_it++ = *source_it++;
121 if (result_it == result_last)
122 {
123 *result_it = '\0';
124 errno = ERANGE;
125 return nullptr;
126 }
127 }
128 }
129
130 // If we copied something and stopped because we reached a semicolon, skip
131 // any semicolons before returning:
132 while (*source_it == ';')
133 {
134 ++source_it;
135 }
136
137 *result_it = '\0';
138 return source_it == source_first
139 ? nullptr
140 : const_cast<Character*>(source_it);
141}
#define EINVAL
Definition: acclib.h:90
#define ERANGE
Definition: acclib.h:92
return nullptr
Definition: expand.cpp:78
#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr)
#define errno
Definition: errno.h:18