X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Flib.c;h=c1e2807ec23164a73f566c40506f04aa238a782c;hb=92e1384ea0be30ae9ab82af6864da2806286e864;hp=73b6432e00b616f56f44ce84148fbd1ef7e921b3;hpb=1081538c9f2903bec7ad003ab29fadd06bddc7b8;p=tpg%2Facess2.git diff --git a/Kernel/lib.c b/Kernel/lib.c index 73b6432e..c1e2807e 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -3,6 +3,7 @@ * Common Library Functions */ #include +#include // === CONSTANTS === #define RANDOM_SEED 0xACE55052 @@ -489,11 +490,11 @@ char *strcpy(char *__str1, const char *__str2) * \brief Copy a string to a new location * \note Copies at most `max` chars */ -char *strncpy(char *__str1, const char *__str2, size_t max) +char *strncpy(char *__str1, const char *__str2, size_t __max) { - while(*__str2 && max-- >= 1) + while(*__str2 && __max-- >= 1) *__str1++ = *__str2++; - if(max) + if(__max) *__str1 = '\0'; // Terminate String return __str1; } @@ -821,35 +822,29 @@ int rand(void) */ int CheckString(const char *String) { - if( !MM_GetPhysAddr( (tVAddr)String ) ) + tVAddr addr; + int bUser; + + addr = (tVAddr)String; + + if( !MM_GetPhysAddr( addr ) ) return 0; // Check 1st page - if( MM_IsUser( (tVAddr)String ) ) + bUser = MM_IsUser( addr ); + + while( *(char*)addr ) { - // Traverse String - while( *String ) + if( (addr & (PAGE_SIZE-1)) == 0 ) { - if( !MM_IsUser( (tVAddr)String ) ) + if(bUser && !MM_IsUser(addr) ) return 0; - // Increment string pointer - String ++; - } - return 1; - } - else if( MM_GetPhysAddr( (tVAddr)String ) ) - { - // Traverse String - while( *String ) - { - if( !MM_GetPhysAddr( (tVAddr)String ) ) + if(!bUser && !MM_GetPhysAddr(addr) ) return 0; - // Increment string pointer - String ++; } - return 1; + addr ++; } - return 0; + return 1; } /** @@ -858,32 +853,7 @@ int CheckString(const char *String) */ int CheckMem(const void *Mem, int NumBytes) { - tVAddr addr = (tVAddr)Mem; - - if( !MM_GetPhysAddr( addr ) ) - return 0; - - if( MM_IsUser( addr ) ) - { - while( NumBytes-- ) - { - if( !MM_IsUser( addr ) ) - return 0; - addr ++; - } - return 1; - } - else if( MM_GetPhysAddr( addr ) ) - { - while( NumBytes-- ) - { - if( !MM_GetPhysAddr( addr ) ) - return 0; - addr ++; - } - return 1; - } - return 0; + return MM_IsValidBuffer( (tVAddr)Mem, NumBytes ); } /* * * \}