+static void vg_fatal_exit_loop( const char *error );
+static void *vg_alloc( size_t size )
+{
+ void *ptr = malloc( size );
+
+ if( !ptr )
+ vg_fatal_exit_loop( "Out of memory" );
+
+ return ptr;
+}
+
+static void *vg_realloc( void *orig, size_t size )
+{
+ void *ptr = realloc( orig, size );
+
+ if( !ptr )
+ vg_fatal_exit_loop( "Out of memory" );
+
+ return ptr;
+}
+
+/* seems to be a GCC bug when inlining this, its low priority anyway */
+__attribute__ ((noinline))
+static void vg_free( void *ptr )
+{
+ free( ptr );
+}
+
+static void vg_required( void *ptr, const char *path )
+{
+ if( !ptr )
+ {
+ vg_fatal_exit_loop( path );
+ }
+}
+
+#define VG_REQUIRED_ASSET( TYPE, DECL, FN, PATH, ... ) \
+ TYPE DECL = FN( PATH,##__VA_ARGS__ ); \
+ vg_required( DECL, "Resource is required but failed to load: '" PATH "'" );
+
+VG_DEPRECATED
+void *malloc( size_t size );
+
+VG_DEPRECATED
+void *realloc( void *orig, size_t size );
+
+VG_DEPRECATED
+void free( void *ptr );
+
+#include <stdio.h>
+#include <dirent.h>
+#include <string.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <math.h>
+#include <assert.h>
+
+static int vg_thread_run( void *pfunc, void *data );
+static void vg_thread_exit(void);
+static void vg_set_thread_name( const char *name );
+static int vg_semaphore_init( vg_semaphore *sem, u32 value );
+static int vg_semaphore_trywait( vg_semaphore *sem );
+static int vg_semaphore_wait( vg_semaphore *sem );
+static int vg_semaphore_post( vg_semaphore *sem );
+static void vg_semaphore_free( vg_semaphore *sem );
+static int vg_mutex_init( vg_mutex *mutex );
+static int vg_mutex_lock( vg_mutex *mutex );
+static int vg_mutex_unlock( vg_mutex *mutex );
+static void vg_mutex_free( vg_mutex *mutex );
+static void vg_sleep_ms( long msec );
+static double vg_time_diff( vg_timespec start, vg_timespec end );
+
+#ifdef _WIN32_NO
+
+static int vg_thread_run( void *pfunc, void *data )