From: Tim Kientzle Date: Thu, 10 Sep 2009 04:06:22 +0000 (-0400) Subject: Remove some unused code; fix the build on MinGW. X-Git-Tag: v2.8.0~363 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04850cfd614d68ef0e7e2c591d83f0df6ce5d66c;p=thirdparty%2Flibarchive.git Remove some unused code; fix the build on MinGW. SVN-Revision: 1445 --- diff --git a/cpio/cpio_windows.c b/cpio/cpio_windows.c index 0fc8c898e..90bb85a4a 100644 --- a/cpio/cpio_windows.c +++ b/cpio/cpio_windows.c @@ -204,213 +204,6 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, return (handle); } -#if HAVE_CREATEHARDLINKW -static size_t -wequallen(const wchar_t *s1, const wchar_t *s2) -{ - size_t i = 0; - - while (*s1 != L'\0' && *s2 != L'\0' && *s1 == *s2) { - ++s1; ++s2; ++i; - } - return (i); -} - -/* Check that path1 and path2 can be hard-linked by each other. - * Both arguments must be made by permissive_name function. - */ -static int -canHardLinkW(const wchar_t *path1, const wchar_t *path2) -{ - wchar_t root[MAX_PATH]; - wchar_t fs[32]; - const wchar_t *s; - int r; - - r = wequallen(path1, path2); - /* Is volume-name the same? */ - if (r < 7) - return (0); - if (wcsncmp(path1, L"\\\\?\\UNC\\", 8) == 0) { - int len; - - s = path1 + 8; - if (*s == L'\\') - return (0); - /* 012345678 - * Name : "\\?\UNC\Server\Share\" - * ^ search - */ - s = wcschr(++s, L'\\'); - if (s == NULL) - return (0); - if (*++s == L'\\') - return (0); - /* 012345678 - * Name : "\\?\UNC\Server\Share\" - * ^ search - */ - s = wcschr(++s, L'\\'); - if (s == NULL) - return (0); - s++; - /* 012345678 - * Name : "\\?\UNC\Server\Share\xxxx" - * ^--- len ----^ - */ - len = (int)(s - path1 - 8); - /* Is volume-name the same? */ - if (r < len + 8) - return (0); - /* Is volume-name too long? */ - if (sizeof(root) -3 < len) - return (0); - root[0] = root[1] = L'\\'; - wcsncpy(root + 2, path1 + 8 , len); - /* root : "\\Server\Share\" */ - root[2 + len] = L'\0'; - } else if (wcsncmp(path1, L"\\\\?\\", 4) == 0) { - s = path1 + 4; - if ((!iswalpha(*s)) || s[1] != L':' || s[2] != L'\\') - return (0); - wcsncpy(root, path1 + 4, 3); - root[3] = L'\0'; - } else - return (0); - if (!GetVolumeInformationW(root, NULL, 0, NULL, NULL, NULL, fs, sizeof(fs))) - return (0); - if (wcscmp(fs, L"NTFS") == 0) - return (1); - else - return (0); -} -#endif - -/* Make a link to src called dst. */ -static int -__link(const char *src, const char *dst, int sym) -{ - wchar_t *wsrc, *wdst; - int res, retval; - DWORD attr; - - if (src == NULL || dst == NULL) { - errno = EINVAL; - return -1; - } - - wsrc = permissive_name(src); - wdst = permissive_name(dst); - if (wsrc == NULL || wdst == NULL) { - if (wsrc != NULL) - free(wsrc); - if (wdst != NULL) - free(wdst); - errno = EINVAL; - return -1; - } - - if ((attr = GetFileAttributesW(wsrc)) != -1) { - if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { - errno = EPERM; - retval = -1; - goto exit; - } -#if HAVE_CREATEHARDLINKW - if (!sym && canHardLinkW(wsrc, wdst)) - res = CreateHardLinkW(wdst, wsrc, NULL); - else -#endif - res = CopyFileW(wsrc, wdst, FALSE); - } else { - /* wsrc does not exist; try src prepend it with the dirname of wdst */ - wchar_t *wnewsrc, *slash; - int i, n, slen, wlen; - - if (strlen(src) >= 3 && isalpha((unsigned char)src[0]) && - src[1] == ':' && src[2] == '\\') { - /* Original src name is already full-path */ - retval = -1; - goto exit; - } - if (src[0] == '\\') { - /* Original src name is almost full-path - * (maybe src name is without drive) */ - retval = -1; - goto exit; - } - - wnewsrc = malloc ((wcslen(wsrc) + wcslen(wdst) + 1) * sizeof(wchar_t)); - if (wnewsrc == NULL) { - errno = ENOMEM; - retval = -1; - goto exit; - } - /* Copying a dirname of wdst */ - wcscpy(wnewsrc, wdst); - slash = wcsrchr(wnewsrc, L'\\'); - if (slash != NULL) - *++slash = L'\0'; - else - wcscat(wnewsrc, L"\\"); - /* Converting multi-byte src to wide-char src */ - wlen = wcslen(wsrc); - slen = strlen(src); - n = MultiByteToWideChar(CP_ACP, 0, src, slen, wsrc, slen); - if (n == 0) { - free (wnewsrc); - retval = -1; - goto exit; - } - for (i = 0; i < n; i++) - if (wsrc[i] == L'/') - wsrc[i] = L'\\'; - wcsncat(wnewsrc, wsrc, n); - /* Check again */ - attr = GetFileAttributesW(wnewsrc); - if (attr == -1 || (attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { - if (attr == -1) - cpio_dosmaperr(GetLastError()); - else - errno = EPERM; - free (wnewsrc); - retval = -1; - goto exit; - } -#if HAVE_CREATEHARDLINKW - if (!sym && canHardLinkW(wnewsrc, wdst)) - res = CreateHardLinkW(wdst, wnewsrc, NULL); - else -#endif - res = CopyFileW(wnewsrc, wdst, FALSE); - free (wnewsrc); - } - if (res == 0) { - cpio_dosmaperr(GetLastError()); - retval = -1; - } else - retval = 0; -exit: - free(wsrc); - free(wdst); - return (retval); -} - -/* Make a hard link to src called dst. */ -int -link(const char *src, const char *dst) -{ - return __link (src, dst, 0); -} - -/* Make a symbolic link to FROM called TO. */ -int symlink (from, to) - const char *from; - const char *to; -{ - return __link (from, to, 1); -} - #define WINTIME(sec, usec) ((Int32x32To64(sec, 10000000) + EPOC_TIME) + (usec * 10)) static int __hutimes(HANDLE handle, const struct __timeval *times)