diff options
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index fec6df73a..8588b1a86 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -673,8 +673,7 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf) | |||
673 | buf->st_tag = get_symlink_data(buf->st_attr, file_name, &findbuf); | 673 | buf->st_tag = get_symlink_data(buf->st_attr, file_name, &findbuf); |
674 | 674 | ||
675 | if (buf->st_tag) { | 675 | if (buf->st_tag) { |
676 | ssize_t len; | 676 | char *content; |
677 | char content[PATH_MAX]; | ||
678 | 677 | ||
679 | if (follow) { | 678 | if (follow) { |
680 | /* The file size and times are wrong when Windows follows | 679 | /* The file size and times are wrong when Windows follows |
@@ -687,8 +686,9 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf) | |||
687 | 686 | ||
688 | /* Get the contents of a symlink, not its target. */ | 687 | /* Get the contents of a symlink, not its target. */ |
689 | buf->st_mode = S_IFLNK|S_IRWXU|S_IRWXG|S_IRWXO; | 688 | buf->st_mode = S_IFLNK|S_IRWXU|S_IRWXG|S_IRWXO; |
690 | len = readlink(file_name, content, PATH_MAX); | 689 | content = xmalloc_readlink(file_name); |
691 | buf->st_size = (len < 0 || len == PATH_MAX) ? 0 : len; | 690 | buf->st_size = content ? strlen(content) : 0; |
691 | free(content); | ||
692 | buf->st_atim = filetime_to_timespec(&(findbuf.ftLastAccessTime)); | 692 | buf->st_atim = filetime_to_timespec(&(findbuf.ftLastAccessTime)); |
693 | buf->st_mtim = filetime_to_timespec(&(findbuf.ftLastWriteTime)); | 693 | buf->st_mtim = filetime_to_timespec(&(findbuf.ftLastWriteTime)); |
694 | buf->st_ctim = filetime_to_timespec(&(findbuf.ftCreationTime)); | 694 | buf->st_ctim = filetime_to_timespec(&(findbuf.ftCreationTime)); |
@@ -1642,9 +1642,11 @@ typedef struct { | |||
1642 | } APPEXECLINK_BUFFER; | 1642 | } APPEXECLINK_BUFFER; |
1643 | 1643 | ||
1644 | #define SRPB rptr->SymbolicLinkReparseBuffer | 1644 | #define SRPB rptr->SymbolicLinkReparseBuffer |
1645 | ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) | 1645 | char * FAST_FUNC xmalloc_readlink(const char *pathname) |
1646 | { | 1646 | { |
1647 | HANDLE h; | 1647 | HANDLE h; |
1648 | char *buf; | ||
1649 | int bufsiz; | ||
1648 | 1650 | ||
1649 | h = CreateFile(pathname, 0, 0, NULL, OPEN_EXISTING, | 1651 | h = CreateFile(pathname, 0, 0, NULL, OPEN_EXISTING, |
1650 | FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL); | 1652 | FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL); |
@@ -1688,15 +1690,17 @@ ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) | |||
1688 | if (name) { | 1690 | if (name) { |
1689 | name[len] = 0; | 1691 | name[len] = 0; |
1690 | name = normalize_ntpath(name); | 1692 | name = normalize_ntpath(name); |
1691 | len = wcslen(name); | 1693 | bufsiz = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, 0, 0); |
1692 | if (len > bufsiz) | 1694 | if (bufsiz) { |
1693 | len = bufsiz; | 1695 | buf = xmalloc(bufsiz); |
1694 | if (WideCharToMultiByte(CP_ACP, 0, name, len, buf, bufsiz, 0, 0)) | 1696 | if (WideCharToMultiByte(CP_ACP, 0, name, -1, buf, bufsiz, 0, 0)) |
1695 | return len; | 1697 | return buf; |
1698 | free(buf); | ||
1699 | } | ||
1696 | } | 1700 | } |
1697 | } | 1701 | } |
1698 | errno = err_win_to_posix(); | 1702 | errno = err_win_to_posix(); |
1699 | return -1; | 1703 | return NULL; |
1700 | } | 1704 | } |
1701 | 1705 | ||
1702 | const char *get_busybox_exec_path(void) | 1706 | const char *get_busybox_exec_path(void) |