Ejemplo n.º 1
0
static bool chd_get_crc(database_state_handle_t *db_state,
      const char *name, uint32_t *crc)
{
   intfstream_t *fd = NULL;
   uint32_t acc = 0;
   uint8_t buffer[4096];
   ssize_t size;

   fd = open_chd_track(name, CHDSTREAM_TRACK_FIRST_DATA);
   if (!fd)
   {
      return 0;
   }

   while ((size = intfstream_read(fd, buffer, sizeof(buffer))) > 0)
   {
      acc = encoding_crc32(acc, buffer, size);
   }
   if (size < 0)
   {
      return 0;
   }

   RARCH_LOG("CHD '%s' crc: %x\n", name, acc);

   *crc = acc;

   return 1;
}
Ejemplo n.º 2
0
static bool intfstream_file_get_serial(const char *name,
      uint64_t offset, uint64_t size, char *serial)
{
   int rv;
   uint8_t *data     = NULL;
   int64_t file_size = -1;
   intfstream_t *fd  = intfstream_open_file(name,
         RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);

   if (!fd)
      return 0;

   if (intfstream_seek(fd, 0, SEEK_END) == -1)
      goto error;

   file_size = intfstream_tell(fd);

   if (intfstream_seek(fd, 0, SEEK_SET) == -1)
      goto error;

   if (file_size < 0)
      goto error;

   if (offset != 0 || size < (uint64_t) file_size)
   {
      if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1)
         goto error;

      data = (uint8_t*)malloc((size_t)size);

      if (intfstream_read(fd, data, size) != (int64_t) size)
      {
         free(data);
         goto error;
      }

      intfstream_close(fd);
      free(fd);
      fd = intfstream_open_memory(data, RETRO_VFS_FILE_ACCESS_READ,
            RETRO_VFS_FILE_ACCESS_HINT_NONE,
            size);
      if (!fd)
      {
         free(data);
         return 0;
      }
   }

   rv = intfstream_get_serial(fd, serial);
   intfstream_close(fd);
   free(fd);
   free(data);
   return rv;

error:
   intfstream_close(fd);
   free(fd);
   return 0;
}
Ejemplo n.º 3
0
static int intfstream_get_crc(intfstream_t *fd, uint32_t *crc)
{
   int64_t read = 0;
   uint32_t acc = 0;
   uint8_t buffer[4096];

   while ((read = intfstream_read(fd, buffer, sizeof(buffer))) > 0)
      acc = encoding_crc32(acc, buffer, (size_t)read);

   if (read < 0)
      return 0;

   *crc = acc;

   return 1;
}