- getcwd is slow, it might fail, and it does not necessarily
- return a canonical name even when it succeeds. Perhaps we
- can use dev+ino pairs instead of names? */
- copy = tar_getcwd ();
- if (copy)
- {
- size_t copylen = strlen (copy);
- bool need_separator = ! (DOUBLE_SLASH_IS_DISTINCT_ROOT
- && copylen == 2 && ISSLASH (copy[1]));
- copy = xrealloc (copy, copylen + need_separator + strlen (name) + 1);
- copy[copylen] = DIRECTORY_SEPARATOR;
- strcpy (copy + copylen + need_separator, name);
- }
- else
- WARN ((0, errno, _("Cannot get working directory")));
+ tar_getcdpath does not return a true "canonical" path, so
+ this following approach may lead to situations where the same
+ file or directory is processed twice under different absolute
+ paths without that duplication being detected. Perhaps we
+ should use dev+ino pairs instead of names? */
+ const char *cdpath = tar_getcdpath (cdidx);
+ size_t copylen;
+ bool need_separator;
+
+ if (!cdpath)
+ call_arg_fatal ("getcwd", ".");
+ copylen = strlen (cdpath);
+ need_separator = ! (DOUBLE_SLASH_IS_DISTINCT_ROOT
+ && copylen == 2 && ISSLASH (cdpath[1]));
+ copy = xmalloc (copylen + need_separator + strlen (name) + 1);
+ strcpy (copy, cdpath);
+ copy[copylen] = DIRECTORY_SEPARATOR;
+ strcpy (copy + copylen + need_separator, name);