comparison src/realpath.c @ 1760:0240ff815597

[xemacs-hg @ 2003-10-22 14:16:58 by james] Fix Cygwin problem with resolving symbolic links to absolute pathnames.
author james
date Wed, 22 Oct 2003 14:17:00 +0000
parents e22b0213b713
children ecf1ebac70d8
comparison
equal deleted inserted replaced
1759:a14f3af8e6fb 1760:0240ff815597
178 Ibyte link_path[PATH_MAX]; 178 Ibyte link_path[PATH_MAX];
179 int n; 179 int n;
180 int abslen = abs_start (path); 180 int abslen = abs_start (path);
181 #endif 181 #endif
182 182
183 restart:
184
183 /* Make a copy of the source path since we may need to modify it. */ 185 /* Make a copy of the source path since we may need to modify it. */
184 qxestrcpy (copy_path, path); 186 qxestrcpy (copy_path, path);
185 path = copy_path; 187 path = copy_path;
186 max_path = copy_path + PATH_MAX - 2; 188 max_path = copy_path + PATH_MAX - 2;
187 189
318 } 320 }
319 321
320 /* Note: readlink doesn't add the null byte. */ 322 /* Note: readlink doesn't add the null byte. */
321 link_path[n] = '\0'; 323 link_path[n] = '\0';
322 324
323 if (abs_start (link_path) > 0) 325 abslen = abs_start (link_path);
324 /* Start over for an absolute symlink. */ 326 if (abslen > 0)
325 new_path = resolved_path + abs_start (link_path) - 1; 327 {
326 else 328 /* Start over for an absolute symlink. */
327 /* Otherwise back up over this component. */ 329 new_path = resolved_path;
328 for (--new_path; !IS_DIRECTORY_SEP (*new_path); --new_path) 330 qxestrcat (link_path, path);
329 assert (new_path > resolved_path); 331 path = link_path;
332 goto restart;
333 }
334
335 /* Otherwise back up over this component. */
336 for (--new_path; !IS_DIRECTORY_SEP (*new_path); --new_path)
337 assert (new_path > resolved_path);
330 338
331 /* Safe sex check. */ 339 /* Safe sex check. */
332 if (qxestrlen (path) + n >= PATH_MAX) 340 if (qxestrlen (path) + n >= PATH_MAX)
333 { 341 {
334 errno = ENAMETOOLONG; 342 errno = ENAMETOOLONG;