⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsc_files.c

📁 vlc stand 0.1.99 ist sehr einfach
💻 C
📖 第 1 页 / 共 2 页
字号:
    {        intf_ErrMsg("rsc error 103-1: %s\n", strerror(errno));        return( -2 );    }    /* Write header */    p_buffer[0] =               'R';    p_buffer[1] =               'F';    p_buffer[2] =               'V';    p_buffer[3] =               'L';    *(u16 *)(p_buffer + 4) =    p_file->i_type;    *(u16 *)(p_buffer + 6) =    p_file->i_size;    if( write( p_file->i_file, p_buffer, 8 ) != 8 )    {        intf_ErrMsg("rsc error 103-2: %s\n", strerror(errno));        return( -3 );    }    /* Write resources table */    for( i_index = 0; i_index < p_file->i_size; i_index++ )    {        memcpy( p_buffer, p_file->p_resource[i_index].psz_name, 32 );        *(u16 *)(p_buffer + 32) =   p_file->p_resource[i_index].i_type;        *(u64 *)(p_buffer + 34) =   p_file->p_resource[i_index].i_offset;        *(u64 *)(p_buffer + 42) =   p_file->p_resource[i_index].i_size;        if( write( p_file->i_file, p_buffer, 8 ) != 8 )        {            intf_ErrMsg("rsc error 103-3: %s\n", strerror(errno));            return( -4 );        }    }    /* Mark file as up to date */    p_file->b_up_to_date = 1;    return( 0 );}/***************************************************************************** * CloseResourceFile: close a resource file ***************************************************************************** * Updates the resources table if required, and close the file. It returns non * 0 in case of error. ***************************************************************************** * Messages type: rsc, major code 104 *****************************************************************************/int CloseResourceFile( resource_file_t *p_file ){    /* Update table */    if( !p_file->b_up_to_date && ( UpdateResourceFile( p_file ) < 0 ) )    {        return( -1 );    }    /* Close and destroy descriptor */    if( close( p_file->i_file ) )    {        intf_ErrMsg("rsc error 104-1: %s\n", strerror(errno));        return( -2 );    }    free( p_file->p_resource );    free( p_file );    return( 0 );}/***************************************************************************** * SeekResource: seek a resource in a resource file ***************************************************************************** * Look for a resource in file and place the "reading head" at the beginning of * the resource data. * In case of success, the resource number is returned. Else, a negative number * is returned. ***************************************************************************** * Messages type: rsc, major code 105 *****************************************************************************/int SeekResource( resource_file_t *p_file, char *psz_name, int i_type ){    int     i_index;                                       /* resource index */    /* Look for resource in table */    for( i_index = 0;         (i_index < p_file->i_size)             && ((i_type != p_file->p_resource[i_index].i_type )                 || strcmp(psz_name, p_file->p_resource[i_index].psz_name));         i_index++ )    {        ;    }    if( i_index == p_file->i_size )    {        intf_ErrMsg("rsc error 105-1: unknown resource %s.%d\n", psz_name, i_type);        return( -1 );    }    /* Seek */    if( lseek( p_file->i_file, p_file->p_resource[i_index].i_offset, SEEK_SET ) )    {        intf_ErrMsg("rsc error 105-2: can not reach %s.%d: %s\n", psz_name,                    i_type, strerror(errno));        return( -2 );    }    return( i_index );}/***************************************************************************** * ReadResource: read a resource ***************************************************************************** * Read a resource from a file. The function returns a negative value in case * of error, and 0 in case of success. ***************************************************************************** * Messages type: rsc, major code 106 *****************************************************************************/int ReadResource( resource_file_t *p_file, char *psz_name, int i_type,                  size_t max_size, byte_t *p_data ){    int i_index;                                           /* resource index */    /* Seek resource */    i_index = SeekResource( p_file, psz_name, i_type );    if( i_index < 0 )    {        return( -1 );    }    /* Check if buffer is large enough */    if( max_size < p_file->p_resource[i_index].i_size )    {        intf_ErrMsg("rsc error 106-1: buffer is too small\n");        return( -2 );    }    /* Read data */    if( read( p_file->i_file, p_data, p_file->p_resource[i_index].i_size )        != p_file->p_resource[i_index].i_size )    {        intf_ErrMsg("rsc error 106-2: can not read %s.%d: %s\n",                    p_file->p_resource[i_index].psz_name,                    p_file->p_resource[i_index].i_type,                    strerror(errno));        return( -3 );    }    return( 0 );}/***************************************************************************** * WriteResource: write a resource ***************************************************************************** * Append a resource at the end of the file. It returns non 0 on error. ***************************************************************************** * Messages type: rsc, major code 107 *****************************************************************************/int WriteResource( resource_file_t *p_file, char *psz_name, int i_type,                   size_t size, byte_t *p_data ){    int i_index;                                           /* resource index */    int i_tmp_index;                             /* temporary resource index */    u64 i_offset;                                                  /* offset */#ifdef DEBUG    if( p_file->b_read_only )    {        intf_DbgMsg("rsc debug 107-1: can not write to a read-only resource file\n");        return( -1 );    }#endif    /* Look for an empty place in the resources table */    i_index = -1;    i_offset = p_file->i_size * 50 + 8;    for( i_tmp_index = 0; i_tmp_index < p_file->i_size; i_tmp_index++ )    {        if( p_file->p_resource[i_tmp_index].i_type != EMPTY_RESOURCE)        {            i_offset = MAX( i_offset, p_file->p_resource[i_tmp_index].i_offset                            + p_file->p_resource[i_tmp_index].i_size );        }        else if( i_index == -1 )        {            i_index = i_tmp_index;        }    }    if( i_index == -1 )    {        intf_ErrMsg("rsc error 107-1: resources table is full\n");        return( -1 );    }    /* Seek end of file */    if( lseek( p_file->i_file, i_offset, SEEK_SET ) )    {        intf_ErrMsg("rsc error 107-2: %s\n", strerror(errno));        return( -2 );    }    /* Write data */    if( write( p_file->i_file, p_data, size ) != size )    {        intf_ErrMsg("rsc error 107-3: %s\n", strerror(errno));        return( -3 );    }    /* Update table */    strncpy( p_file->p_resource[i_index].psz_name, psz_name, RESOURCE_MAX_NAME );    p_file->p_resource[i_index].psz_name[RESOURCE_MAX_NAME] = '\0';    p_file->p_resource[i_index].i_type = i_type;    p_file->p_resource[i_index].i_offset = i_offset;    p_file->p_resource[i_index].i_size = size;    p_file->b_up_to_date = 0;    return( 0 );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -