X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_platform.h;h=c7e178b93df5dbb8a891e52e30d09da31bc8c843;hb=8340e9c7406c7292f85266f9f30f4b5ff246dcd3;hp=319f7a9abd1892e2fb4b8d03860484aa4c5725a0;hpb=76f30a0f4aef82c10b4affbeab3f0271936ce7ca;p=vg.git diff --git a/vg_platform.h b/vg_platform.h index 319f7a9..c7e178b 100644 --- a/vg_platform.h +++ b/vg_platform.h @@ -1,6 +1,12 @@ #ifndef VG_PLATFORM_H #define VG_PLATFORM_H +#ifdef VG_RELEASE + #define VG_STATIC static +#else + #define VG_STATIC +#endif + //#include "vg.h" #include "vg_stdint.h" @@ -29,23 +35,74 @@ struct vg_achievement const char *name; }; -#ifndef VG_STATIC -#define VG_STATIC static -#endif - #define vg_static_assert _Static_assert #define vg_list_size( A ) (sizeof(A)/sizeof(A[0])) #define VG_MUST_USE_RESULT __attribute__((warn_unused_result)) -VG_STATIC void vg_strncpy( const char *src, char *dst, u32 len ) +enum strncpy_behaviour{ + k_strncpy_always_add_null = 0, + k_strncpy_allow_cutoff = 1 +}; + +VG_STATIC u32 vg_strncpy( const char *src, char *dst, u32 len, + enum strncpy_behaviour behaviour ) { - for( u32 i=0; ibuffer = buffer; + str->i = 0; + str->len = len; +} + +VG_STATIC void vg_strcat( vg_str *str, const char *append ) +{ + for( u32 i=0; str->i < str->len; i++, str->i ++ ){ + str->buffer[ str->i ] = append[i]; + + if( append[i] == '\0' ) return; + } +} + +VG_STATIC int vg_strgood( vg_str *str ) +{ + if( str->i == str->len ){ + if( str->buffer[str->i -1] == '\0' ) return 1; + else return 0; + } + else{ + str->buffer[ str->i ++ ] = '\0'; + return 1; + } +} + +VG_STATIC u32 vg_strdjb2( const char *str ) +{ + u32 hash = 5381, c; + + while( (c = *str++) ) + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + + return hash; } #include @@ -58,5 +115,4 @@ VG_STATIC void vg_strncpy( const char *src, char *dst, u32 len ) #define VG_MIN( A, B ) ((A)<(B)?(A):(B)) #define VG_MAX( A, B ) ((A)>(B)?(A):(B)) - #endif