memory semantics
[vg.git] / vg_platform.h
index c7e178b93df5dbb8a891e52e30d09da31bc8c843..98baef896a60196c0a85521e9f6ea3386120bf99 100644 (file)
@@ -41,9 +41,11 @@ struct vg_achievement
 
 enum strncpy_behaviour{
    k_strncpy_always_add_null = 0,
-   k_strncpy_allow_cutoff = 1
+   k_strncpy_allow_cutoff = 1,
+   k_strncpy_overflow_fatal = 2
 };
 
+VG_STATIC void vg_fatal_error( const char *fmt, ... );
 VG_STATIC u32 vg_strncpy( const char *src, char *dst, u32 len,
                           enum strncpy_behaviour behaviour )
 {
@@ -52,9 +54,14 @@ VG_STATIC u32 vg_strncpy( const char *src, char *dst, u32 len,
 
       if( !src[i] ) return i;
 
-      if( (behaviour == k_strncpy_always_add_null) && (i == len-1) ){
-         dst[i] = '\0';
-         return i;
+      if( i == len-1 ){
+         if( behaviour == k_strncpy_always_add_null ){
+            dst[i] = '\0';
+            return i;
+         }
+         else if( behaviour == k_strncpy_overflow_fatal ){
+            vg_fatal_error( "Strncpy dest exceeded buffer length\n" );
+         }
       }
    }