jsagevid avatar jsagevid committed 7f89623

Added Visual Studio support.

Comments (0)

Files changed (5)

 		return (const void*)((const char *)p + bytes);
 	}
 
-	inline template<class T> T *memory::pointer_add(T *p, uint32_t bytes)
-	{
-		return (T*)((char *)p + bytes);
-	}
-
-	inline template<class T> const T *memory::pointer_add(const T *p, uint32_t bytes)
-	{
-		return (const T*)((char *)p + bytes);
-	}
-
 	/// Returns the result of moving p back by the specified number of bytes
 	inline void *memory::pointer_sub(void *p, uint32_t bytes)
 	{
+#pragma once
+
+#if defined(_MSC_VER)
+	#include <stdarg.h>
+	#include <stdio.h>
+
+	inline int vsnprintf_compat(char* buffer, size_t size, const char* format, va_list args)
+	{
+		int result = -1;
+		if (size > 0)
+			result = _vsnprintf_s(buffer, size, _TRUNCATE, format, args);
+		if (result == -1)
+			return _vscprintf(format, args);
+	
+		return result;	
+	}
+
+	inline int snprintf_compat(char* buffer, size_t size, const char* format, ...)
+	{
+		va_list args;
+		va_start(args, format);
+		int result = vsnprintf_compat(buffer, size, format, args);
+		va_end(args);
+		return result;
+	}
+
+	#define snprintf snprintf_compat
+	#define vsnprintf vsnprintf_compat
+#endif
 #include <string.h>
 #include <stdio.h>
 
+#include "snprintf_msvc.h"
+
 namespace foundation
 {
 	/// Functions for operating on an Array<char> as a stream of characters,
 
 #include <stdint.h>
 
-#ifndef alignof
+#if defined(_MSC_VER)
+	#define _ALLOW_KEYWORD_MACROS
+#endif
+	
+#if !defined(alignof)
 	#define alignof(x) __alignof(x)
-#endif
+#endif
 
 	void test_pointer_arithmetic()
 	{
-		const char check = 0xfe;
+		const char check = (char)0xfe;
 		const unsigned test_size = 128;
 
 		TempAllocator512 ta;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.