]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Fix issues with Windows compiling
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 30 Aug 2017 10:02:35 +0000 (06:02 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 30 Aug 2017 10:02:35 +0000 (06:02 -0400)
Sources/libMultiMarkdown/transclude.c
Sources/libMultiMarkdown/zip.c
Sources/multimarkdown/main.c

index d92da7179d4e72cf41aa141d42ad645f8f3a38bf..fa362faead6f613422c6c52bba3469bc801bb746 100644 (file)
@@ -268,7 +268,7 @@ DString * scan_file(const char * fname) {
        wchar_t wstr[wchars_num];
        MultiByteToWideChar(CP_UTF8, 0, fname, -1, wstr, wchars_num);
 
-       if ((file = _wfopen(wstr, L"r")) == NULL) {
+       if ((file = _wfopen(wstr, L"rb")) == NULL) {
        #else
 
        if ((file = fopen(fname, "r")) == NULL ) {
index 4ebb87f990dfab31fdf5e90448b64e13e25f8641..ccfa1ab1bcc6a1843239fcd5229b0f252b95f928 100644 (file)
 #include <unistd.h>
 
 
+// Windows deprecated mkdir()
+// Fix per internet searches and modified by @f8ttyc8t (<https://github.com/f8ttyc8t>)
+#if (defined(_WIN32) || defined(__WIN32__))
+       // Let compiler know where to find _mkdir()
+       #include  <direct.h>
+       #define mkdir(A, B) _mkdir(A)
+#endif
+
+
 // Create new zip archive
 void zip_new_archive(mz_zip_archive * pZip) {
        memset(pZip, 0, sizeof(mz_zip_archive));
index db1d96121104020bdcecf18678e6d439f1392e8e..29af4a3923f4698aefc408d9904858ec21b218a5 100644 (file)
@@ -143,6 +143,42 @@ char * filename_with_extension(const char * original, const char * new_extension
 }
 
 
+// Windows does not know realpath(), so we need a "windows port"
+// Fix by @f8ttyc8t (<https://github.com/f8ttyc8t>)
+#if (defined(_WIN32) || defined(__WIN32__))
+// Let compiler know where to find GetFullPathName()
+#include <windows.h>
+
+char *realpath(const char *path, char *resolved_path) {
+       DWORD  retval = 0;
+       DWORD  dwBufSize = 0; // Just in case MAX_PATH differs from PATH_MAX
+       TCHAR  *buffer = NULL;
+
+       if (resolved_path == NULL) {
+               // realpath allocates appropiate bytes if resolved_path is null. This is to mimic realpath behavior
+               dwBufSize = PATH_MAX; // Use windows PATH_MAX constant, because we are in Windows context now.
+               buffer = (char*)malloc(dwBufSize);
+
+               if (buffer == NULL) {
+                       return NULL; // some really weird is going on...
+               }
+       } else {
+               dwBufSize = MAX_PATH;  // buffer has been allocated using MAX_PATH earlier
+               buffer = resolved_path;
+       }
+
+       retval = GetFullPathName(path, dwBufSize, buffer, NULL);
+
+       if (retval == 0) {
+               return NULL;
+               printf("Failed to GetFullPathName()\n");
+       }
+
+       return buffer;
+}
+#endif
+
+
 int main(int argc, char** argv) {
        int exitcode = EXIT_SUCCESS;
        char * binname = "multimarkdown";