Fossil SCM
Make everything compile on MinGW(-w64). WARNING: will not run on Windows XP, that still has to be fixed! Should work on Vista+.
Commit
631dff61e0e8e1875c3f5a5a78bf5d946473c217
Parent
9c5bbd6a015482d…
2 files changed
+3
+24
-11
+3
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -72,10 +72,13 @@ | ||
| 72 | 72 | */ |
| 73 | 73 | /* the S_ISLNK provided by dirent.h for windows is inadequate, so fix it */ |
| 74 | 74 | #if defined(S_ISLNK) |
| 75 | 75 | # undef S_ISLNK |
| 76 | 76 | #endif |
| 77 | +#if !defined(S_IFLNK) | |
| 78 | +# define S_IFLNK 0120000 | |
| 79 | +#endif | |
| 77 | 80 | #if !defined(S_ISLNK) |
| 78 | 81 | # define S_ISLNK(x) ((x)==S_IFLNK) |
| 79 | 82 | #endif |
| 80 | 83 | #endif |
| 81 | 84 | |
| 82 | 85 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -72,10 +72,13 @@ | |
| 72 | */ |
| 73 | /* the S_ISLNK provided by dirent.h for windows is inadequate, so fix it */ |
| 74 | #if defined(S_ISLNK) |
| 75 | # undef S_ISLNK |
| 76 | #endif |
| 77 | #if !defined(S_ISLNK) |
| 78 | # define S_ISLNK(x) ((x)==S_IFLNK) |
| 79 | #endif |
| 80 | #endif |
| 81 | |
| 82 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -72,10 +72,13 @@ | |
| 72 | */ |
| 73 | /* the S_ISLNK provided by dirent.h for windows is inadequate, so fix it */ |
| 74 | #if defined(S_ISLNK) |
| 75 | # undef S_ISLNK |
| 76 | #endif |
| 77 | #if !defined(S_IFLNK) |
| 78 | # define S_IFLNK 0120000 |
| 79 | #endif |
| 80 | #if !defined(S_ISLNK) |
| 81 | # define S_ISLNK(x) ((x)==S_IFLNK) |
| 82 | #endif |
| 83 | #endif |
| 84 | |
| 85 |
+24
-11
| --- src/winfile.c | ||
| +++ src/winfile.c | ||
| @@ -21,19 +21,33 @@ | ||
| 21 | 21 | #include "config.h" |
| 22 | 22 | #ifdef _WIN32 |
| 23 | 23 | /* This code is for win32 only */ |
| 24 | 24 | #include <sys/stat.h> |
| 25 | 25 | #include <windows.h> |
| 26 | -#include <versionhelpers.h> | |
| 27 | 26 | #include "winfile.h" |
| 27 | + | |
| 28 | +#if !defined(S_IFLNK) | |
| 29 | +# define S_IFLNK 0120000 | |
| 30 | +#endif | |
| 31 | +#if !defined(SYMBOLIC_LINK_FLAG_DIRECTORY) | |
| 32 | +# define SYMBOLIC_LINK_FLAG_DIRECTORY (0x1) | |
| 33 | +#endif | |
| 28 | 34 | |
| 29 | 35 | #ifndef LABEL_SECURITY_INFORMATION |
| 30 | 36 | # define LABEL_SECURITY_INFORMATION (0x00000010L) |
| 31 | 37 | #endif |
| 38 | + | |
| 39 | +#if defined(__MSVCRT__) | |
| 40 | +/* TODO: determine those dynamically. */ | |
| 41 | +WINBASEAPI DWORD WINAPI GetFinalPathNameByHandleW (HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); | |
| 42 | +WINBASEAPI BOOLEAN APIENTRY CreateSymbolicLinkW (LPCWSTR lpSymlinkFileName, LPCWSTR lpTargetFileName, DWORD dwFlags); | |
| 43 | +#endif | |
| 32 | 44 | |
| 33 | 45 | /* a couple defines to make the borrowed struct below compile */ |
| 34 | -#define _ANONYMOUS_UNION | |
| 46 | +#ifndef _ANONYMOUS_UNION | |
| 47 | +# define _ANONYMOUS_UNION | |
| 48 | +#endif | |
| 35 | 49 | #define DUMMYUNIONNAME |
| 36 | 50 | |
| 37 | 51 | /* |
| 38 | 52 | ** this structure copied on 20 Sept 2014 from |
| 39 | 53 | ** https://reactos-mirror.googlecode.com/svn-history/r54752/branches/usb-bringup/include/ddk/ntifs.h |
| @@ -250,26 +264,25 @@ | ||
| 250 | 264 | */ |
| 251 | 265 | int win32_symlink(const char *oldpath, const char *newpath){ |
| 252 | 266 | fossilStat stat; |
| 253 | 267 | int created = 0; |
| 254 | 268 | DWORD flags = 0; |
| 255 | - wchar_t *zMbcs; | |
| 269 | + wchar_t *zMbcs, *zMbcsOld; | |
| 256 | 270 | |
| 257 | 271 | /* does oldpath exist? is it a dir or a file? */ |
| 258 | - zMbcs = fossil_utf8_to_filename(oldpath); | |
| 259 | - if (win32_stat(zMbcs, &stat) == 0){ | |
| 272 | + zMbcsOld = fossil_utf8_to_filename(oldpath); | |
| 273 | + if (win32_stat(zMbcsOld, &stat) == 0){ | |
| 260 | 274 | if (stat.st_mode == S_IFDIR) |
| 261 | 275 | flags = SYMBOLIC_LINK_FLAG_DIRECTORY; |
| 262 | 276 | } |
| 263 | - fossil_filename_free(zMbcs); | |
| 264 | 277 | |
| 265 | 278 | /* remove newpath before creating the symlink */ |
| 266 | 279 | zMbcs = fossil_utf8_to_filename(newpath); |
| 267 | 280 | win32_unlink_rmdir(zMbcs); |
| 281 | + created = CreateSymbolicLinkW(zMbcs, zMbcsOld, flags); | |
| 268 | 282 | fossil_filename_free(zMbcs); |
| 269 | - | |
| 270 | - created = CreateSymbolicLink(newpath, oldpath, flags); | |
| 283 | + fossil_filename_free(zMbcsOld); | |
| 271 | 284 | |
| 272 | 285 | /* if the symlink was not created, create a plain text file */ |
| 273 | 286 | if (!created){ |
| 274 | 287 | Blob content; |
| 275 | 288 | blob_set(&content, oldpath); |
| @@ -324,13 +337,13 @@ | ||
| 324 | 337 | DWORD fullLength; |
| 325 | 338 | wchar_t volName[MAX_PATH+1]; |
| 326 | 339 | DWORD fsFlags; |
| 327 | 340 | |
| 328 | 341 | /* symlinks only supported on vista or greater */ |
| 329 | - if (!IsWindowsVistaOrGreater()) | |
| 330 | - return 0; | |
| 331 | - | |
| 342 | + /* if (!IsWindowsVistaOrGreater()) // TODO: make it work on MinGW | |
| 343 | + return 0; */ | |
| 344 | + | |
| 332 | 345 | /* next we need to check to see if the privilege is available */ |
| 333 | 346 | |
| 334 | 347 | /* can't check privilege if we can't lookup its value */ |
| 335 | 348 | if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid)) |
| 336 | 349 | return 0; |
| 337 | 350 |
| --- src/winfile.c | |
| +++ src/winfile.c | |
| @@ -21,19 +21,33 @@ | |
| 21 | #include "config.h" |
| 22 | #ifdef _WIN32 |
| 23 | /* This code is for win32 only */ |
| 24 | #include <sys/stat.h> |
| 25 | #include <windows.h> |
| 26 | #include <versionhelpers.h> |
| 27 | #include "winfile.h" |
| 28 | |
| 29 | #ifndef LABEL_SECURITY_INFORMATION |
| 30 | # define LABEL_SECURITY_INFORMATION (0x00000010L) |
| 31 | #endif |
| 32 | |
| 33 | /* a couple defines to make the borrowed struct below compile */ |
| 34 | #define _ANONYMOUS_UNION |
| 35 | #define DUMMYUNIONNAME |
| 36 | |
| 37 | /* |
| 38 | ** this structure copied on 20 Sept 2014 from |
| 39 | ** https://reactos-mirror.googlecode.com/svn-history/r54752/branches/usb-bringup/include/ddk/ntifs.h |
| @@ -250,26 +264,25 @@ | |
| 250 | */ |
| 251 | int win32_symlink(const char *oldpath, const char *newpath){ |
| 252 | fossilStat stat; |
| 253 | int created = 0; |
| 254 | DWORD flags = 0; |
| 255 | wchar_t *zMbcs; |
| 256 | |
| 257 | /* does oldpath exist? is it a dir or a file? */ |
| 258 | zMbcs = fossil_utf8_to_filename(oldpath); |
| 259 | if (win32_stat(zMbcs, &stat) == 0){ |
| 260 | if (stat.st_mode == S_IFDIR) |
| 261 | flags = SYMBOLIC_LINK_FLAG_DIRECTORY; |
| 262 | } |
| 263 | fossil_filename_free(zMbcs); |
| 264 | |
| 265 | /* remove newpath before creating the symlink */ |
| 266 | zMbcs = fossil_utf8_to_filename(newpath); |
| 267 | win32_unlink_rmdir(zMbcs); |
| 268 | fossil_filename_free(zMbcs); |
| 269 | |
| 270 | created = CreateSymbolicLink(newpath, oldpath, flags); |
| 271 | |
| 272 | /* if the symlink was not created, create a plain text file */ |
| 273 | if (!created){ |
| 274 | Blob content; |
| 275 | blob_set(&content, oldpath); |
| @@ -324,13 +337,13 @@ | |
| 324 | DWORD fullLength; |
| 325 | wchar_t volName[MAX_PATH+1]; |
| 326 | DWORD fsFlags; |
| 327 | |
| 328 | /* symlinks only supported on vista or greater */ |
| 329 | if (!IsWindowsVistaOrGreater()) |
| 330 | return 0; |
| 331 | |
| 332 | /* next we need to check to see if the privilege is available */ |
| 333 | |
| 334 | /* can't check privilege if we can't lookup its value */ |
| 335 | if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid)) |
| 336 | return 0; |
| 337 |
| --- src/winfile.c | |
| +++ src/winfile.c | |
| @@ -21,19 +21,33 @@ | |
| 21 | #include "config.h" |
| 22 | #ifdef _WIN32 |
| 23 | /* This code is for win32 only */ |
| 24 | #include <sys/stat.h> |
| 25 | #include <windows.h> |
| 26 | #include "winfile.h" |
| 27 | |
| 28 | #if !defined(S_IFLNK) |
| 29 | # define S_IFLNK 0120000 |
| 30 | #endif |
| 31 | #if !defined(SYMBOLIC_LINK_FLAG_DIRECTORY) |
| 32 | # define SYMBOLIC_LINK_FLAG_DIRECTORY (0x1) |
| 33 | #endif |
| 34 | |
| 35 | #ifndef LABEL_SECURITY_INFORMATION |
| 36 | # define LABEL_SECURITY_INFORMATION (0x00000010L) |
| 37 | #endif |
| 38 | |
| 39 | #if defined(__MSVCRT__) |
| 40 | /* TODO: determine those dynamically. */ |
| 41 | WINBASEAPI DWORD WINAPI GetFinalPathNameByHandleW (HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); |
| 42 | WINBASEAPI BOOLEAN APIENTRY CreateSymbolicLinkW (LPCWSTR lpSymlinkFileName, LPCWSTR lpTargetFileName, DWORD dwFlags); |
| 43 | #endif |
| 44 | |
| 45 | /* a couple defines to make the borrowed struct below compile */ |
| 46 | #ifndef _ANONYMOUS_UNION |
| 47 | # define _ANONYMOUS_UNION |
| 48 | #endif |
| 49 | #define DUMMYUNIONNAME |
| 50 | |
| 51 | /* |
| 52 | ** this structure copied on 20 Sept 2014 from |
| 53 | ** https://reactos-mirror.googlecode.com/svn-history/r54752/branches/usb-bringup/include/ddk/ntifs.h |
| @@ -250,26 +264,25 @@ | |
| 264 | */ |
| 265 | int win32_symlink(const char *oldpath, const char *newpath){ |
| 266 | fossilStat stat; |
| 267 | int created = 0; |
| 268 | DWORD flags = 0; |
| 269 | wchar_t *zMbcs, *zMbcsOld; |
| 270 | |
| 271 | /* does oldpath exist? is it a dir or a file? */ |
| 272 | zMbcsOld = fossil_utf8_to_filename(oldpath); |
| 273 | if (win32_stat(zMbcsOld, &stat) == 0){ |
| 274 | if (stat.st_mode == S_IFDIR) |
| 275 | flags = SYMBOLIC_LINK_FLAG_DIRECTORY; |
| 276 | } |
| 277 | |
| 278 | /* remove newpath before creating the symlink */ |
| 279 | zMbcs = fossil_utf8_to_filename(newpath); |
| 280 | win32_unlink_rmdir(zMbcs); |
| 281 | created = CreateSymbolicLinkW(zMbcs, zMbcsOld, flags); |
| 282 | fossil_filename_free(zMbcs); |
| 283 | fossil_filename_free(zMbcsOld); |
| 284 | |
| 285 | /* if the symlink was not created, create a plain text file */ |
| 286 | if (!created){ |
| 287 | Blob content; |
| 288 | blob_set(&content, oldpath); |
| @@ -324,13 +337,13 @@ | |
| 337 | DWORD fullLength; |
| 338 | wchar_t volName[MAX_PATH+1]; |
| 339 | DWORD fsFlags; |
| 340 | |
| 341 | /* symlinks only supported on vista or greater */ |
| 342 | /* if (!IsWindowsVistaOrGreater()) // TODO: make it work on MinGW |
| 343 | return 0; */ |
| 344 | |
| 345 | /* next we need to check to see if the privilege is available */ |
| 346 | |
| 347 | /* can't check privilege if we can't lookup its value */ |
| 348 | if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid)) |
| 349 | return 0; |
| 350 |