gonzui


Format: Advanced Search

tkernel_2/lib/libtk/src/chkspc3.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: 
   15: /*
   16:  *      @(#)chkspc3.c (libtk)
   17:  *
   18:  *      Address check
   19:  */
   20: 
   21: #include <basic.h>
   22: #include <tk/syslib.h>
   23: #include <sys/segment.h>
   24: 
   25: #if VIRTUAL_ADDRESS
   26: 
   27: #include "getsvcenv.h"
   28: 
   29: /*
   30:  * Check address space (B string)
   31:  *      Checks to see that the memory area from str through to either
   32:  *      '\0' or the max byte is valid.
   33:  *      If max = 0, the number of bytes (max) is ignored.
   34:  *      If the memory area is valid, the value returned is either the
   35:  *      number of bytes or the max value (through to the max byte with
   36:  *      max !=0 and no '\0').
   37:  *      If the memory area is not valid, the error code is returned.
   38:  */
   39: EXPORT INT ChkSpaceBstrR( CONST UB *str, INT max )
   40: {
   41:         return ChkSpaceBstr(str, max, MA_READ, getsvcenv());
   42: }
   43: EXPORT INT ChkSpaceBstrRW( CONST UB *str, INT max )
   44: {
   45:         return ChkSpaceBstr(str, max, MA_READ|MA_WRITE, getsvcenv());
   46: }
   47: 
   48: #else /* VIRTUAL_ADDRESS */
   49: 
   50: LOCAL INT chklen( CONST UB *p, INT max )
   51: {
   52:         INT    len = 0;
   53: 
   54:         while ( *p++ != '\0' ) {
   55:                 len++;
   56:                 if ( --max == 0 ) {
   57:                         break;
   58:                 }
   59:         }
   60:         return len;
   61: }
   62: 
   63: EXPORT INT ChkSpaceBstrR( CONST UB *str, INT max )
   64: {
   65:         return chklen(str, max);
   66: }
   67: EXPORT INT ChkSpaceBstrRW( CONST UB *str, INT max )
   68: {
   69:         return chklen(str, max);
   70: }
   71: 
   72: #endif /* VIRTUAL_ADDRESS */