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+.

jan.nijtmans 2014-09-26 09:23 winsymlink
Commit 631dff61e0e8e1875c3f5a5a78bf5d946473c217
2 files changed +3 +24 -11
+3
--- src/file.c
+++ src/file.c
@@ -72,10 +72,13 @@
7272
*/
7373
/* the S_ISLNK provided by dirent.h for windows is inadequate, so fix it */
7474
#if defined(S_ISLNK)
7575
# undef S_ISLNK
7676
#endif
77
+#if !defined(S_IFLNK)
78
+# define S_IFLNK 0120000
79
+#endif
7780
#if !defined(S_ISLNK)
7881
# define S_ISLNK(x) ((x)==S_IFLNK)
7982
#endif
8083
#endif
8184
8285
--- 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 @@
2121
#include "config.h"
2222
#ifdef _WIN32
2323
/* This code is for win32 only */
2424
#include <sys/stat.h>
2525
#include <windows.h>
26
-#include <versionhelpers.h>
2726
#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
2834
2935
#ifndef LABEL_SECURITY_INFORMATION
3036
# define LABEL_SECURITY_INFORMATION (0x00000010L)
3137
#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
3244
3345
/* a couple defines to make the borrowed struct below compile */
34
-#define _ANONYMOUS_UNION
46
+#ifndef _ANONYMOUS_UNION
47
+# define _ANONYMOUS_UNION
48
+#endif
3549
#define DUMMYUNIONNAME
3650
3751
/*
3852
** this structure copied on 20 Sept 2014 from
3953
** https://reactos-mirror.googlecode.com/svn-history/r54752/branches/usb-bringup/include/ddk/ntifs.h
@@ -250,26 +264,25 @@
250264
*/
251265
int win32_symlink(const char *oldpath, const char *newpath){
252266
fossilStat stat;
253267
int created = 0;
254268
DWORD flags = 0;
255
- wchar_t *zMbcs;
269
+ wchar_t *zMbcs, *zMbcsOld;
256270
257271
/* 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){
260274
if (stat.st_mode == S_IFDIR)
261275
flags = SYMBOLIC_LINK_FLAG_DIRECTORY;
262276
}
263
- fossil_filename_free(zMbcs);
264277
265278
/* remove newpath before creating the symlink */
266279
zMbcs = fossil_utf8_to_filename(newpath);
267280
win32_unlink_rmdir(zMbcs);
281
+ created = CreateSymbolicLinkW(zMbcs, zMbcsOld, flags);
268282
fossil_filename_free(zMbcs);
269
-
270
- created = CreateSymbolicLink(newpath, oldpath, flags);
283
+ fossil_filename_free(zMbcsOld);
271284
272285
/* if the symlink was not created, create a plain text file */
273286
if (!created){
274287
Blob content;
275288
blob_set(&content, oldpath);
@@ -324,13 +337,13 @@
324337
DWORD fullLength;
325338
wchar_t volName[MAX_PATH+1];
326339
DWORD fsFlags;
327340
328341
/* 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
+
332345
/* next we need to check to see if the privilege is available */
333346
334347
/* can't check privilege if we can't lookup its value */
335348
if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid))
336349
return 0;
337350
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button