getino(struct ustat *ub)
{
ULARGE_INTEGER ino64;
-
ino64.QuadPart = ub->st_ino;
/* I don't know this hashing is correct way */
return (ino64.LowPart ^ (ino64.LowPart >> INOSIZE));
return f == NULL ? 0 : (*f)(linkname, target, NULL);
}
-/* Check that path1 and path2 can be hard-linked by each other.
- * Both arguments must be made by permissive_name function.
- */
-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);
-}
-
-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);
-}
/* Make a link to src called dst. */
static int
wsrc = permissive_name(src);
wdst = permissive_name(dst);
if (wsrc == NULL || wdst == NULL) {
- if (wsrc != NULL)
- free(wsrc);
- if (wdst != NULL)
- free(wdst);
+ free(wsrc);
+ free(wdst);
set_errno (EINVAL);
return -1;
}
if ((attr = GetFileAttributesW(wsrc)) != -1) {
- if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
- errno = EPERM;
- retval = -1;
- goto exit;
- }
- if (!sym && canHardLinkW(wsrc, wdst)) {
- res = la_CreateHardLinkW(wdst, wsrc);
- } else {
- res = CopyFileW(wsrc, wdst, FALSE);
- }
+ res = la_CreateHardLinkW(wdst, wsrc);
} else {
/* wsrc does not exist; try src prepend it with the dirname of wdst */
wchar_t *wnewsrc, *slash;
retval = -1;
goto exit;
}
- if (!sym && canHardLinkW(wnewsrc, wdst))
- res = la_CreateHardLinkW(wdst, wnewsrc);
- else
- res = CopyFileW(wnewsrc, wdst, FALSE);
+ res = la_CreateHardLinkW(wdst, wnewsrc);
free (wnewsrc);
}
if (res == 0) {
return __link (src, dst, 0);
}
-/* Make a symbolic link to FROM called TO. */
-int
-__la_symlink (const char *from, const char *to)
-{
- return __link (from, to, 1);
-}
-
int
__la_ftruncate(int fd, off_t length)
{
#if defined(_MSC_VER)
/* TODO: Fix the code, don't suppress the warnings. */
#pragma warning(disable:4244) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */
-#pragma warning(disable:4146) /* unary minus operator applied to unsigned type, result still unsigned */
-//#pragma warning(disable:4267) /* Conversion, possible loss of data */
-#pragma warning(default: 4061) /* The enumerate has no associated handler in a switch statement */
-#pragma warning(default: 4296) /* An unsigned variable was used in a comparison operation with zero */
#pragma warning(default: 4365) /* 'action':conversion from 'type_1' to 'type_2', signed/unsigned mismatch */
#endif
#define rmdir __la_rmdir
#define stat(path,stref) __la_stat(path,stref)
#define strdup _strdup
-#define symlink __la_symlink
#define tzset _tzset
#define umask _umask
#define unlink __la_unlink
#ifndef HAVE_LINK
#define HAVE_LINK 1
#endif
-#ifndef HAVE_SYMLINK
-#define HAVE_SYMLINK 1
-#endif
/* Replacement POSIX function */
extern int __la_chdir(const char *path);
extern ssize_t __la_read(int fd, void *buf, size_t nbytes);
extern int __la_rmdir(const char *path);
extern int __la_stat(const char *path, struct stat *st);
-extern int __la_symlink(const char *from, const char *to);
extern int __la_unlink(const char *path);
extern int __la_utimes(const char *name, const struct __timeval *times);
extern pid_t __la_waitpid(pid_t wpid, int *status, int option);