Esempio n. 1
0
extern ResNameOrOrdinal * WResHelpIDToNameOrOrd( WResHelpID * id )
/********************************************************/
{
    ResNameOrOrdinal *  newname;

    if (id->IsName) {
        /* the one char in the ResNameOrOrdinal gives room for the '\0' */
        newname = WRESALLOC( sizeof(ResNameOrOrdinal) + id->ID.Name.NumChars );
        if (newname == NULL) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            memcpy( newname->name, id->ID.Name.Name, id->ID.Name.NumChars );
            newname->name[ id->ID.Name.NumChars ] = '\0';
        }
    } else {
        newname = WRESALLOC( sizeof(ResNameOrOrdinal) );
        if (newname == NULL) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            newname->ord.fFlag = 0xff;
            newname->ord.wOrdinalID = id->ID.Num;
        }
    }

    return( newname );
}
Esempio n. 2
0
char * WResHelpIDToStr( const WResHelpID * name )
/***************************************/
/* return the value in a Help ID if it is a string, NULL otherwise */
{
    char *string;

    if ( name != NULL && name->IsName) {
        /* alloc space for the string and a \0 char at the end */
        string = WRESALLOC( name->ID.Name.NumChars + 1 );
        if (string == NULL) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            /* copy the string */
            memcpy( string, name->ID.Name.Name, name->ID.Name.NumChars );
            string[ name->ID.Name.NumChars ] = '\0';
        }
    } else {
        string = WRESALLOC( UINT32_MAXDIGITS + 1 );
        if( string == NULL ) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            itoa( name->ID.Num, string, 10 );
        }
    }

    return( string );
} /* WResHelpIDToStr */
Esempio n. 3
0
WResIDName *WResReadWResIDName( WResFileID fid )
/**********************************************/
{
    WResIDName      newname;
    WResIDName      *newptr;
    WResFileSSize   numread;
    bool            error;

    /* read the size of the name in */
    error = ResReadUint8( &(newname.NumChars), fid );

    /* alloc the space for the new record */
    if( error ) {
        return( NULL );
    } else {
        /* -1 because one of the chars in the name is declared in the struct */
        newptr = WRESALLOC( sizeof( WResIDName ) + newname.NumChars - 1 );
    }

    /* read in the characters */
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        newptr->NumChars = newname.NumChars;
        numread = WRESREAD( fid, newptr->Name, newptr->NumChars );
        if( numread != newptr->NumChars ) {
            WRES_ERROR( WRESIOERR( fid, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
            WRESFREE( newptr );
            newptr = NULL;
        }
    }

    return( newptr );
} /* WResReadWResIDName */
Esempio n. 4
0
extern int ResWriteStringLen( char *string, uint_8 use_unicode, int handle, uint_16 len )
/***************************************************************************************/
{
    wio_ssize_t     numwrote;
    char            *buf;
    int             ret;

    if( use_unicode ) {
        if( len * 2 > CONV_BUF_SIZE ) {
            buf = WRESALLOC( 2 * len );
        } else {
            buf = ConvBuffer;
        }
        len = (ConvToUnicode)( len, string, buf );
    } else {
        buf = string;
    }
    numwrote = WRESWRITE( handle, buf, len );
    if( numwrote != len ) {
        WRES_ERROR( WRS_WRITE_FAILED );
        ret = TRUE;
    } else {
        ret = FALSE;
    }
    if( buf != ConvBuffer && buf != string ) {
        WRESFREE( buf );
    }
    return( ret );
}
Esempio n. 5
0
static int readLangInfoList( WResFileID handle, WResResNode *res,
                             void *fileinfo ) {

    unsigned            i;
    WResLangNode        *langnode;
    int                 error;
    int                 numread;

    error = FALSE;
    for( i=0; i < res->Info.NumResources; i++ ) {
        langnode = WRESALLOC( sizeof(WResLangNode) );
        if( langnode == NULL ) {
            error = TRUE;
            WRES_ERROR( WRS_MALLOC_FAILED );
        }
        if( error ) break;
        numread = (* WRESREAD) ( handle, &(langnode->Info),
                                 sizeof( WResLangInfo ) );
        if( numread != sizeof( WResLangInfo ) ) {
            error = TRUE;
            WRES_ERROR( numread == -1 ? WRS_READ_FAILED:WRS_READ_INCOMPLETE );
            WRESFREE( langnode );
            break;
        }
        langnode->data = NULL;
        langnode->fileInfo = fileinfo;
        ResAddLLItemAtEnd( (void **)&(res->Head), (void **)&(res->Tail), langnode );
    }
    return( error );
}
Esempio n. 6
0
WResHelpID * WResHelpIDFromStr( const char * newstr )
/*******************************************/
/* allocate a Help ID and fill it in */
{
    WResHelpID *newid;
    unsigned    strsize;

    strsize = strlen( newstr );
    /* check the size of the string:  can it fit in one byte? */
    if (strsize <= 0xff) {
        /* allocate the new Help ID */
        // if strsize is non-zero then the memory allocated is larger
        // than required by 1 byte
        newid = WRESALLOC( sizeof(WResHelpID) + strsize );

        if (newid == NULL) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            newid->IsName = TRUE;
            newid->ID.Name.NumChars = strsize;
            memcpy( newid->ID.Name.Name, newstr, strsize );
        }
    } else {
        WRES_ERROR( WRS_BAD_PARAMETER );
        newid = NULL;
    }

    return( newid );
} /* WResHelpIDFromStr */
Esempio n. 7
0
static WResLangNode *newLangNode( uint_16 memflags, uint_32 offset,
                                  uint_32 length, WResLangType *type,
                                  void *fileinfo )
{
    WResLangNode        *newnode;

    newnode = WRESALLOC( sizeof( WResLangNode ) );
    if( newnode == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        newnode->Next = NULL;
        newnode->Prev = NULL;
        newnode->data = NULL;
        newnode->fileInfo = fileinfo;
        newnode->Info.MemoryFlags = memflags;
        newnode->Info.Offset = offset;
        newnode->Info.Length = length;
        if( type == NULL ) {
            newnode->Info.lang.lang = DEF_LANG;
            newnode->Info.lang.sublang = DEF_SUBLANG;
        } else {
            newnode->Info.lang = *type;
        }
    }
    return( newnode );
}
Esempio n. 8
0
bool ResWriteStringLen( const char *string, bool use_unicode, WResFileID handle, uint_16 len )
/********************************************************************************************/
{
    char            *buf = NULL;
    bool            ret;

    if( use_unicode ) {
        if( len * 2 > CONV_BUF_SIZE ) {
            buf = WRESALLOC( 2 * len );
        } else {
            buf = ConvBuffer;
        }
        len = (ConvToUnicode)( len, string, buf );
        string = buf;
    }
    if( WRESWRITE( handle, string, len ) != len ) {
        WRES_ERROR( WRS_WRITE_FAILED );
        ret = true;
    } else {
        ret = false;
    }
    if( use_unicode ) {
        if( buf != ConvBuffer ) {
            WRESFREE( buf );
        }
    }
    return( ret );
}
Esempio n. 9
0
extern ResNameOrOrdinal * ResStrToNameOrOrd( char * string )
/**********************************************************/
{
    ResNameOrOrdinal *  newname;
    int                 stringlen;

    if( string == NULL || *(unsigned char *)string == 0xff ) {
        /* the first character of a ResNameOrOrdinal can't be 0xff */
        /* since this indicated that it is an ordinal, not a name */
        WRES_ERROR( WRS_BAD_PARAMETER );
        return( NULL );
    }

    stringlen = strlen( string );

    newname = WRESALLOC( sizeof(ResNameOrOrdinal) + stringlen );
    if (newname != NULL) {
        /* +1 so we get the '\0' as well */
        memcpy( &(newname->name), string, stringlen + 1 );
    } else {
        WRES_ERROR( WRS_MALLOC_FAILED );
    }

    return( newname );
}
Esempio n. 10
0
WResIDName *WResReadWResIDName( FILE *fp )
/****************************************/
{
    WResIDName      newname;
    WResIDName      *newptr;
    size_t          numread;

    /* read the size of the name in */
    if( ResReadUint8( &(newname.NumChars), fp ) )
        return( NULL );

    /* alloc the space for the new record */
    /* -1 because one of the chars in the name is declared in the struct */
    newptr = WRESALLOC( sizeof( WResIDName ) + newname.NumChars - 1 );
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        /* read in the characters */
        newptr->NumChars = newname.NumChars;
        if( (numread = WRESREAD( fp, newptr->Name, newptr->NumChars )) != newptr->NumChars ) {
            WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
            WRESFREE( newptr );
            newptr = NULL;
        }
    }

    return( newptr );
} /* WResReadWResIDName */
Esempio n. 11
0
static bool ResWriteDialogHeaderCommon32( DialogBoxHeader32 *head, FILE *fp, bool add_quotes )
/********************************************************************************************/
{
    bool    error;
    size_t  len;
    char    *newname;

    if( add_quotes ) {
        if( head->MenuName != NULL && head->MenuName->name[0] != '\0' ) {
            len = strlen( head->MenuName->name );
            newname = WRESALLOC( len + 3 );
            newname[0] = '"';
            strcpy( newname + 1, head->MenuName->name );
            newname[len + 1] = '"';
            newname[len + 2] = '\0';
            head->MenuName = ResStrToNameOrOrd( newname );
            WRESFREE( newname );
        }
    }

    error = ResWriteNameOrOrdinal( head->MenuName, true, fp );
    if( !error ) {
        error = ResWriteNameOrOrdinal( head->ClassName, true, fp );
    }
    if( !error ) {
        error = ResWriteString( head->Caption, true, fp );
    }

    return( error );
}
Esempio n. 12
0
ResNameOrOrdinal *ResReadNameOrOrdinal( WResFileID handle )
/*********************************************************/
{
    ResNameOrOrdinal    newname;
    ResNameOrOrdinal *  newptr;
    int                 error;
    int                 stringlen;
    char *              restofstr;
    uint_8              tmp8;
    uint_16             tmp16;

    restofstr = NULL;
    error = ResReadUint8( &tmp8, handle );
    newname.ord.fFlag = tmp8;
    newname.ord.wOrdinalID = 0;
    stringlen = 0;

    /* read the rest of the Name or Ordinal */
    if (!error) {
        if (newname.ord.fFlag == 0xff) {
            error = ResReadUint16( &tmp16, handle );
            newname.ord.wOrdinalID = tmp16;
        } else {
            if (newname.name[0] != '\0') {
                restofstr = ResReadString( handle, &stringlen );
                stringlen += 1; /* for the '\0' */
                error = (restofstr == NULL);
            }
        }
    }

    /* allocate space for the new Name or Ordinal */
    if (error) {
        newptr = NULL;
    } else {
        newptr = WRESALLOC( sizeof(ResNameOrOrdinal) + stringlen );
        error = (newptr == NULL);
        if( error ) WRES_ERROR( WRS_MALLOC_FAILED );
    }

    /* copy the new new Name or Ordinal into the correct place */
    if (!error) {
        newptr->ord.fFlag = newname.ord.fFlag;
        if (newname.ord.fFlag == 0xff) {
            newptr->ord.wOrdinalID = newname.ord.wOrdinalID;
        } else {
            if (newptr->name[0] != '\0') {
                memcpy( &(newptr->name[1]), restofstr, stringlen );
                WRESFREE( restofstr );
            }
        }
    }

    return( newptr );
}
Esempio n. 13
0
DepInfo *WResGetAutoDep( const char *fname )
{
    WResFileID      handle;
    WResDir         dir;
    bool            dup_discarded;
    WResID          *name;
    WResID          *type;
    WResDirWindow   window;
    WResLangInfo    *info;
    DepInfo         *ret;
    WResFileSSize   numread;

    ret = NULL;
    handle = ResOpenFileRO( fname );
    if( handle != WRES_NIL_HANDLE ) {
        if( WResIsWResFile( handle ) && (dir = WResInitDir()) != NULL ) {
            if( !WResReadDir( handle, dir, &dup_discarded ) ) {
                name = WResIDFromStr( DEP_LIST_NAME );
                type = WResIDFromNum( DEP_LIST_TYPE );
                if( name != NULL && type != NULL ) {
                    window = WResFindResource( type, name, dir, NULL );
                    if( WResIsEmptyWindow( window ) ) {
                        WRES_ERROR( WRS_RES_NOT_FOUND );
                    } else {
                        info = WResGetLangInfo( window );
                        if( WRESSEEK( handle, info->Offset, SEEK_SET ) == -1 ) {
                            WRES_ERROR( WRS_SEEK_FAILED );
                        } else {
                            ret = WRESALLOC( info->Length );
                            if( ret == NULL ) {
                                WRES_ERROR( WRS_MALLOC_FAILED );
                            } else {
                                numread = WRESREAD( handle, ret, info->Length );
                                if( numread != (WResFileSSize)info->Length ) {
                                    WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                                    ret = NULL;
                                }
                            }
                        }
                    }
                }
                if( name != NULL ) {
                    WResIDFree( name );
                }
                if( type != NULL ) {
                    WResIDFree( type );
                }
            }
            WResFreeDir( dir );
        }
        ResCloseFile( handle );
    }
    return( ret );
}
Esempio n. 14
0
ResNameOrOrdinal *ResRead32NameOrOrdinal( WResFileID handle )
/***********************************************************/
{
    uint_16             flags;
    uint_16             ord;
    ResNameOrOrdinal *  newptr;
    int                 error;
    int                 stringlen;
    char *              restofstr;

    restofstr = NULL;
    ord = 0;
    stringlen = 0;

    error = ResReadUint16( &flags, handle );
    /* read the rest of the Name or Ordinal */
    if( !error ) {
        if( flags == 0xffff ) {
            error = ResReadUint16( &ord, handle );
        } else {
            if( flags != 0x0000 ) {
                restofstr = ResRead32String( handle, &stringlen );
                stringlen += 1; /* for the '\0' */
                error = (restofstr == NULL);
            }
        }
    }

    /* allocate space for the new Name or Ordinal */
    if( error ) {
        newptr = NULL;
    } else {
        newptr = WRESALLOC( sizeof(ResNameOrOrdinal) + stringlen );
        error = (newptr == NULL);
        if( error ) WRES_ERROR( WRS_MALLOC_FAILED );
    }

    /* copy the new new Name or Ordinal into the correct place */
    if( !error ) {
        if( flags == 0xffff ) {
            newptr->ord.fFlag = 0xff;
            newptr->ord.wOrdinalID = ord;
        } else {
            newptr->name[0] = (char)(flags & 0x00ff);
            if( flags != 0x0000 ) {
                memcpy( &(newptr->name[1]), restofstr, stringlen );
                WRESFREE( restofstr );
            }
        }
    }

    return( newptr );
}
Esempio n. 15
0
extern ResNameOrOrdinal * ResNumToNameOrOrd( uint_16 num )
/********************************************************/
{
    ResNameOrOrdinal *  newname;

    newname = WRESALLOC( sizeof(ResNameOrOrdinal) );
    if (newname != NULL) {
        newname->ord.fFlag = 0xff;
        newname->ord.wOrdinalID = num;
    }

    return( newname );
}
Esempio n. 16
0
static int readTypeList( WResFileID handle, WResDirHead * currdir,
                         uint_16 ver, void *fileinfo )
{
    WResTypeNode *  newnode;
    WResTypeInfo    newtype;
    int             error;
    int             typenum;
    int             extrabytes;

    /* loop through the list of types */
    for (error = FALSE, typenum = 0; typenum < currdir->NumTypes && !error;
            typenum++) {
        /* read a type record from disk */
        if( ver < 3 ) {
            error = WResReadFixedTypeRecord2( &newtype, handle );
        } else {
            error = WResReadFixedTypeRecord( &newtype, handle );
        }
        if( !error ) {
            /* allocate a new node */
            extrabytes = WResIDExtraBytes( &(newtype.TypeName) );
            newnode = WRESALLOC( sizeof(WResTypeNode) + extrabytes );
            if( newnode == NULL ) {
                error = TRUE;
                WRES_ERROR( WRS_MALLOC_FAILED );
            }
        }
        if( !error ) {
            /* initialize the linked list of resources */
            newnode->Head = NULL;
            newnode->Tail = NULL;
            /* copy the new type info into the new node */
            memcpy( &(newnode->Info), &newtype, sizeof(WResTypeInfo) );

            /* read the extra bytes (if any) */
            if( extrabytes > 0 ) {
                error = WResReadExtraWResID( &(newnode->Info.TypeName),
                                             handle );
            }
        }
        if( !error ) {
            /* add the type node to the linked list */
            ResAddLLItemAtEnd( (void **)&(currdir->Head), (void **)&(currdir->Tail), newnode );
            /* read in the list of resources of this type */
            error = readResList( handle, newnode, ver, fileinfo );
        }
    }

    return( error );

} /* readTypeList */
Esempio n. 17
0
int WResWriteWResIDNameUni( const WResIDName *name, uint_8 use_unicode, int handle )
/**********************************************************************************/
{
    int             error;
    wio_ssize_t     numwrote;
    uint_16         numchars;
    uint_8          tmp;
    char            *ptr;
    int             freebuf;

    freebuf = FALSE;
    error = FALSE;
    if (name == NULL) {
        /* a NULL name means write 0 length name */
        numchars = 0;
    } else {
        numchars = name->NumChars;
    }
    if( use_unicode ) {
        // for short strings use a static buffer in improve performance
        if( numchars <= CONV_BUF_SIZE / 2 ) {
            ptr = ConvBuffer;
        } else {
            freebuf = TRUE;
            ptr = WRESALLOC( 2 * numchars );
        }
        numchars = (ConvToUnicode)( numchars, name->Name, ptr ) / 2;
        error = ResWriteUint16( &numchars, handle );
        numchars *= 2;
    } else {
        numchars &= 0xFF;       /* in 16-bit the string can be no more than
                                   256 characters*/
        tmp = numchars;
        ptr = (char *)name->Name;
        error = ResWriteUint8( &tmp, handle );
    }
    if( !error && numchars > 0 ) {
        numwrote = WRESWRITE( handle, ptr, numchars );
        if( numwrote != numchars ) {
            error = TRUE;
            WRES_ERROR( WRS_WRITE_FAILED );
        }
    }
    if( freebuf ) {
        WRESFREE( ptr );
    }
    return( error );
} /* WResWriteWResIDNameUni */
Esempio n. 18
0
extern int WResLoadResource2( WResDir            dir,
                                     PHANDLE_INFO       hInstance,
                                     UINT               idType,
                                     UINT               idResource,
                                     LPSTR              *lpszBuffer,
                                     int                *bufferSize )
/******************************************************************/
{
    int                 retcode;
    WResID              resource_type;
    WResID              resource_id;
    WResDirWindow       wind;
    WResLangInfo        *res;
    WResLangType        lang;
    char                *res_buffer;

    if( ( lpszBuffer == NULL ) || ( bufferSize == NULL ) ) {
        return( -1 );
    }

    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;
    WResInitIDFromNum( idResource, &resource_id );
    WResInitIDFromNum( (long)idType, &resource_type );

    wind = WResFindResource( &resource_type, &resource_id, dir, &lang );

    if( WResIsEmptyWindow( wind ) ) {
        retcode = -1;
    } else {
        res = WResGetLangInfo( wind );
        // lets make sure we dont perturb malloc into apoplectic fits
        if( res->Length >= INT_MAX ) {
            return( -1 );
        }
        res_buffer  = WRESALLOC( res->Length );
        *lpszBuffer = res_buffer;
        if( *lpszBuffer == NULL ) {
            return( -1 );
        }
        *bufferSize = (int)res->Length;
        retcode = GetResource( res, hInstance, res_buffer );
    }

    return( retcode );
}
Esempio n. 19
0
MenuItem * ResNewMenuItem( void )
/*******************************/
{
    MenuItem *  newitem;

    newitem = WRESALLOC( sizeof( MenuItem ) );
    if( newitem == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        newitem->IsPopup = false;
        newitem->Item.Normal.ItemFlags = 0;
        newitem->Item.Normal.ItemID = 0;
        newitem->Item.Normal.ItemText = NULL;
    }

    return( newitem );
}
Esempio n. 20
0
bool WResWriteWResIDNameUni( const WResIDName *name, bool use_unicode, WResFileID handle )
/******************************************************************************************/
{
    bool            error;
    uint_16         numchars;
    char            *ptr;
    bool            freebuf;

    freebuf = false;
    error = false;
    if( name == NULL ) {
        /* a NULL name means write 0 length name */
        numchars = 0;
    } else {
        numchars = name->NumChars;
    }
    if( use_unicode ) {
        // for short strings use a static buffer in improve performance
        if( numchars <= CONV_BUF_SIZE / 2 ) {
            ptr = ConvBuffer;
        } else {
            freebuf = true;
            ptr = WRESALLOC( 2 * numchars );
        }
        numchars = (ConvToUnicode)( numchars, name->Name, ptr ) / 2;
        error = ResWriteUint16( numchars, handle );
        numchars *= 2;
    } else {
        /* in 16-bit resources the string can be no more than 255 characters */
        if( numchars > 0xFF )
            numchars = 0xFF;
        ptr = (char *)name->Name;
        error = ResWriteUint8( numchars, handle );
    }
    if( !error && numchars > 0 ) {
        if( WRESWRITE( handle, ptr, numchars ) != numchars ) {
            error = true;
            WRES_ERROR( WRS_WRITE_FAILED );
        }
    }
    if( freebuf ) {
        WRESFREE( ptr );
    }
    return( error );
} /* WResWriteWResIDNameUni */
Esempio n. 21
0
static WResTypeNode *newTypeNode( const WResID *type )
{
    WResTypeNode        *newnode;
    int                 extrabytes;

    extrabytes = WResIDExtraBytes( type );
    newnode = WRESALLOC( sizeof( WResTypeNode ) + extrabytes );
    if (newnode != NULL) {
        newnode->Next = NULL;
        newnode->Prev = NULL;
        newnode->Head = NULL;
        newnode->Tail = NULL;
        newnode->Info.NumResources = 0;
        memcpy( &(newnode->Info.TypeName), type, sizeof(WResID) + extrabytes );
    } else {
        WRES_ERROR( WRS_MALLOC_FAILED );
    }
    return( newnode );
}
Esempio n. 22
0
WResID * WResIDFromNum( long newnum )
/***********************************/
/* allocate an ID and fill it in */
{
    WResID *    newid;

    if( (int_32)newnum < SHRT_MIN || ( newnum > 0 && newnum > USHRT_MAX ) ) {
        newid = NULL;
        WRES_ERROR( WRS_BAD_PARAMETER );
    } else {
        newid = WRESALLOC( sizeof( WResID ) );
        if( newid == NULL ) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            WResInitIDFromNum( newnum, newid );
        }
    }
    return( newid );
} /* WResIDFromNum */
Esempio n. 23
0
int WResLoadResource2( WResDir dir, PHANDLE_INFO hinfo, WResID *resource_type,
                       WResID *resource_id, lpstr *lpszBuffer, size_t *bufferSize )
/*********************************************************************************/
{
    int                 retcode;
    WResDirWindow       wind;
    WResLangInfo        *res;
    WResLangType        lang;
    char                *res_buffer;

    if( ( resource_type == NULL ) || ( resource_id == NULL ) || ( lpszBuffer == NULL ) || ( bufferSize == NULL ) ) {
        return( -1 );
    }

    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;

    wind = WResFindResource( resource_type, resource_id, dir, &lang );

    if( WResIsEmptyWindow( wind ) ) {
        retcode = -1;
    } else {
        res = WResGetLangInfo( wind );
#ifdef _M_I86
        // lets make sure we dont perturb malloc into apoplectic fits
        if( res->Length > (size_t)(-1LL) ) {
            return( -1 );
        }
#endif
        res_buffer  = WRESALLOC( res->Length );
        *lpszBuffer = res_buffer;
        if( *lpszBuffer == NULL ) {
            return( -1 );
        }
        *bufferSize = (size_t)res->Length;
        retcode = GetResource( res, hinfo, res_buffer );
    }

    return( retcode );
}
Esempio n. 24
0
MResResourceHeader *MResReadResourceHeader( WResFileID handle )
/*************************************************************/
{
    MResResourceHeader     *newhead;
    int                     error;
    uint_16                 tmp16;
    uint_32                 tmp32;

    newhead = WRESALLOC( sizeof(MResResourceHeader) );
    if( newhead == NULL ) {
        error = TRUE;
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        error = FALSE;
    }

    if (!error) {
        newhead->Type = ResReadNameOrOrdinal( handle );
        error = (newhead->Type == NULL);
    }
    if (!error) {
        newhead->Name = ResReadNameOrOrdinal( handle );
        error = (newhead->Name == NULL);
    }
    if (!error) {
        error = ResReadUint16( &tmp16, handle);
        newhead->MemoryFlags = tmp16;
    }
    if (!error) {
        error = ResReadUint32( &tmp32, handle );
        newhead->Size = tmp32;
    }

    if (error && newhead != NULL) {
        WRESFREE( newhead );
        newhead = NULL;
    }

    return( newhead );
} /* MResReadResourceHeader */
Esempio n. 25
0
WResResInfo *WResReadResRecord( WResFileID handle )
/*************************************************/
/* reads in the fields of a res info record from the current position in */
/* the file identified by fp */
{
    WResResInfo     newres;
    WResResInfo     *newptr;
    WResFileSSize   numread;
    int             numcharsleft;
    bool            error;

    error = WResReadFixedResRecord( &newres, handle );
    if( error ) {
        return( NULL );
    }

    if( newres.ResName.IsName ) {
        numcharsleft = newres.ResName.ID.Name.NumChars - 1;
    } else {
        numcharsleft = 0;
    }
    newptr = WRESALLOC( sizeof( WResResInfo ) + numcharsleft );
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        memcpy( newptr, &newres, sizeof( WResResInfo ) );
        if( numcharsleft != 0 ) {
            numread = WRESREAD( handle, newptr->ResName.ID.Name.Name + 1, numcharsleft );
            if( numread != numcharsleft ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                WRESFREE( newptr );
                newptr = NULL;
            }
        }
    }

    return( newptr );
} /* WResReadResRecord */
Esempio n. 26
0
WResID *WResReadWResID( WResFileID handle )
/*****************************************/
{
    WResID          newid;
    WResID          *newidptr;
    WResFileSSize   numread;
    int             extrabytes;     /* chars to be read beyond the fixed size */
    bool            error;

    /* read in the fixed part of the record */
    error = WResReadFixedWResID( &newid, handle );
    if( error ) {
        return( NULL );
    }

    if( newid.IsName ) {
        extrabytes = newid.ID.Name.NumChars - 1;
    } else {
        extrabytes = 0;
    }

    newidptr = WRESALLOC( sizeof( WResID ) + extrabytes );
    if( newidptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        memcpy( newidptr, &newid, sizeof( WResID ) );
        if( extrabytes != 0 ) {
            numread = WRESREAD( handle, newidptr->ID.Name.Name + 1, extrabytes );
            if( numread != extrabytes ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                WRESFREE( newidptr );
                newidptr = NULL;
            }
        }
    }

    return( newidptr );
} /* WResReadWResID */
Esempio n. 27
0
WResIDName *WResIDNameFromStr( const char *string )
/*************************************************/
{
    WResIDName  *newstring;
    size_t      stringlen;

    stringlen = strlen( string );
    if( stringlen >= USHRT_MAX ) {
        /* truncate the string if it is more that UCHAR_MAX in length */
        stringlen = USHRT_MAX;
    }

    newstring = WRESALLOC( sizeof( WResIDName ) + stringlen - 1 );
    if( newstring == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        newstring->NumChars = stringlen;
        /* don't copy the '\0' */
        memcpy( &(newstring->Name), string, stringlen );
    }

    return( newstring );
}
Esempio n. 28
0
extern M32ResResourceHeader *M32ResReadResourceHeader( WResFileID handle )
/************************************************************************/
{
    M32ResResourceHeader     *newhead;
    int                       error = FALSE;
    uint_16                   tmp16;
    uint_32                   tmp32;

    newhead = WRESALLOC( sizeof( M32ResResourceHeader ) );
    if( newhead == NULL ) {
        error = TRUE;
        WRES_ERROR( WRS_MALLOC_FAILED );
    }
    newhead->head16 = WRESALLOC( sizeof( MResResourceHeader ) );
    if( newhead->head16 == NULL ) {
        error = TRUE;
        WRES_ERROR( WRS_MALLOC_FAILED );
    }
    if( !error ) {
        error = ResPadDWord( handle );
    }
    if( !error ) {
        error = ResReadUint32( &tmp32, handle );
        newhead->head16->Size = tmp32;
    }
    if( !error ) {
        error = ResReadUint32( &(newhead->HeaderSize), handle );
    }
    if( !error ) {
        newhead->head16->Type = ResRead32NameOrOrdinal( handle );
        error = (newhead->head16->Type == NULL );
    }
    if( !error ) {
        newhead->head16->Name = ResRead32NameOrOrdinal( handle );
        error = (newhead->head16->Name == NULL );
    }
    if( !error ) {
        error = ResPadDWord( handle );
    }
    if( !error ) {
        error = ResReadUint32( &tmp32, handle );
        newhead->head16->DataVersion = tmp32;
    }
    if( !error ) {
        error = ResReadUint16( &tmp16, handle );
        newhead->head16->MemoryFlags = tmp16;
    }
    if( !error ) {
        error = ResReadUint16( &tmp16, handle );
        newhead->head16->LanguageId = tmp16;
    }
    if( !error ) {
        error = ResReadUint32( &tmp32, handle );
        newhead->head16->Version = tmp32;
    }
    if( !error ) {
        error = ResReadUint32( &tmp32, handle );
        newhead->head16->Characteristics = tmp32;
    }
    if( error && newhead != NULL ) {
        WRESFREE( newhead->head16 );
        WRESFREE( newhead );
        newhead = NULL;
    }

    return( newhead );
}
Esempio n. 29
0
static int readResList( WResFileID handle, WResTypeNode * currtype,
                        uint_16 ver, void *fileinfo )
{
    WResResNode    *newnode;
    WResResInfo     newres;
    WResResInfo1    newres1;
    WResLangNode   *langnode;
    WResID         *resid;
    WResID          tmpresid;
    int             error;
    int             resnum;
    int             extrabytes;

    /* loop through the list of resources of this type */
    for (resnum = 0, error = FALSE; resnum < currtype->Info.NumResources &&
            !error; resnum++) {

        /* read a resource record from disk */
        if( ver < 2 ) {
            error = WResReadFixedResRecord1( &newres1, handle );
            resid = &tmpresid;
            tmpresid.IsName = newres1.ResName.IsName;
            if( tmpresid.IsName ) {
                tmpresid.ID.Name.Name[0] = newres1.ResName.ID.Name.Name[0];
                tmpresid.ID.Name.NumChars = newres1.ResName.ID.Name.NumChars;
            } else {
                tmpresid.ID.Num = newres1.ResName.ID.Num;
            }
        } else if( ver == 2 ) {
            error = WResReadFixedResRecord2( &newres, handle );
            resid = &( newres.ResName );
        } else {
            error = WResReadFixedResRecord( &newres, handle );
            resid = &( newres.ResName );
        }

        if( !error ) {
            /* allocate a new node */
            extrabytes = WResIDExtraBytes( resid );
            newnode = WRESALLOC( sizeof(WResResNode) + extrabytes );
            if( newnode == NULL ) {
                error = TRUE;
                WRES_ERROR( WRS_MALLOC_FAILED );
            }
        }
        if( !error ) {
            newnode->Head = NULL;
            newnode->Tail = NULL;
            /* copy the new resource info into the new node */
            if( ver < 2 ) {
                newnode->Info.NumResources = 1;
                memcpy( &(newnode->Info.ResName), &( newres1.ResName ),
                        sizeof( WResID ) );
            } else {
                memcpy( &(newnode->Info), &newres, sizeof(WResResInfo) );
            }

            /* read the extra bytes (if any) */
            if( extrabytes > 0 ) {
                error = WResReadExtraWResID( &(newnode->Info.ResName), handle );
            }

            if( ver < 2 ) {
                langnode = WRESALLOC( sizeof(WResLangNode) );
                if( langnode == NULL ) {
                    error =  TRUE;
                    WRES_ERROR( WRS_MALLOC_FAILED );
                }
                if( !error ) {
                    langnode->data = NULL;
                    langnode->fileInfo = fileinfo;
                    langnode->Info.MemoryFlags = newres1.MemoryFlags;
                    langnode->Info.Offset = newres1.Offset;
                    langnode->Info.Length = newres1.Length;
                    langnode->Info.lang.lang = DEF_LANG;
                    langnode->Info.lang.sublang = DEF_SUBLANG;
                    ResAddLLItemAtEnd( (void **)&(newnode->Head), (void **)&(newnode->Tail),
                                       langnode );
                }
            } else {
                error = readLangInfoList( handle, newnode, fileinfo );
            }
        }
        if( !error ) {
            /* add the resource node to the linked list */
            ResAddLLItemAtEnd( (void **)&(currtype->Head), (void **)&(currtype->Tail), newnode );
        }
    }

    return( error );

} /* readResList */