aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-05-22 11:06:14 +0100
committerRon Yorston <rmy@pobox.com>2022-05-22 11:06:14 +0100
commit32de287bb714ff185d943090622b4cb64287dd78 (patch)
treed6739ff3e6d63794ad4df40a30be81b8443858ca
parentb68bda6482aed55d13b5bb622f60bc63ea930472 (diff)
downloadbusybox-w32-32de287bb714ff185d943090622b4cb64287dd78.tar.gz
busybox-w32-32de287bb714ff185d943090622b4cb64287dd78.tar.bz2
busybox-w32-32de287bb714ff185d943090622b4cb64287dd78.zip
win32: code shrink readlink(2)
Use PrintName rather than SubstituteName from the reparse data buffer. This avoids the need to normalise the name. Saves 240 bytes.
-rw-r--r--win32/mingw.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index bf9b75a7f..95f5e5687 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1526,30 +1526,6 @@ char *realpath(const char *path, char *resolved_path)
1526 return NULL; 1526 return NULL;
1527} 1527}
1528 1528
1529static wchar_t *normalize_ntpath(wchar_t *wbuf)
1530{
1531 int i;
1532 /* fix absolute path prefixes */
1533 if (wbuf[0] == '\\') {
1534 /* strip NT namespace prefixes */
1535 if (!wcsncmp(wbuf, L"\\??\\", 4) ||
1536 !wcsncmp(wbuf, L"\\\\?\\", 4))
1537 wbuf += 4;
1538 else if (!wcsnicmp(wbuf, L"\\DosDevices\\", 12))
1539 wbuf += 12;
1540 /* replace remaining '...UNC\' with '\\' */
1541 if (!wcsnicmp(wbuf, L"UNC\\", 4)) {
1542 wbuf += 2;
1543 *wbuf = '\\';
1544 }
1545 }
1546 /* convert backslashes to slashes */
1547 for (i = 0; wbuf[i]; i++)
1548 if (wbuf[i] == '\\')
1549 wbuf[i] = '/';
1550 return wbuf;
1551}
1552
1553#define SRPB rptr->SymbolicLinkReparseBuffer 1529#define SRPB rptr->SymbolicLinkReparseBuffer
1554ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) 1530ssize_t readlink(const char *pathname, char *buf, size_t bufsiz)
1555{ 1531{
@@ -1570,21 +1546,25 @@ ssize_t readlink(const char *pathname, char *buf, size_t bufsiz)
1570 CloseHandle(h); 1546 CloseHandle(h);
1571 1547
1572 if (status && rptr->ReparseTag == IO_REPARSE_TAG_SYMLINK) { 1548 if (status && rptr->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
1573 len = SRPB.SubstituteNameLength/sizeof(WCHAR); 1549 len = SRPB.PrintNameLength/sizeof(WCHAR);
1574 name = SRPB.PathBuffer + SRPB.SubstituteNameOffset/sizeof(WCHAR); 1550 name = SRPB.PathBuffer + SRPB.PrintNameOffset/sizeof(WCHAR);
1575 } else if (status && rptr->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { 1551 } else if (status && rptr->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) {
1576 len = MRPB.SubstituteNameLength/sizeof(WCHAR); 1552 len = MRPB.PrintNameLength/sizeof(WCHAR);
1577 name = MRPB.PathBuffer + MRPB.SubstituteNameOffset/sizeof(WCHAR); 1553 name = MRPB.PathBuffer + MRPB.PrintNameOffset/sizeof(WCHAR);
1578 } 1554 }
1579 1555
1580 if (name) { 1556 if (name) {
1581 name[len] = 0;
1582 name = normalize_ntpath(name);
1583 len = wcslen(name);
1584 if (len > bufsiz) 1557 if (len > bufsiz)
1585 len = bufsiz; 1558 len = bufsiz;
1586 if (WideCharToMultiByte(CP_ACP, 0, name, len, buf, bufsiz, 0, 0)) 1559 len = WideCharToMultiByte(CP_ACP, 0, name, len, buf, bufsiz, 0, 0);
1560 if (len) {
1561 int i;
1562
1563 for (i = 0; i < len; i++)
1564 if (buf[i] == '\\')
1565 buf[i] = '/';
1587 return len; 1566 return len;
1567 }
1588 } 1568 }
1589 } 1569 }
1590 errno = err_win_to_posix(); 1570 errno = err_win_to_posix();