7 /* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
9 typedef unsigned int uint
;
24 typedef struct vg_tex2d vg_tex2d
;
32 #define vg_static_assert _Static_assert
33 #define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))
34 #define VG_MUST_USE_RESULT __attribute__((warn_unused_result))
49 #include "vg_string.h"
51 enum strncpy_behaviour
{
52 k_strncpy_always_add_null
= 0,
53 k_strncpy_allow_cutoff
= 1,
54 k_strncpy_overflow_fatal
= 2
57 static void vg_fatal_error( const char *fmt
, ... );
58 static u32
vg_strncpy( const char *src
, char *dst
, u32 len
,
59 enum strncpy_behaviour behaviour
)
61 for( u32 i
=0; i
<len
; i
++ ){
64 if( !src
[i
] ) return i
;
67 if( behaviour
== k_strncpy_always_add_null
){
71 else if( behaviour
== k_strncpy_overflow_fatal
){
72 vg_fatal_error( "Strncpy dest exceeded buffer length\n" );
80 static u32
vg_strdjb2( const char *str
){
84 hash
= ((hash
<< 5) + hash
) + c
; /* hash * 33 + c */
89 static int vg_strdjb2_eq( const char *s1
, u32 h1
,
90 const char *s2
, u32 h2
)
93 if(!strcmp(s1
, s2
)) return 1;
98 #define VG_STRDJB2_EQ( CS1, S2, H2 ) \
99 vg_strdjb2_eq( CS1, vg_strdjb2(CS1), S2, H2 )
102 #define VG_MIN( A, B ) ((A)<(B)?(A):(B))
103 #define VG_MAX( A, B ) ((A)>(B)?(A):(B))