cmark

My personal build of CMark ✏️

Commit
9dd842c540146839688bca33bfd386b925efff2c
Parent
4be7a417b4ea18f36e294a547c304a454a53a98f
Author
John MacFarlane <jgm@berkeley.edu>
Date

Merge pull request #45 from nwellnhof/windows_snprintf

Cope with broken snprintf on Windows

Diffstat

3 files changed, 14 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified src/CMakeLists.txt 8 6 2
Modified src/buffer.c 6 6 0
Modified src/config.h.in 2 2 0
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -128,6 +128,7 @@ install(FILES
 # Feature tests
 include(CheckIncludeFile)
 include(CheckCSourceCompiles)
+include(CheckCSourceRuns)
 include(CheckSymbolExists)
 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
 CHECK_C_SOURCE_COMPILES(
@@ -137,6 +138,10 @@ CHECK_C_SOURCE_COMPILES("
   int f(void) __attribute__ (());
   int main() { return 0; }
 " HAVE___ATTRIBUTE__)
+CHECK_C_SOURCE_RUNS("
+  #include <stdio.h>
+  int main() { return snprintf(NULL, 0, \"123\") == 3 ? 0 : 1; }
+" HAVE_C99_SNPRINTF)
 CHECK_SYMBOL_EXISTS(va_copy stdarg.h HAVE_VA_COPY)
 
 CONFIGURE_FILE(
@@ -167,4 +172,4 @@ endif($ENV{TIMER})
 
 if(CMAKE_BUILD_TYPE STREQUAL "Ubsan")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
-endif()-
\ No newline at end of file
+endif()
diff --git a/src/buffer.c b/src/buffer.c
@@ -175,6 +175,12 @@ int cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap)
 		          buf->asize - buf->size,
 		          format, args
 		      );
+#ifndef HAVE_C99_SNPRINTF
+		// Assume we're on Windows.
+		if (len < 0) {
+			len = _vscprintf(format, args);
+		}
+#endif
 
 		va_end(args);
 
diff --git a/src/config.h.in b/src/config.h.in
@@ -21,3 +21,5 @@
 #ifndef HAVE_VA_COPY
   #define va_copy(dest, src) ((dest) = (src))
 #endif
+
+#cmakedefine HAVE_C99_SNPRINTF