Esempio n. 1
0
_WCRTLINK CHAR_TYPE *__F_NAME(_fullpath,_wfullpath)
                ( CHAR_TYPE *buff, const CHAR_TYPE *path, size_t size )
/*********************************************************************/
{
    CHAR_TYPE *ptr = NULL;

    if( buff == NULL ) {
        size = _MAX_PATH;
        ptr = lib_malloc( size * CHARSIZE );
        if( ptr == NULL )
            __set_errno( ENOMEM );
        buff = ptr;
    }
    if( buff != NULL ) {
        buff[ 0 ] = NULLCHAR;
        if( path == NULL || path[ 0 ] == NULLCHAR ) {
            buff = __F_NAME(getcwd,_wgetcwd)( buff, size );
        } else {
            buff = __F_NAME(_sys_fullpath,_sys_wfullpath)( buff, path, size );
        }
        if( buff == NULL ) {
            if( ptr != NULL ) {
                lib_free( ptr );
            }
        }
    }
    return( buff );
}
Esempio n. 2
0
CHAR_TYPE *__F_NAME(strstr,wcsstr)( const CHAR_TYPE *str,
                                    const CHAR_TYPE *substr )
/***********************************************************/
{
    size_t              strLen;
    size_t              substrLen;
    int                 i, maxi;
    CHAR_TYPE           ch;

    substrLen = __F_NAME(strlen,wcslen)( substr );
    if( substrLen == 0 )
        return( (CHAR_TYPE*)str );

    strLen = __F_NAME(strlen,wcslen)( str );
    maxi = strLen - substrLen + 1;
    ch = substr[0];

    for( i = 0; i < maxi; i++ ) {
        if( str[i] == ch ) {
            if( !__F_NAME(strncmp,wcsncmp)( str + i, substr, substrLen ) ) {
                return( (CHAR_TYPE*)str + i );
            }
        }
    }
    return( NULL );
}
Esempio n. 3
0
_WCRTLINK void __F_NAME(_assert99,_wassert99)( char *expr, char *func, char *fn, int line_num )
{
    CHAR_TYPE   str[STR_SIZE];

#ifndef __WIDECHAR__
    int     after_num_returns = 1;

    if( __extra_return ) {
        after_num_returns++;
        __extra_return = 0;
    }
#endif

    /* Have to use snprintf() here. The error message can be arbitrarily long */
    __F_NAME(_snprintf,swprintf)( str, STR_SIZE, FMT_STRING, expr, func, fn, line_num );
#ifndef __WIDECHAR__
    if( __WD_Present ) {
        char    *buf;

        buf = alloca( strlen( str ) + sizeof( TITLE_STRING ) + 1 );
        strcpy( buf, TITLE_STRING );
        strcat( buf, ": " );
        strcat( buf, str );
        DebuggerBreakAfterReturnWithMessage( after_num_returns, buf );
    } else {
#endif
        __F_NAME(__rterr_msg,__wrterr_msg)( TITLE_STRING, str );
        abort();
#ifndef __WIDECHAR__
    }
#endif
}
Esempio n. 4
0
int __F_NAME(__setenv,__wsetenv)( const CHAR_TYPE *name, const CHAR_TYPE *newvalue, int overwrite )
{
#ifdef __NETWARE__
    name = name;
    newvalue = newvalue;
    overwrite = overwrite;
    return( -1 );
#else
    int     rc;

    if( name == NULL || *name == NULLCHAR ) {
        return( -1 );
    }
#ifdef __WIDECHAR__
    if( _RWD_wenviron == NULL ) {
        __create_wide_environment();
    }
#endif
    rc = __F_NAME(__findenv,__wfindenv)( name, ( newvalue == NULL ) );
    if( rc > 0 ) {
        rc = __F_NAME(addenv,waddenv)( rc - 1, name, newvalue );
    }
    return( rc );
#endif
}
Esempio n. 5
0
_WCRTLINK CHAR_TYPE *__F_NAME(getenv,_wgetenv)( const CHAR_TYPE *name )
{
  #ifdef __NETWARE__
    name = name;
  #else
    CHAR_TYPE       **envp;
    CHAR_TYPE       *p;
    int             len;

  #ifdef __WIDECHAR__
    if( _RWD_wenviron == NULL ) {
        __create_wide_environment();
    }
  #endif

    /*** Find the environment string ***/
    __ptr_check( name, 0 );
    envp = __F_NAME(_RWD_environ,_RWD_wenviron);
    if( (envp != NULL) && (name != NULL) ) {
        len = __F_NAME(strlen,wcslen)( name );
        for( ; p = *envp; ++envp ) {
            if( CMP_FUNC( p, name, len ) == 0 ) {
                if( p[len] == STRING( '=' ) ) {
                    return( &p[len+1] );
                }
            }
        }
    }
  #endif
    return( NULL );                 /* not found */
}
Esempio n. 6
0
_WCRTLINK CHAR_TYPE *__F_NAME(strstr,wcsstr)( const CHAR_TYPE *s1, const CHAR_TYPE *s2 )
{
    CHAR_TYPE       *end_of_s1;
    size_t          s1len, s2len;

    if( s2[0] == NULLCHAR ) {
        return( (CHAR_TYPE *)s1 );
    } else if( s2[1] == NULLCHAR ) {
        return( __F_NAME(strchr,wcschr)( s1, s2[0] ) );
    }
#ifdef __WIDECHAR__
    end_of_s1 = (CHAR_TYPE*)s1 + wcslen( s1 );
#else
    end_of_s1 = memchr( s1, NULLCHAR, ~0u );
#endif
    s2len = __F_NAME(strlen,wcslen)( s2 );
    for( ;; ) {
        s1len = end_of_s1 - s1;
        if( s1len < s2len )
            break;
#ifdef __WIDECHAR__
        s1 = wcschr( s1, *s2 );  /* find start of possible match */
#else
        s1 = memchr( s1, *s2, s1len );  /* find start of possible match */
#endif
        if( s1 == NULL )
            break;
        if( memeq( s1, s2, s2len ) )
            return( (CHAR_TYPE *)s1 );
        ++s1;
    }
    return( NULL );
}
Esempio n. 7
0
_WCRTLINK FILE *__F_NAME(freopen,_wfreopen)( const CHAR_TYPE *name,
                                const CHAR_TYPE *access_mode, FILE *fp )
{
    int             hdl;
    int             file_flags;
    int             extflags;

    _ValidFile( fp, 0 );

    /* validate access_mode */
    file_flags = __F_NAME(__open_flags,__wopen_flags)( access_mode, &extflags );
    if( file_flags == 0 ) {
        return( NULL );
    }

    hdl = fileno( fp );
    _AccessFileH( hdl );

#ifdef DEFAULT_WINDOWING
    if( _WindowsRemoveWindowedHandle != 0 ) {
        _WindowsRemoveWindowedHandle( hdl );
    }
#endif
    fp = close_file( fp );
    if( fp != NULL ) {
        fp->_flag &= _DYNAMIC;                      /* 24-jul-92 */
        fp = __F_NAME(__doopen,__wdoopen)( name, *access_mode,
                                           file_flags, extflags,
                                           0, fp );
    }
    _ReleaseFileH( hdl );
    return( fp );
}
Esempio n. 8
0
void __F_NAME(__WinMain,__wWinMain)( void )
{
#ifdef __SW_BR
    {
#ifdef _M_IX86
        REGISTRATION_RECORD rr;
        __NewExceptionFilter( &rr );
#endif
        __process_fini = __FiniRtns;
        __InitRtns( 255 );
    }
#else
    {
        REGISTRATION_RECORD     rr;
        thread_data             *tdata;
        __InitRtns( INIT_PRIORITY_THREAD );
        tdata = __alloca( __ThreadDataSize );
        memset( tdata, 0, __ThreadDataSize );
        // tdata->__allocated = 0;
        tdata->__data_size = __ThreadDataSize;
        __InitThreadData( tdata );
        __NTMainInit( &rr, tdata );
        /* allocate alternate stack for F77 */
        __ASTACKPTR = (char *)alloca( __ASTACKSIZ ) + __ASTACKSIZ;
    }
#endif
    __CommonInit();
    exit( __F_NAME(WinMain,wWinMain)(
              GetModuleHandle( NULL ),
              0,
              __F_NAME(_LpCmdLine,_LpwCmdLine),
              SW_SHOWDEFAULT ) );
}
Esempio n. 9
0
_WCRTLINK int __F_NAME(access,_waccess)( const CHAR_TYPE *path, int pmode )
{
    APIRET          rc;
    OS_UINT         attr;
#ifndef _M_I86
    FILESTATUS3     fs;
#endif
#ifdef __WIDECHAR__
    char            mbPath[MB_CUR_MAX * _MAX_PATH]; /* single-byte char */

    if( wcstombs( mbPath, path, sizeof( mbPath ) ) == -1 ) {
        mbPath[0] = '\0';
    }
#endif
#ifdef _M_I86
    rc = DosQFileMode( (PSZ)__F_NAME(path,mbPath), &attr, 0 );
#else
    rc = DosQueryPathInfo( (PSZ)__F_NAME(path,mbPath), FIL_STANDARD, &fs, sizeof( fs ) );
    attr = fs.attrFile;
#endif
    if( rc ) {
        return( __set_errno_dos( rc ) );
    }
    if( (pmode & ACCESS_WR) && (attr & _A_RDONLY) ) {
        return( __set_errno_dos( ERROR_ACCESS_DENIED ) );   /* invalid access mode */
    }
    return( 0 );
}
Esempio n. 10
0
void __F_NAME(__NTMain,__wNTMain)( void )
/***************************************/
{
#if defined(__SW_BR)
  #if defined(_M_IX86)
    REGISTRATION_RECORD rr;

    __NewExceptionFilter( &rr );
  #endif
    __process_fini = __FiniRtns;
    __InitRtns( 255 );
    __CommonInit();
    exit( __F_NAME(main( ___Argc, ___Argv ),wmain( ___wArgc, ___wArgv )) );
#else
    REGISTRATION_RECORD     rr;
    thread_data             *tdata;

    __InitRtns( INIT_PRIORITY_THREAD );
    tdata = __alloca( __ThreadDataSize );
    memset( tdata, 0, __ThreadDataSize );
    // tdata->__allocated = 0;
    tdata->__data_size = __ThreadDataSize;

    __InitThreadData( tdata );
    __NTMainInit( &rr, tdata );
    __F_NAME(__CMain,__wCMain)();
#endif
}
Esempio n. 11
0
_WCRTLINK int __F_NAME(chmod,_wchmod)( const CHAR_TYPE *pathname, int pmode )
/***************************************************************************/
{
#ifdef __WIDECHAR__
    char        mbPath[MB_CUR_MAX * _MAX_PATH];

    if( wcstombs( mbPath, pathname, sizeof( mbPath ) ) == -1 ) {
        mbPath[0] = '\0';
    }
    return( chmod( mbPath, pmode ) );
#else
    unsigned    attr;

    if( _dos_getfileattr( __F_NAME(pathname,mbPath), &attr ) ) {
        return( -1 );
    }
    attr &= ~_A_RDONLY;
    if( !( pmode & S_IWRITE ) ) {
        attr |= _A_RDONLY;
    }
    if( _dos_setfileattr( __F_NAME(pathname,mbPath), attr ) ) {
        return( -1 );
    }
    return( 0 );
#endif
}
Esempio n. 12
0
 DWORD __fixed_GetFileAttributesA( LPCSTR lpFileName )
#endif
/*****************************************************/
{
    HANDLE              handle;
    WIN32_FIND_DATA     finddata;

    if( WIN32_IS_NT4 ) {
        return( GetFileAttributes( lpFileName ) );
    }
    /*** Fail if the filename contains a wildcard ***/
    if( __F_NAME(strchr,wcschr)( lpFileName, STRING( '*' ) ) != NULL ||
        __F_NAME(strchr,wcschr)( lpFileName, STRING( '?' ) ) != NULL ) {
        return( INVALID_FILE_ATTRIBUTES );
    }

    /*** Ok, use FindFirstFile to get the file attribute ***/
    handle = __lib_FindFirstFile( lpFileName, &finddata );
    if( handle == INVALID_HANDLE_VALUE ) {
        return( INVALID_FILE_ATTRIBUTES );
    } else {
        FindClose( handle );
    }
    return( finddata.dwFileAttributes );
}
Esempio n. 13
0
_WCRTLINK long int __F_NAME(atol,_wtol)( const CHAR_TYPE *p )
{
    long int        value;
    bool            minus;

    __ptr_check( p, 0 );

    while( __F_NAME(isspace,iswspace)( (UCHAR_TYPE)*p ) )
        ++p;
    minus = false;
    switch( *p ) {
    case STRING( '-' ):
        minus = true;
        // fall down
    case STRING( '+' ):
        ++p;
        break;
    }
    value = 0;
    while( __F_NAME(isdigit,iswdigit)( (UCHAR_TYPE)*p ) ) {
        value = value * 10 + *p - STRING( '0' );
        ++p;
    }
    if( minus )
        value = - value;
    return( value );
}
Esempio n. 14
0
_WCRTLINK INTCHAR_TYPE __F_NAME(getchar,getwchar)( void )
{
#ifdef getc
    return( __F_NAME(getc,getwc)( stdin ) );
#else
    return( __F_NAME(fgetc,fgetwc)( stdin ) );
#endif
}
Esempio n. 15
0
static int cget_file( PTR_SCNF_SPECS specs )
{
    int     c;

    if( (c = __F_NAME(getc,getwc)( (FILE *)specs->ptr )) == __F_NAME(EOF,WEOF) ) {
        specs->eoinp = 1;
    }
    return( c );
}
Esempio n. 16
0
_WCRTLINK CHAR_TYPE *__F_NAME(strspnp,_wcsspnp)( const CHAR_TYPE *p1, const CHAR_TYPE *p2 )
{
    size_t              index;

    index = __F_NAME(strspn,wcsspn)( p1, p2 );
    if( *(p1+index) != __F_NAME('\0',L'\0') ) {
        return( (CHAR_TYPE*)(p1+index) );
    } else {
        return( NULL );
    }
}
Esempio n. 17
0
static int x_dospawn( int mode, CHAR_TYPE SPVE_NEAR *pgmname, CHAR_TYPE SPVE_NEAR *cmdline,
  #if defined( _M_I86 )
    unsigned env,
  #else
    CHAR_TYPE *env,
  #endif
    const CHAR_TYPE * const *argv ) {

    /* do this here instead of in the .asm files */
    __F_NAME(__ccmdline,__wccmdline)( pgmname, argv, cmdline, 0 );
    return( __F_NAME(_dospawn,_wdospawn)( mode, pgmname, cmdline, env, argv ) );
}
Esempio n. 18
0
_WCRTLINK int __F_NAME(spawnle,_wspawnle)( int mode, const CHAR_TYPE *path, const CHAR_TYPE *arg0, ... )
{
    va_list             ap;
    CHAR_TYPE           **env;
#if defined(__AXP__) || defined(__PPC__) || defined(__MIPS__)
    va_list             bp;
    const CHAR_TYPE     **a;
    const CHAR_TYPE     **tmp;
    int                 num = 1;
#endif

    arg0 = arg0;
    va_start( ap, path );
#if defined(__AXP__) || defined(__PPC__) || defined(__MIPS__)
    memcpy( &bp, &ap, sizeof( ap ) );
#endif

    /*
     * Scan until NULL in parm list
     */
    while( va_arg( ap, CHAR_TYPE * ) ) {
#if defined(__AXP__) || defined(__PPC__) || defined(__MIPS__)
        ++num;
#else
        ;
#endif
    }

    /*
     * Point to environment parameter.
     */
    env = va_arg( ap, CHAR_TYPE ** );

#if defined(__AXP__) || defined(__PPC__) || defined(__MIPS__)
    a = (const CHAR_TYPE **)alloca( num * sizeof( CHAR_TYPE * ) );
    if( !a ) {
        _RWD_errno = ENOMEM;
        return( -1 );
    }

    for( tmp = a; num > 0; --num )
        *tmp++ = (CHAR_TYPE *)va_arg( bp, CHAR_TYPE * );

    return( __F_NAME(spawnve,_wspawnve)( mode, path, a,
            (const CHAR_TYPE**)env ) );
#else
    va_end( ap );
    va_start( ap, path );
    return( __F_NAME(spawnve,_wspawnve)( mode, path,
            (const CHAR_TYPE**)ap[0], (const CHAR_TYPE **)env ) );
#endif
}
Esempio n. 19
0
_WCRTLINK FILE *__F_NAME(fdopen,_wfdopen)( int handle, const CHAR_TYPE *access_mode )
{
    unsigned        flags;
    FILE *          fp;
#if !defined(__NETWARE__)
    int             extflags;
#endif

    if( handle == -1 ) {
        __set_errno( EBADF );           /* 5-dec-90 */
        return( NULL );                 /* 19-apr-90 */
    }
    #ifdef __NETWARE__
        flags = __F_NAME(__open_flags,__wopen_flags)( access_mode );
    #else
        flags = __F_NAME(__open_flags,__wopen_flags)( access_mode,
                                                      &extflags );
    #endif
    if( flags == 0 ) return( NULL );

#if !defined(__NETWARE__)
    /* make sure the handle has the same text/binary mode */
    if( __iomode( handle, flags ) == -1 ) {
        return( NULL );
    }
#endif
    fp = __allocfp( handle );               /* JBS 30-aug-91 */
    if( fp ) {
        fp->_flag &= ~(_READ | _WRITE); /* 2-dec-90 */
        fp->_flag |= flags;
        fp->_cnt = 0;
        _FP_BASE(fp) = NULL;
        fp->_bufsize = 0;                   /* was BUFSIZ JBS 91/05/31 */
        #ifndef __NETWARE__
            _FP_ORIENTATION(fp) = _NOT_ORIENTED; /* initial orientation */
            _FP_EXTFLAGS(fp) = extflags;
        #endif
        #if defined(__NT__) || defined(__OS2__)
            _FP_PIPEDATA(fp).isPipe = 0;    /* not a pipe */
        #endif
        fp->_handle = handle;               /* BJS 91-07-23 */
        if( __F_NAME(tolower,towlower)( *access_mode ) == 'a' ) {
            fseek( fp, 0L, SEEK_END );
        }
        __chktty( fp );                     /* JBS 31-may-91 */
#if !defined(__UNIX__) && !defined(__NETWARE__)
        __SetIOMode( handle, flags );
#endif
    }
    return( fp );
}
Esempio n. 20
0
static int parse_words( const CHAR_TYPE *command, CHAR_TYPE **words )
/*******************************************************************/
{
    int                 numWords = 0;
    const CHAR_TYPE     *p = command;
    const CHAR_TYPE     *pLookAhead;
    int                 error = 0;
    size_t              len;

    while( *p != '\0' ) {
        /*** Skip any leading whitespace ***/
        while( __F_NAME(isspace,iswspace)(*p) ) {
            p++;
        }

        /*** Handle the word ***/
        if( *p == '\0' )  break;
        pLookAhead = p;
        while( *pLookAhead != '\0'  &&  !__F_NAME(isspace,iswspace)(*pLookAhead) ) {
            pLookAhead++;
        }
        if( words != NULL ) {
            len = pLookAhead - p;       /* # of chars, excluding the null */
            words[numWords] = lib_malloc( (len + 1) * sizeof( CHAR_TYPE ) );
            if( words[numWords] == NULL ) {     /* break on error */
                error = 1;
                break;
            }
            __F_NAME(strncpy,wcsncpy)( words[numWords], p, len );
            words[numWords][len] = '\0';
        }

        p = pLookAhead;
        numWords++;
    }

    /*** If an error occurred, free any memory we've allocated ***/
    if( error ) {
        for( numWords--; numWords>=0; numWords-- ) {
            lib_free( words[numWords] );
        }
        return( -1 );
    } else {
        if( words != NULL ) {
            words[numWords] = NULL;    /* last string */
        }
    }

    return( numWords );
}
Esempio n. 21
0
_WCRTLINK int __F_NAME(puts,putws)( const CHAR_TYPE *s )
{
    int             rc;

    rc = __F_NAME(fputs,fputws)( s, stdout );
    if( rc != EOF ) {
        if( __F_NAME(fputc,fputwc)( __F_NAME('\n',L'\n'), stdout ) == __F_NAME(EOF,WEOF) ) {
            rc = EOF;
        } else {
            rc++;
        }
    }
    return( rc );
}
Esempio n. 22
0
_WCRTLINK void __F_NAME(rewinddir,_wrewinddir)( DIR_TYPE *dirp )
/**************************************************************/
{
    if( dirp == NULL || dirp->d_openpath == NULL )
        return;
    __F_NAME(___opendir,___wopendir)( dirp->d_openpath, dirp );
}
Esempio n. 23
0
_WCRTLINK errno_t __F_NAME(ctime_s,_wctime_s)( CHAR_TYPE *s,
                           rsize_t maxsize, const time_t *timer )
/***************************************************************/
{
    errno_t     rc = -1;
    char        *msg = NULL;
    struct tm   tm;

    // Verify runtime-constraints
    // s     not NULL
    // timer not NULL
    // 26 <= maxsize <= RSIZE_MAX
    // localtime_s(...) not NULL
    if( __check_constraint_nullptr_msg( msg, s ) &&
        __check_constraint_nullptr_msg( msg, timer ) &&
        __check_constraint_maxsize_msg( msg, maxsize ) &&
        __check_constraint_a_gt_b_msg( msg, 26, maxsize ) &&
        __check_constraint_nullptr_msg( msg, localtime_s( timer, &tm ) ) ) {

        __F_NAME(_asctime,__wasctime)( &tm, s );
        rc = 0;
    }

    if( msg != NULL ) {
        // Runtime-constraint violated, store zero in receiving field if possible
        if( (s != NULL) && (maxsize > 0) && __lte_rsizmax( maxsize ) ) {
            *s = NULLCHAR;
        }
        // Now call the handler
        __rtct_fail( __func__, msg, NULL );
    }
    return( rc );
}
Esempio n. 24
0
   void __dos_finddata_cvt( struct find_t *findbuf, struct _finddata_t *fileinfo )
  #endif
 #endif
/******************************************************************************/
{
    /*** Handle attributes ***/
    fileinfo->attrib = findbuf->attrib;

    /*** Handle the timestamps ***/
  #ifdef __WATCOM_LFN__
    if( IS_LFN( findbuf ) && CRTIME_OF( findbuf ) ) {
        fileinfo->time_create = _d2ttime( CRDATE_OF( findbuf ), CRTIME_OF( findbuf ) );
        fileinfo->time_access = _d2ttime( ACDATE_OF( findbuf ), ACTIME_OF( findbuf ) );
    } else {
  #endif
        fileinfo->time_create = -1L;
        fileinfo->time_access = -1L;
  #ifdef __WATCOM_LFN__
    }
  #endif
    fileinfo->time_write = _d2ttime( findbuf->wr_date, findbuf->wr_time );
    /*** Handle the file size ***/
  #ifdef __INT64__
    U64Set( (unsigned_64 *)&fileinfo->size, findbuf->size, 0 );
  #else
    fileinfo->size = findbuf->size;
  #endif

    /*** Handle the file name ***/
    __F_NAME(strcpy,wcscpy)( fileinfo->name, findbuf->name );
}
Esempio n. 25
0
static int file_exists( const CHAR_TYPE *filename )                     /* 05-apr-91 */
{
    if( __F_NAME(access,_waccess)( filename, 0 ) == 0 )
        return( 1 );
    else
        return( 0 );
}
Esempio n. 26
0
_WCRTLINK int __F_NAME(sopen,_wsopen)( const CHAR_TYPE *name, int mode, int shflag, ... )
{
    va_list     args;

    va_start( args, shflag );
    return( __F_NAME(__sopen,__wsopen)( name, mode, shflag, args ) );
}
Esempio n. 27
0
_WCRTLINK errno_t __F_NAME(asctime_s,_wasctime_s)( CHAR_TYPE *s,
                            rsize_t maxsize, const struct tm *timeptr )
/*********************************************************************/
{
    errno_t     rc = -1;
    char        *msg = NULL;

    // Verify runtime-constraints
    // s       not NULL
    // timeptr not NULL
    // 26 <= maxsize      <= RSIZE_MAX
    // 0  <= timeptr.year <= 9999
    if( __check_constraint_nullptr_msg( msg, s ) &&
        __check_constraint_nullptr_msg( msg, timeptr ) &&
        __check_constraint_maxsize_msg( msg, maxsize ) &&
        __check_constraint_a_gt_b_msg( msg, 26, maxsize ) &&
        __check_constraint_a_gt_b_msg( msg, 0, timeptr->tm_year ) &&
        __check_constraint_a_gt_b_msg( msg, timeptr->tm_year, 9999  ) ) {

        // Parameters validated, now call 'normal' _asctime
        __F_NAME(_asctime,__wasctime)( timeptr, s );
        rc = 0;
    }

    if( msg != NULL ) {
        // Runtime-constraint violated, store zero in receiving field if possible
        if( (s != NULL) && (maxsize > 0) && __lte_rsizmax( maxsize ) ) {
            *s = NULLCHAR;
        }
        // Now call the handler
        __rtct_fail( __func__, msg, NULL );
    }

    return( rc );
}
Esempio n. 28
0
static unsigned long int _stol( const CHAR_TYPE *nptr,CHAR_TYPE **endptr,int base,int who)
    {
        const CHAR_TYPE *p;
        const CHAR_TYPE *startp;
        int digit;
        unsigned long int value;
        unsigned long int prev_value;
        CHAR_TYPE sign;
        char overflow;          /*overflow is used as a flag so it does not
                                 *need to be of type CHAR_TYPE */

        if( endptr != NULL ) *endptr = (CHAR_TYPE *)nptr;
        p = nptr;
        while( __F_NAME(isspace,iswspace)(*p) ) ++p;
        sign = *p;
        if( sign == '+'  ||  sign == '-' ) ++p;
        if( base == 0 ) {
            if( hexstr(p) )      base = 16;
            else if( *p == '0' ) base = 8;
            else                 base = 10;
        }
        if( base < 2  ||  base > 36 ) {
            __set_errno( EDOM );
            return( 0 );
        }
        if( base == 16 ) {
            if( hexstr(p) )  p += 2;    /* skip over '0x' */
        }
        startp = p;
        overflow = 0;
        value = 0;
        for(;;) {
            digit = radix_value( *p );
            if( digit >= base ) break;
            if( value > nearly_overflowing[base-2] ) overflow = 1;
            prev_value = value;
            value = value * base + digit;
            if( value < prev_value ) overflow = 1;
            ++p;
        }
        if( p == startp )  p = nptr;
        if( endptr != NULL ) *endptr = (CHAR_TYPE *)p;
        if( who == 1 ) {
            if( value >= 0x80000000 ) {
                if( value == 0x80000000  &&  sign == '-' ) {
                    ;  /* OK */
                } else {
                    overflow = 1;
                }
            }
        }
        if( overflow ) {
            __set_errno( ERANGE );
            if( who == 0 )     return( ULONG_MAX );
            if( sign == '-' )  return( LONG_MIN );
            return( LONG_MAX );
        }
        if( sign == '-' )  value = - value;
        return( value );
    }
Esempio n. 29
0
_WCRTLINK int __F_NAME(vsnprintf,vsnwprintf)( CHAR_TYPE *s, size_t bufsize,
                                              const CHAR_TYPE *format, va_list arg )
{
    int                 len;
    struct buf_limit    bufinfo;

    bufinfo.bufptr  = s;
    bufinfo.bufsize = bufsize - 1;
    if( bufsize == 0 )
        len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, buf_count_putc );
    else {
        len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, buf_putc );
        s[(( len >= 0 ) && ( len < bufsize )) ? len : bufsize - 1] = '\0';
    }
    return( len );
}
Esempio n. 30
0
 _WCRTLINK int __F_NAME(_stati64,_wstati64)( CHAR_TYPE const *path, struct _stati64 *buf )
{
    struct _stat        buf32;
    int                 rc;
    INT_TYPE            tmp;

    /*** Get the info using non-64bit version ***/
    rc = __F_NAME(stat,_wstat)( path, &buf32 );
    if( rc != -1 ) {
        /*** Convert the info to 64-bit equivalent ***/
        buf->st_dev = buf32.st_dev;
        buf->st_ino = buf32.st_ino;
        buf->st_mode = buf32.st_mode;
        buf->st_nlink = buf32.st_nlink;
        buf->st_uid = buf32.st_uid;
        buf->st_gid = buf32.st_gid;
        buf->st_rdev = buf32.st_rdev;
        _clib_U32ToU64( buf32.st_size, tmp );
        buf->st_size = GET_REALINT64(tmp);
        buf->st_atime = buf32.st_atime;
        buf->st_mtime = buf32.st_mtime;
        buf->st_ctime = buf32.st_ctime;
        buf->st_btime = buf32.st_btime;
        buf->st_attr = buf32.st_attr;
        buf->st_archivedID = buf32.st_archivedID;
        buf->st_updatedID = buf32.st_updatedID;
        buf->st_inheritedRightsMask = buf32.st_inheritedRightsMask;
        buf->st_originatingNameSpace = buf32.st_originatingNameSpace;
    }
    return( rc );
}