예제 #1
0
caddr_t _sbrk_r (struct _reent *r, int incr)
{
    extern char   end __asm ("end");    /* Defined by the linker.  */
    static char * heap_end;
    char        * prev_heap_end;
    extern char   _vStackTop;           /* Defined by the linker.  */
    char        * pStack;
     
    if (heap_end == NULL){
        heap_end = &end;
    }
    prev_heap_end = heap_end;
 
    pStack = ( stack_ptr > heap_end ) ? stack_ptr : &_vStackTop; 
     
    if (heap_end + incr > pStack)
    {
        /* Some of the libstdc++-v3 tests rely upon detecting
        out of memory errors, so do not abort here.  */
#if 0
        extern void abort (void);
        _write_r( r, 1, "_sbrk: Heap and stack collision\n", 32);
        while(1); /* Terminate here */
        /* abort (); */
#else
        errno = ENOMEM;
        return (caddr_t) -1;
#endif
    }
    heap_end += incr;
    return (caddr_t) prev_heap_end;
}
예제 #2
0
int
__swrite (void* cookie,char const *buf,int n)
{
  register FILE *fp = (FILE *) cookie;

  if (fp->_flags & __SAPP)
    (void) _lseek_r (fp->_data, fp->_file, (off_t) 0, SEEK_END);
  fp->_flags &= ~__SOFF;	/* in case O_APPEND mode is set */
  return _write_r (fp->_data, fp->_file, buf, n);
}
예제 #3
0
static int zero_pad(int handle )           /* 09-jan-95 */
/*******************************/
{
    int         rc;
    long        curPos, eodPos;
    long        bytesToWrite;
    unsigned    writeAmt;
    char        zeroBuf[PAD_SIZE];

    // Pad with zeros due to lseek() past EOF (POSIX)
    curPos = lseek( handle, 0L, SEEK_CUR );   /* current offset */
    if( curPos == -1 )
        return( -1 );
    eodPos = lseek( handle, 0L, SEEK_END );   /* end of data offset */
    if( eodPos == -1 )
        return( -1 );

    if( curPos > eodPos ) {
        bytesToWrite = curPos - eodPos;         /* amount to pad by */

        if( bytesToWrite > 0 ) {                /* only write if needed */
            memset( zeroBuf, 0x00, PAD_SIZE );  /* zero out a buffer */
            do {                                /* loop until done */
                if( bytesToWrite > PAD_SIZE )
                    writeAmt = 512;
                else
                    writeAmt = (unsigned)bytesToWrite;
                rc = _write_r(ptr, handle, zeroBuf, writeAmt );
                if( rc < 0 )
                    return( rc );
                bytesToWrite -= writeAmt;       /* more bytes written */
            } while( bytesToWrite != 0 );
        }
    } else {
        curPos = _lseek_r( ptr, handle, curPos, SEEK_SET );
        if( curPos == -1 ) {
            return( -1 );
        }
    }

    return( 0 );                /* return success code */
}
예제 #4
0
int devo_fputc(int c, FILE *stream) {
    long fd = (long)stream - 1;
    char ch = c;
    return (_write_r(NULL, fd, &ch, 1) == -1) ? -1 : c;
}
예제 #5
0
파일: stubs.c 프로젝트: CobooGuo/elua
_ssize_t write( int file, const void *ptr, size_t len )
{
    return _write_r( _REENT, file, ptr, len );
}