ソースを参照

* Make deprecated cucul_load_file() use cucul_file_t functions.

tags/v0.99.beta14
Sam Hocevar sam 16年前
コミット
9edb7dc623
1個のファイルの変更22行の追加20行の削除
  1. +22
    -20
      cucul/legacy.c

+ 22
- 20
cucul/legacy.c ファイルの表示

@@ -172,44 +172,46 @@ cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
return buf;
}

#if !defined(__KERNEL__)
cucul_buffer_t *cucul_load_file(char const *file)
{
cucul_buffer_t *buf;
FILE *fp;
long int size;
cucul_file_t *f;
int ret;

fp = fopen(file, "rb");
if(!fp)
f = cucul_file_open(file, "rb");
if(!f)
return NULL;

buf = malloc(sizeof(cucul_buffer_t));
if(!buf)
{
fclose(fp);
cucul_file_close(f);
return NULL;
}

fseek(fp, 0, SEEK_END);
size = ftell(fp);
buf->data = NULL;
buf->size = 0;

buf->data = malloc(size);
if(!buf->data)
while(!cucul_file_eof(f))
{
free(buf);
fclose(fp);
return NULL;
buf->data = realloc(buf->data, buf->size + 1024);
if(!buf->data)
{
int saved_errno = geterrno();
free(buf);
cucul_file_close(f);
seterrno(saved_errno);
return NULL;
}

ret = cucul_file_read(f, buf->data + buf->size, 1024);
if(ret >= 0)
buf->size += ret;
}
buf->size = size;
buf->user_data = 0;

fseek(fp, 0, SEEK_SET);
fread(buf->data, buf->size, 1, fp);
fclose(fp);
cucul_file_close(f);

return buf;
}
#endif

unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
{


読み込み中…
キャンセル
保存