MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / splitpath

Function splitpath

jni/stasm/misc.cpp:88–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86// This has not been tested for every possible combination but seems to work.
87
88void splitpath(
89 const char* path, // in
90 char* drive, // out: can be NULL
91 char* dir, // out: can be NULL
92 char* base, // out: can be NULL
93 char* ext) // out: can be NULL, includes dot
94{
95 CV_Assert(path && STRNLEN(path, _MAX_PATH) < _MAX_PATH);
96
97 if (drive)
98 {
99 *drive = 0;
100 if (*path && *(path+1) == ':') // has drive prefix?
101 {
102 *drive++ = *path++; // copy to drive
103 *drive++ = *path++;
104 *drive = 0;
105 }
106 }
107 const char* end;
108 for (end = path; *end; end++) // end of path
109 ;
110
111 const char* start;
112 for (start = end; start != path; ) // start of extension
113 {
114 start--;
115 if (*start == '/' || *start == '\\')
116 break;
117 if (*start == '.')
118 {
119 end = start;
120 break;
121 }
122 }
123 for (start = end; start != path; ) // start of directory
124 {
125 start--;
126 if (*start == '/' || *start == '\\')
127 {
128 start++;
129 break;
130 }
131 }
132 const char* p;
133 if (dir) // copy directory to dir
134 {
135 for (p = path; p != start; )
136 *dir++ = *p++;
137 // remove trailing / if any, but keep if just a single / or double //
138 if (p > path+1 && *(dir-2) != *(dir-1) &&
139 (*(dir-1) == '/' || *(dir-1) == '\\'))
140 {
141 dir--;
142 }
143 *dir = 0;
144 }
145 if (base) // copy basename to base

Callers 2

BaseExtFunction · 0.85
BaseFunction · 0.85

Calls 1

STRNLENFunction · 0.85

Tested by

no test coverage detected