From 44cf820304298bd5fba5a5be5d332c2afa9d4091 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Sun, 3 May 2015 02:42:02 +0000 Subject: kpathsea: Implement same_file_p () for windows (w32 only). git-svn-id: svn://tug.org/texlive/trunk@37161 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/kpathsea/ChangeLog | 4 ++++ Build/source/texk/kpathsea/file-p.c | 39 +++++++++++++++++++++++++++++++++++ Build/source/texk/kpathsea/win32lib.h | 1 + 3 files changed, 44 insertions(+) (limited to 'Build/source/texk/kpathsea') diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index b5ec656aedc..51b97fc4c4d 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,7 @@ +2015-05-03 Akira Kakuto + + * file-p.c: Implement same_file_p () for windows. + 2015-04-17 Peter Breitenlohner * configure.ac: Test if isascii is declared. diff --git a/Build/source/texk/kpathsea/file-p.c b/Build/source/texk/kpathsea/file-p.c index 23218c94467..eb8955f08a3 100644 --- a/Build/source/texk/kpathsea/file-p.c +++ b/Build/source/texk/kpathsea/file-p.c @@ -26,6 +26,44 @@ boolean same_file_p (const_string filename1, const_string filename2) { +#ifdef _WIN32 + intptr_t handle1, handle2; + FILE *f1, *f2; + BY_HANDLE_FILE_INFORMATION fileinfo1, fileinfo2; + + f1 = fopen(filename1, "r"); + if(!f1) return false; + f2 = fopen(filename2, "r"); + if(!f2) { + fclose(f1); + return false; + } + + handle1 = _get_osfhandle(fileno(f1)); + handle2 = _get_osfhandle(fileno(f2)); + + if (!GetFileInformationByHandle((HANDLE)handle1, &fileinfo1)) { + fclose(f1); + fclose(f2); + return false; + } + + if (!GetFileInformationByHandle((HANDLE)handle2, &fileinfo2)) { + fclose(f1); + fclose(f2); + return false; + } + + fclose(f1); + fclose(f2); + + if (fileinfo1.dwVolumeSerialNumber == fileinfo2.dwVolumeSerialNumber && + fileinfo1.nFileIndexHigh == fileinfo2.nFileIndexHigh && + fileinfo1.nFileIndexLow == fileinfo2.nFileIndexLow) + return true; + else + return false; +#else struct stat sb1, sb2; /* These are put in variables only so the results can be inspected under gdb. */ @@ -33,4 +71,5 @@ same_file_p (const_string filename1, const_string filename2) int r2 = stat (filename2, &sb2); return r1 == 0 && r2 == 0 ? SAME_FILE_P (sb1, sb2) : false; +#endif } diff --git a/Build/source/texk/kpathsea/win32lib.h b/Build/source/texk/kpathsea/win32lib.h index d7e51f054a7..853899ddb7b 100644 --- a/Build/source/texk/kpathsea/win32lib.h +++ b/Build/source/texk/kpathsea/win32lib.h @@ -253,6 +253,7 @@ extern KPSEDLL FILE *win32_popen (const char *cmd, const char *mode); extern KPSEDLL int win32_pclose (FILE *f); extern KPSEDLL struct passwd *kpathsea_getpwnam (kpathsea kpse, char *name); extern KPSEDLL int win32_system(const char *cmd); +extern KPSEDLL void kpathsea_init_user_info (kpathsea kpse); #if defined (KPSE_COMPAT_API) extern KPSEDLL struct passwd *getpwnam (char *name); -- cgit v1.2.3