Skip to content

Commit

Permalink
Check if GetFinalPathNameByHandleW() is available
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMertes committed Nov 23, 2023
1 parent 005cb40 commit e69d9c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/chkccomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6258,6 +6258,18 @@ static void determineOsWCharFunctions (FILE *versionFile)
fputs("#define os_setmode _setmode\n", versionFile);
} /* if */
#endif
if (compileAndLinkOk("#include <stdio.h>\n#include <windows.h>\n"
"int main(int argc,char *argv[])\n"
"{HANDLE fileHandle;\n"
"fileHandle = CreateFile(\"tst_vers.h\", 0, FILE_SHARE_READ, NULL,\n"
" OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |\n"
" FILE_FLAG_BACKUP_SEMANTICS, NULL);\n"
"printf(\"%d\\n\", fileHandle != INVALID_HANDLE_VALUE &&\n"
" GetFinalPathNameByHandleW(fileHandle,\n"
" NULL, 0, FILE_NAME_OPENED) != 0);\n"
"return 0;}\n")) {
fputs("#define DEFINE_WIN_READ_LINK\n", versionFile);
} /* if */
} /* determineOsWCharFunctions */
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/cmd_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int wsetenv (const const_os_striType name, const const_os_striType value,
#ifdef DEFINE_WUNSETENV
int wunsetenv (const const_os_striType name);
#endif
#ifdef OS_STRI_WCHAR
#ifdef DEFINE_WIN_READ_LINK
striType winReadLink (const const_striType filePath, errInfoType *err_info);
#endif
striType cmdGetGroup (const const_striType filePath);
Expand Down
4 changes: 2 additions & 2 deletions src/cmd_rtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3369,7 +3369,7 @@ striType cmdReadLink (const const_striType filePath)
raise_error(err_info);
} /* if */
#else
#ifdef OS_STRI_WCHAR
#ifdef DEFINE_WIN_READ_LINK
destination = winReadLink(filePath, &err_info);
if (unlikely(destination == NULL)) {
raise_error(err_info);
Expand Down Expand Up @@ -3419,7 +3419,7 @@ striType cmdReadLinkAbsolute (const const_striType filePath)
raise_error(err_info);
} /* if */
#else
#ifdef OS_STRI_WCHAR
#ifdef DEFINE_WIN_READ_LINK
destination = winReadLink(filePath, &err_info);
if (unlikely(destination == NULL)) {
raise_error(err_info);
Expand Down
2 changes: 2 additions & 0 deletions src/cmd_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ static PSID getSidFromName (const const_striType name, errInfoType *err_info)



#ifdef DEFINE_WIN_READ_LINK
striType winReadLink (const const_striType filePath, errInfoType *err_info)

{
Expand Down Expand Up @@ -614,6 +615,7 @@ striType winReadLink (const const_striType filePath, errInfoType *err_info)
printf("\"%s\"\n", striAsUnquotedCStri(destination)););
return destination;
} /* winReadLink */
#endif



Expand Down
4 changes: 4 additions & 0 deletions src/stat_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ int lstati64Ext (const wchar_t *path, os_stat_struct *statBuf)
statBuf->st_mode = S_IFLNK | S_IRUSR | S_IRGRP | S_IROTH |
S_IWUSR | S_IWGRP | S_IWOTH |
S_IXUSR | S_IXGRP | S_IXOTH;
#ifdef DEFINE_WIN_READ_LINK
fileHandle = CreateFileW(path, 0, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_BACKUP_SEMANTICS, NULL);
Expand All @@ -314,6 +315,9 @@ int lstati64Ext (const wchar_t *path, os_stat_struct *statBuf)
#endif
CloseHandle(fileHandle);
} /* if */
#else
statBuf->st_size = 0;
#endif
} /* if */
} /* if */
} /* if */
Expand Down

0 comments on commit e69d9c4

Please sign in to comment.