Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1.  
  2. #include <sys/types.h>
  3. #include <stdint.h>
  4. #include <sys/kos_io.h>
  5.  
  6. void *load_file(const char *path, size_t *len)
  7. {
  8.     fileinfo_t   info;
  9.     size_t       bytes;
  10.     void        *file = NULL;
  11.  
  12.     if( len) *len = 0;
  13.  
  14.  
  15.     if( !get_fileinfo(path, &info) )
  16.     {
  17.  
  18.         file = (void*)user_alloc( info.size );
  19.         read_file(path, file, 0, info.size, &bytes );
  20.         if( bytes == info.size )
  21.         {
  22.             if ( *(uint32_t*)file == 0x4B43504B )
  23.             {
  24.                 void *tmp = NULL;
  25.                 info.size = ((size_t*)file)[1];
  26.                 tmp = (void*)user_alloc(info.size);
  27.                 unpack(file, tmp);
  28.                 user_free(file);
  29.                 file = tmp;
  30.             }
  31.             if(len) *len = info.size;
  32.         };
  33.     };
  34.     return file;
  35. };
  36.  
  37.  
  38.