gonzui


Format: Advanced Search

tkernel_2/lib/libtk/src/chkspc2.cbare sourcepermlink (0.02 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:  *      @(#)chkspc2.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 (TC string)
   31:  *      Checks to see that the memory area from str through to
   32:  *      either TNULL or the max character is valid.
   33:  *      If max = 0, the number of characters (max) is ignored.
   34:  *      If the memory area is valid, the value returned is either
   35:  *      the number of characters or the max value (through to the
   36:  *      max character with max !=0 character and no TNULL).
   37:  *      If the memory area is not valid, the error code is returned.
   38:  */
   39: EXPORT INT ChkSpaceTstrR( CONST TC *str, INT max )
   40: {
   41:         return ChkSpaceTstr(str, max, MA_READ, getsvcenv());
   42: }
   43: EXPORT INT ChkSpaceTstrRW( CONST TC *str, INT max )
   44: {
   45:         return ChkSpaceTstr(str, max, MA_READ|MA_WRITE, getsvcenv());
   46: }
   47: 
   48: #else /* VIRTUAL_ADDRESS */
   49: 
   50: LOCAL INT chklen( CONST TC *p, INT max )
   51: {
   52:         INT    len = 0;
   53: 
   54:         while ( *p++ != TNULL ) {
   55:                 len++;
   56:                 if ( --max == 0 ) {
   57:                         break;
   58:                 }
   59:         }
   60:         return len;
   61: }
   62: 
   63: EXPORT INT ChkSpaceTstrR( CONST TC *str, INT max )
   64: {
   65:         return chklen(str, max);
   66: }
   67: EXPORT INT ChkSpaceTstrRW( CONST TC *str, INT max )
   68: {
   69:         return chklen(str, max);
   70: }
   71: 
   72: #endif /* VIRTUAL_ADDRESS */