@@ -84,16 +84,15 @@ static const cpj_char_t *cpj_path_find_next_stop(cpj_path_style_t path_style, co
8484 return c ;
8585} /* cpj_path_find_next_stop */
8686
87- static void cpj_path_get_root_windows (const cpj_char_t * path , cpj_size_t * length )
87+ static cpj_size_t cpj_path_get_root_windows (const cpj_char_t * path )
8888{
8989 const cpj_char_t * c ;
90-
90+ cpj_size_t length = 0 ;
9191 // We can not determine the root if this is an empty string. So we set the
9292 // root to NULL and the length to zero and cancel the whole thing.
9393 c = path ;
94- * length = 0 ;
9594 if (!* c ) {
96- return ;
95+ return length ;
9796 }
9897
9998 // Now we have to verify whether this is a windows network path (UNC), which
@@ -107,8 +106,8 @@ static void cpj_path_get_root_windows(const cpj_char_t *path, cpj_size_t *length
107106 if (!cpj_path_is_separator (CPJ_STYLE_WINDOWS , * c )) {
108107 // Okay, this is not a network path but we still use the backslash as a
109108 // root.
110- ++ ( * length ) ;
111- return ;
109+ ++ length ;
110+ return length ;
112111 }
113112
114113 // A device path is a path which starts with "\\." or "\\?". A device path
@@ -124,8 +123,8 @@ static void cpj_path_get_root_windows(const cpj_char_t *path, cpj_size_t *length
124123 // That's a device path, and the root must be either "\\.\" or "\\?\"
125124 // which is 4 characters long. (at least that's how Windows
126125 // GetFullPathName behaves.)
127- * length = 4 ;
128- return ;
126+ length = 4 ;
127+ return length ;
129128 }
130129
131130 // We will grab anything up to the next stop. The next stop might be a '\0'
@@ -149,44 +148,37 @@ static void cpj_path_get_root_windows(const cpj_char_t *path, cpj_size_t *length
149148 }
150149
151150 // Finally, calculate the size of the root.
152- * length = (cpj_size_t )(c - path );
153- return ;
151+ length = (cpj_size_t )(c - path );
152+ return length ;
154153 }
155154
156155 // Move to the next and check whether this is a colon.
157156 if (* ++ c == ':' ) {
158- * length = 2 ;
157+ length = 2 ;
159158
160159 // Now check whether this is a backslash (or slash). If it is not, we could
161160 // assume that the next character is a '\0' if it is a valid path. However,
162161 // we will not assume that - since ':' is not valid in a path it must be a
163162 // mistake by the caller than. We will try to understand it anyway.
164163 if (cpj_path_is_separator (CPJ_STYLE_WINDOWS , * (++ c ))) {
165- * length = 3 ;
164+ length = 3 ;
166165 }
167166 }
167+ return length ;
168168} /* cpj_path_get_root_windows */
169169
170- static void cpj_path_get_root_unix (const cpj_char_t * path , cpj_size_t * length )
170+ static cpj_size_t cpj_path_get_root_unix (const cpj_char_t * path )
171171{
172172 // The slash of the unix path represents the root. There is no root if there
173173 // is no slash.
174- if (cpj_path_is_separator (CPJ_STYLE_UNIX , * path )) {
175- * length = 1 ;
176- } else {
177- * length = 0 ;
178- }
174+ return cpj_path_is_separator (CPJ_STYLE_UNIX , * path ) ? 1 : 0 ;
179175} /* cpj_path_get_root_unix */
180176
181- void cpj_path_get_root (cpj_path_style_t path_style , const cpj_char_t * path , cpj_size_t * length )
177+ cpj_size_t cpj_path_get_root (cpj_path_style_t path_style , const cpj_char_t * path )
182178{
183179 // We use a different implementation here based on the configuration of the
184180 // library.
185- if (path_style == CPJ_STYLE_WINDOWS ) {
186- cpj_path_get_root_windows (path , length );
187- } else {
188- cpj_path_get_root_unix (path , length );
189- }
181+ return path_style == CPJ_STYLE_WINDOWS ? cpj_path_get_root_windows (path ) : cpj_path_get_root_unix (path );
190182} /* cpj_path_get_root */
191183
192184static cpj_char_t cpj_path_get_char (cpj_join_state_t * state , cpj_iterator_t * it )
@@ -204,7 +196,7 @@ static void cpj_path_update_root_length(cpj_join_state_t *state, cpj_iterator_t
204196{
205197 state -> path_total_size += state -> path_list_p [it -> list_pos ].size ;
206198 if (state -> is_module || it -> list_pos == 0 ) {
207- cpj_path_get_root (state -> style , state -> path_list_p [it -> list_pos ].ptr , & it -> root_length );
199+ it -> root_length = cpj_path_get_root (state -> style , state -> path_list_p [it -> list_pos ].ptr );
208200 }
209201} /* cpj_path_update_root_length */
210202
@@ -992,8 +984,8 @@ cpj_size_t cpj_path_get_relative(
992984 // First we compare the roots of those two paths. If the roots are not equal
993985 // we can't continue, since there is no way to get a relative path from
994986 // different roots.
995- cpj_path_get_root (path_style , base_directory , & base_root_length );
996- cpj_path_get_root (path_style , path , & path_root_length );
987+ base_root_length = cpj_path_get_root (path_style , base_directory );
988+ path_root_length = cpj_path_get_root (path_style , path );
997989 if (base_root_length != path_root_length ||
998990 !cpj_path_is_string_equal (path_style , base_directory , path , base_root_length , path_root_length )) {
999991 cpj_path_terminate_output (buffer , buffer_size , pos );
@@ -1093,7 +1085,7 @@ cpj_size_t cpj_path_change_root(
10931085
10941086 // First we need to determine the actual size of the root which we will
10951087 // change.
1096- cpj_path_get_root (path_style , path , & root_length );
1088+ root_length = cpj_path_get_root (path_style , path );
10971089
10981090 // Now we determine the sizes of the new root and the path. We need that to
10991091 // determine the size of the part after the root (the tail).
@@ -1118,24 +1110,6 @@ cpj_size_t cpj_path_change_root(
11181110 return new_path_size ;
11191111}
11201112
1121- bool cpj_path_is_absolute (cpj_path_style_t path_style , const cpj_char_t * path )
1122- {
1123- cpj_size_t length ;
1124-
1125- // We grab the root of the path. This root does not include the first
1126- // separator of a path.
1127- cpj_path_get_root (path_style , path , & length );
1128-
1129- // Now we can determine whether the root is absolute or not.
1130- return cpj_path_is_root_absolute (path_style , path , length );
1131- }
1132-
1133- bool cpj_path_is_relative (cpj_path_style_t path_style , const cpj_char_t * path )
1134- {
1135- // The path is relative if it is not absolute.
1136- return !cpj_path_is_absolute (path_style , path );
1137- }
1138-
11391113void cpj_path_get_basename (
11401114 cpj_path_style_t path_style , const cpj_char_t * path , const cpj_char_t * * basename , cpj_size_t * length
11411115)
@@ -1176,7 +1150,7 @@ cpj_size_t cpj_path_change_basename(
11761150
11771151 // So there is no segment in this path. First we grab the root and output
11781152 // that. We are not going to modify the root in any way.
1179- cpj_path_get_root (path_style , path , & root_size );
1153+ root_size = cpj_path_get_root (path_style , path );
11801154 pos = cpj_path_output_sized (buffer , buffer_size , 0 , path , root_size );
11811155
11821156 // We have to trim the separators from the beginning of the new basename.
@@ -1282,7 +1256,7 @@ cpj_size_t cpj_path_change_extension(
12821256 // So there is no segment in this path. First we grab the root and output
12831257 // that. We are not going to modify the root in any way. If there is no
12841258 // root, this will end up with a root size 0, and nothing will be written.
1285- cpj_path_get_root (path_style , path , & root_size );
1259+ root_size = cpj_path_get_root (path_style , path );
12861260 pos = cpj_path_output_sized (buffer , buffer_size , 0 , path , root_size );
12871261
12881262 // Add a dot if the submitted value doesn't have any.
@@ -1349,8 +1323,8 @@ cpj_path_get_intersection(cpj_path_style_t path_style, const cpj_char_t *path_ba
13491323 // We first compare the two roots. We just return zero if they are not equal.
13501324 // This will also happen to return zero if the paths are mixed relative and
13511325 // absolute.
1352- cpj_path_get_root (path_style , path_base , & base_root_length );
1353- cpj_path_get_root (path_style , path_other , & other_root_length );
1326+ base_root_length = cpj_path_get_root (path_style , path_base );
1327+ other_root_length = cpj_path_get_root (path_style , path_other );
13541328 if (!cpj_path_is_string_equal (path_style , path_base , path_other , base_root_length , other_root_length )) {
13551329 return 0 ;
13561330 }
@@ -1413,7 +1387,7 @@ bool cpj_path_get_first_segment(cpj_path_style_t path_style, const cpj_char_t *p
14131387
14141388 // We skip the root since that's not part of the first segment. The root is
14151389 // treated as a separate entity.
1416- cpj_path_get_root (path_style , path , & length );
1390+ length = cpj_path_get_root (path_style , path );
14171391 segments = path + length ;
14181392
14191393 // Now, after we skipped the root we can continue and find the actual segment
@@ -1585,7 +1559,7 @@ cpj_path_style_t cpj_path_guess_style(const cpj_char_t *path)
15851559 // First we determine the root. Only windows roots can be longer than a single
15861560 // slash, so if we can determine that it starts with something like "C:", we
15871561 // know that this is a windows path.
1588- cpj_path_get_root_windows (path , & root_length );
1562+ root_length = cpj_path_get_root_windows (path );
15891563 if (root_length > 1 ) {
15901564 return CPJ_STYLE_WINDOWS ;
15911565 }
0 commit comments