update xfile.h (suppress warnings)

This commit is contained in:
Yuichi Nishiwaki 2014-09-26 13:50:27 +09:00
parent 1be24ae9d4
commit d029e003d6
1 changed files with 14 additions and 14 deletions

View File

@ -111,7 +111,7 @@ xf_file_read(void *cookie, char *ptr, int size)
FILE *file = cookie; FILE *file = cookie;
int r; int r;
r = fread(ptr, 1, size, file); r = (int)fread(ptr, 1, (size_t)size, file);
if (r < size && ferror(file)) { if (r < size && ferror(file)) {
return -1; return -1;
} }
@ -127,7 +127,7 @@ xf_file_write(void *cookie, const char *ptr, int size)
FILE *file = cookie; FILE *file = cookie;
int r; int r;
r = fwrite(ptr, 1, size, file); r = (int)fwrite(ptr, 1, (size_t)size, file);
if (r < size) { if (r < size) {
return -1; return -1;
} }
@ -212,8 +212,8 @@ xf_mem_read(void *cookie, char *ptr, int size)
mem = (struct xf_membuf *)cookie; mem = (struct xf_membuf *)cookie;
if (size > mem->end - mem->pos) if (size > (int)(mem->end - mem->pos))
size = mem->end - mem->pos; size = (int)(mem->end - mem->pos);
memcpy(ptr, mem->buf + mem->pos, size); memcpy(ptr, mem->buf + mem->pos, size);
mem->pos += size; mem->pos += size;
return size; return size;
@ -228,7 +228,7 @@ xf_mem_write(void *cookie, const char *ptr, int size)
if (mem->pos + size >= mem->capa) { if (mem->pos + size >= mem->capa) {
mem->capa = (mem->pos + size) * 2; mem->capa = (mem->pos + size) * 2;
mem->buf = realloc(mem->buf, mem->capa); mem->buf = realloc(mem->buf, (size_t)mem->capa);
} }
memcpy(mem->buf + mem->pos, ptr, size); memcpy(mem->buf + mem->pos, ptr, size);
mem->pos += size; mem->pos += size;
@ -344,12 +344,12 @@ xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
for (i = 0; i < nitems; ++i) { for (i = 0; i < nitems; ++i) {
offset = 0; offset = 0;
if (file->ungot != -1 && block > 0) { if (file->ungot != -1 && block > 0) {
buf[0] = file->ungot; buf[0] = (char)file->ungot;
offset += 1; offset += 1;
file->ungot = -1; file->ungot = -1;
} }
while (offset < block) { while (offset < block) {
n = file->vtable.read(file->vtable.cookie, buf + offset, block - offset); n = file->vtable.read(file->vtable.cookie, buf + offset, (int)(block - offset));
if (n < 0) { if (n < 0) {
file->flags |= XF_ERR; file->flags |= XF_ERR;
goto exit; goto exit;
@ -358,7 +358,7 @@ xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
file->flags |= XF_EOF; file->flags |= XF_EOF;
goto exit; goto exit;
} }
offset += n; offset += (unsigned)n;
} }
memcpy(dst, buf, block); memcpy(dst, buf, block);
dst += block; dst += block;
@ -378,12 +378,12 @@ xfwrite(const void *ptr, size_t block, size_t nitems, xFILE *file)
for (i = 0; i < nitems; ++i) { for (i = 0; i < nitems; ++i) {
offset = 0; offset = 0;
while (offset < block) { while (offset < block) {
n = file->vtable.write(file->vtable.cookie, dst + offset, block - offset); n = file->vtable.write(file->vtable.cookie, dst + offset, (int)(block - offset));
if (n < 0) { if (n < 0) {
file->flags |= XF_ERR; file->flags |= XF_ERR;
goto exit; goto exit;
} }
offset += n; offset += (unsigned)n;
} }
dst += block; dst += block;
} }
@ -458,7 +458,7 @@ xfgets(char *str, int size, xFILE *file)
if ((c = xfgetc(file)) == EOF) { if ((c = xfgetc(file)) == EOF) {
break; break;
} }
str[i] = c; str[i] = (char)c;
} }
if (i == 0 && c == EOF) { if (i == 0 && c == EOF) {
return NULL; return NULL;
@ -492,7 +492,7 @@ xfputc(int c, xFILE *file)
{ {
char buf[1]; char buf[1];
buf[0] = c; buf[0] = (char)c;
xfwrite(buf, 1, 1, file); xfwrite(buf, 1, 1, file);
if (xferror(file)) { if (xferror(file)) {
@ -516,7 +516,7 @@ xputchar(int c)
static inline int static inline int
xfputs(const char *str, xFILE *file) xfputs(const char *str, xFILE *file)
{ {
int len; size_t len;
len = strlen(str); len = strlen(str);
xfwrite(str, len, 1, file); xfwrite(str, len, 1, file);
@ -573,7 +573,7 @@ xvfprintf(xFILE *stream, const char *fmt, va_list ap)
} }
va_end(ap2); va_end(ap2);
return sizeof buf; return (int)(sizeof buf);
} }
} }