int M_ReadFile(char const *name, byte **buffer)
{
  FILE *fp;

  if ((fp = fopen(name, "rb")))
    {
      size_t length;

      I_BeginRead();
      fseek(fp, 0, SEEK_END);
      length = ftell(fp);
      fseek(fp, 0, SEEK_SET);
      *buffer = Z_Malloc(length, PU_STATIC, 0);
      if (fread(*buffer, 1, length, fp) == length)
        {
          fclose(fp);
          I_EndRead();
          return length;
        }
      fclose(fp);
    }

  /* cph 2002/08/10 - this used to return 0 on error, but that's ambiguous,
   * because we could have a legit 0-length file. So make it -1. */
  return -1;
}
예제 #2
0
파일: m_file.c 프로젝트: camgunz/d2k
bool M_WriteFile(const char *path, const char *contents, size_t size) {
  clear_file_error();

  I_BeginRead();
  gboolean res = g_file_set_contents(path, contents, size, &file_error);
  I_EndRead();

  return res;
}
예제 #3
0
파일: m_file.c 프로젝트: camgunz/d2k
bool M_ReadFile(const char *path, char **data, size_t *size) {
  clear_file_error();

  I_BeginRead();
  gboolean res = g_file_get_contents(path, data, size, &file_error);
  I_EndRead();

  return res;
}
예제 #4
0
파일: m_file.c 프로젝트: camgunz/d2k
bool M_ReadFileBuf(buf_t *buf, const char *path) {
  char *data = NULL;
  gsize size;

  clear_file_error();

  I_BeginRead();
  gboolean res = g_file_get_contents(path, &data, &size, &file_error);
  I_EndRead();

  if (!res)
    return false;

  M_BufferWrite(buf, data, size);

  return true;
}
예제 #5
0
void W_ReadLump (int lump, void *dest)
{
	int			c;
	lumpinfo_t	*l;
	
	if (lump >= numlumps)
		I_Error ("W_ReadLump: %i >= numlumps",lump);
	l = lumpinfo+lump;
	
	I_BeginRead ();
	
	lseek (l->handle, l->position, SEEK_SET);
	c = read (l->handle, dest, l->size);
	if (c < l->size)
		I_Error ("W_ReadLump: only read %i of %i on lump %i",c,l->size,lump);	
	I_EndRead ();
}
boolean M_WriteFile(char const *name, void *source, int length)
{
  FILE *fp;

  //errno = 0;

  if (!(fp = fopen(name, "wb")))       // Try opening file
    return 0;                          // Could not open file for writing

  I_BeginRead();                       // Disk icon on
  length = fwrite(source, 1, length, fp) == (size_t)length;   // Write data
  fclose(fp);
  I_EndRead();                         // Disk icon off

  if (!length)                         // Remove partially written file
    remove(name);

  return length;
}
예제 #7
0
파일: w_wad.cpp 프로젝트: WChrisK/OdaStats
//
// W_ReadLump
// Loads the lump into the given buffer,
//  which must be >= W_LumpLength().
//
void W_ReadLump(unsigned int lump, void* dest)
{
	int		c;
	lumpinfo_t*	l;

	if (lump >= numlumps)
		I_Error ("W_ReadLump: %i >= numlumps",lump);

	l = lumpinfo + lump;

	if (lump != stdisk_lumpnum)
    	I_BeginRead();

	fseek (l->handle, l->position, SEEK_SET);
	c = fread (dest, l->size, 1, l->handle);

	if (feof(l->handle))
		I_Error ("W_ReadLump: only read %i of %i on lump %i", c, l->size, lump);

	if (lump != stdisk_lumpnum)
    	I_EndRead();
}
예제 #8
0
파일: w_wad.c 프로젝트: derek57/research
//
// W_ReadLump
// Loads the lump into the given buffer,
//  which must be >= W_LumpLength().
//
void W_ReadLump(lumpindex_t lump, void *dest)
{
    int c;
    lumpinfo_t *l;

    if (lump >= numlumps)
    {
        I_Error ("W_ReadLump: %i >= numlumps", lump);
    }

    l = lumpinfo[lump];

    I_BeginRead();

    c = W_Read(l->wad_file, l->position, dest, l->size);

    if (c < l->size)
    {
        I_Error("W_ReadLump: only read %i of %i on lump %i",
                c, l->size, lump);
    }

    I_EndRead();
}