aboutsummaryrefslogtreecommitdiffstats
path: root/lib/canonicalize-lgpl.c
diff options
context:
space:
mode:
authorPaul Eggert2025-12-12 15:24:31 -0800
committerPaul Eggert2025-12-12 16:27:11 -0800
commit41ffeaec15b9a0f052de2d2e5eab23302c4ce46b (patch)
treea2e82875cc70f7881ba5627872fc8c11630256ec /lib/canonicalize-lgpl.c
parent976143651b832ca0dcaf1d15e41eb7424aec4c90 (diff)
downloademacs-41ffeaec15b9a0f052de2d2e5eab23302c4ce46b.tar.gz
emacs-41ffeaec15b9a0f052de2d2e5eab23302c4ce46b.zip
Update from Gnulib by running admin/merge-gnulib
Diffstat (limited to 'lib/canonicalize-lgpl.c')
-rw-r--r--lib/canonicalize-lgpl.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index 7aea4aaba61..ed89ec4f679 100644
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -191,11 +191,6 @@ struct realpath_bufs
191static char * 191static char *
192realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs) 192realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
193{ 193{
194 char *dest;
195 char const *start;
196 char const *end;
197 int num_links = 0;
198
199 if (name == NULL) 194 if (name == NULL)
200 { 195 {
201 /* As per Single Unix Specification V2 we must return an error if 196 /* As per Single Unix Specification V2 we must return an error if
@@ -215,12 +210,15 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
215 } 210 }
216 211
217 char *rname = bufs->rname.data; 212 char *rname = bufs->rname.data;
218 bool end_in_extra_buffer = false;
219 bool failed = true;
220 213
221 /* This is always zero for Posix hosts, but can be 2 for MS-Windows 214 /* This is always zero for Posix hosts, but can be 2 for MS-Windows
222 and MS-DOS X:/foo/bar file names. */ 215 and MS-DOS X:/foo/bar file names. */
223 idx_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); 216 idx_t prefix_len;
217
218 char *dest;
219 char const *start;
220
221 bool failed = true;
224 222
225 if (!IS_ABSOLUTE_FILE_NAME (name)) 223 if (!IS_ABSOLUTE_FILE_NAME (name))
226 { 224 {
@@ -241,6 +239,7 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
241 } 239 }
242 else 240 else
243 { 241 {
242 prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
244 dest = __mempcpy (rname, name, prefix_len); 243 dest = __mempcpy (rname, name, prefix_len);
245 *dest++ = '/'; 244 *dest++ = '/';
246 if (DOUBLE_SLASH_IS_DISTINCT_ROOT) 245 if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
@@ -253,13 +252,17 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
253 start = name + prefix_len; 252 start = name + prefix_len;
254 } 253 }
255 254
256 for ( ; *start; start = end) 255 int num_links = 0;
256 bool end_in_extra_buffer = false;
257
258 for (; *start;)
257 { 259 {
258 /* Skip sequence of multiple file name separators. */ 260 /* Skip sequence of multiple file name separators. */
259 while (ISSLASH (*start)) 261 while (ISSLASH (*start))
260 ++start; 262 ++start;
261 263
262 /* Find end of component. */ 264 /* Find end of component. */
265 char const *end;
263 for (end = start; *end && !ISSLASH (*end); ++end) 266 for (end = start; *end && !ISSLASH (*end); ++end)
264 /* Nothing. */; 267 /* Nothing. */;
265 268
@@ -378,6 +381,8 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
378 : errno == EINVAL)) 381 : errno == EINVAL))
379 goto error; 382 goto error;
380 } 383 }
384
385 start = end;
381 } 386 }
382 if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1])) 387 if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))
383 --dest; 388 --dest;