Example #1
0
libfile LibOpen( char *name, bool write_to )
{
    FILE    *io;
    libfile lio;

    if( write_to ) {
        io = fopen( name, "wb" );
    } else {
        io = fopen( name, "rb" );
    }
    if( io == NULL ) {
        FatalError( ERR_CANT_OPEN, name, strerror( errno ) );
    }
    if( write_to ) {
        lio = MemAllocGlobal( sizeof( *lio ) + WRITE_FILE_BUFFER_SIZE - 1);
    } else {
        lio = MemAllocGlobal( sizeof( *lio ) + READ_FILE_BUFFER_SIZE - 1);
    }
    lio->next = fileList;
    lio->prev = NULL;
    if( fileList ) {
        fileList->prev = lio;
    }
    fileList = lio;
    lio->write_to = write_to;
    lio->io = io;
    lio->name = DupStrGlobal( name );
    lio->buf_size = 0;
    lio->buf_pos = 0;
    fseek( io, 0, SEEK_END );
    lio->endpos = ftell( io );
    fseek( io, 0, SEEK_SET );
    return( lio );
}
Example #2
0
static void *ObjAlloc( size_t size )
/**********************************/
{
    if( size == 0 )
        size = 1;
    return( MemAllocGlobal( size ) );
}
Example #3
0
char *DupStrGlobal( char *str )
/*****************************/
{
    char *ptr;

    ptr = MemAllocGlobal( strlen( str ) +1 );
    strcpy( ptr, str );
    return( ptr );
}
Example #4
0
File: libio.c Project: JWasm/JWlink
libfile LibOpen( char *name, int access )
{
    int io;
    libfile lio;
    if( access & O_CREAT ) {
        io = open( name, access, S_IRUSR | S_IRGRP | S_IROTH |
                                 S_IWUSR | S_IWGRP | S_IWOTH );
    } else {
        io = open( name, access );
    }


    if( io == -1 && errno == EMFILE ) {
        CloseOneInputLib();
        if( access & O_CREAT ) {
            io = open( name, access, S_IRUSR | S_IRGRP | S_IROTH | 
                                     S_IWUSR | S_IWGRP | S_IWOTH );
        } else {
            io = open( name, access );
        }
    }
    if( io == -1 ) {
        FatalError( ERR_CANT_OPEN, name, strerror( errno ) );
    }
    if( access & O_WRONLY ) {
        lio = MemAllocGlobal( sizeof( *lio ) + WRITE_FILE_BUFFER_SIZE - 1);
    } else {
        lio = MemAllocGlobal( sizeof( *lio ) + READ_FILE_BUFFER_SIZE - 1);
    }
    lio->next = fileList;
    lio->prev = NULL;
    if( fileList ) {
        fileList->prev = lio;
    }
    fileList = lio;
    lio->access = access;
    lio->io = io;
    lio->name = DupStrGlobal( name );
    lio->buf_size = 0;
    lio->buf_pos = 0;
    return( lio );
}