gd_io_file.c (libgd-2.3.2) | : | gd_io_file.c (libgd-2.3.3) | ||
---|---|---|---|---|
skipping to change at line 40 | skipping to change at line 40 | |||
#include "gdhelpers.h" | #include "gdhelpers.h" | |||
/* this is used for creating images in main memory */ | /* this is used for creating images in main memory */ | |||
typedef struct fileIOCtx { | typedef struct fileIOCtx { | |||
gdIOCtx ctx; | gdIOCtx ctx; | |||
FILE *f; | FILE *f; | |||
} | } | |||
fileIOCtx; | fileIOCtx; | |||
gdIOCtx *newFileCtx(FILE *f); | gdIOCtxPtr newFileCtx(FILE *f); | |||
static int fileGetbuf(gdIOCtx *, void *, int); | static int fileGetbuf(gdIOCtxPtr, void *, int); | |||
static int filePutbuf(gdIOCtx *, const void *, int); | static int filePutbuf(gdIOCtxPtr, const void *, int); | |||
static void filePutchar(gdIOCtx *, int); | static void filePutchar(gdIOCtxPtr, int); | |||
static int fileGetchar(gdIOCtx *ctx); | static int fileGetchar(gdIOCtxPtr ctx); | |||
static int fileSeek(struct gdIOCtx *, const int); | static int fileSeek(gdIOCtxPtr, const int); | |||
static long fileTell(struct gdIOCtx *); | static long fileTell(gdIOCtxPtr); | |||
static void gdFreeFileCtx(gdIOCtx *ctx); | static void gdFreeFileCtx(gdIOCtxPtr ctx); | |||
/* | /* | |||
Function: gdNewFileCtx | Function: gdNewFileCtx | |||
Return data as a dynamic pointer. | Return data as a dynamic pointer. | |||
*/ | */ | |||
BGD_DECLARE(gdIOCtx *) gdNewFileCtx(FILE *f) | BGD_DECLARE(gdIOCtxPtr) gdNewFileCtx(FILE *f) | |||
{ | { | |||
fileIOCtx *ctx; | fileIOCtx *ctx; | |||
if (f == NULL) return NULL; | if (f == NULL) return NULL; | |||
ctx = (fileIOCtx *)gdMalloc(sizeof(fileIOCtx)); | ctx = (fileIOCtx *)gdMalloc(sizeof(fileIOCtx)); | |||
if(ctx == NULL) { | if(ctx == NULL) { | |||
return NULL; | return NULL; | |||
} | } | |||
ctx->f = f; | ctx->f = f; | |||
skipping to change at line 79 | skipping to change at line 79 | |||
ctx->ctx.putC = filePutchar; | ctx->ctx.putC = filePutchar; | |||
ctx->ctx.getBuf = fileGetbuf; | ctx->ctx.getBuf = fileGetbuf; | |||
ctx->ctx.putBuf = filePutbuf; | ctx->ctx.putBuf = filePutbuf; | |||
ctx->ctx.tell = fileTell; | ctx->ctx.tell = fileTell; | |||
ctx->ctx.seek = fileSeek; | ctx->ctx.seek = fileSeek; | |||
ctx->ctx.gd_free = gdFreeFileCtx; | ctx->ctx.gd_free = gdFreeFileCtx; | |||
return (gdIOCtx *)ctx; | return (gdIOCtxPtr)ctx; | |||
} | } | |||
static void gdFreeFileCtx(gdIOCtx *ctx) | static void gdFreeFileCtx(gdIOCtxPtr ctx) | |||
{ | { | |||
gdFree(ctx); | gdFree(ctx); | |||
} | } | |||
static int filePutbuf(gdIOCtx *ctx, const void *buf, int size) | static int filePutbuf(gdIOCtxPtr ctx, const void *buf, int size) | |||
{ | { | |||
fileIOCtx *fctx; | fileIOCtx *fctx; | |||
fctx = (fileIOCtx *)ctx; | fctx = (fileIOCtx *)ctx; | |||
return fwrite(buf, 1, size, fctx->f); | return fwrite(buf, 1, size, fctx->f); | |||
} | } | |||
static int fileGetbuf(gdIOCtx *ctx, void *buf, int size) | static int fileGetbuf(gdIOCtxPtr ctx, void *buf, int size) | |||
{ | { | |||
fileIOCtx *fctx; | fileIOCtx *fctx; | |||
fctx = (fileIOCtx *)ctx; | fctx = (fileIOCtx *)ctx; | |||
return (fread(buf, 1, size, fctx->f)); | return (fread(buf, 1, size, fctx->f)); | |||
} | } | |||
static void filePutchar(gdIOCtx *ctx, int a) | static void filePutchar(gdIOCtxPtr ctx, int a) | |||
{ | { | |||
unsigned char b; | unsigned char b; | |||
fileIOCtx *fctx; | fileIOCtx *fctx; | |||
fctx = (fileIOCtx *)ctx; | fctx = (fileIOCtx *)ctx; | |||
b = a; | b = a; | |||
putc(b, fctx->f); | putc(b, fctx->f); | |||
} | } | |||
static int fileGetchar(gdIOCtx *ctx) | static int fileGetchar(gdIOCtxPtr ctx) | |||
{ | { | |||
fileIOCtx *fctx; | fileIOCtx *fctx; | |||
fctx = (fileIOCtx *)ctx; | fctx = (fileIOCtx *)ctx; | |||
return getc(fctx->f); | return getc(fctx->f); | |||
} | } | |||
static int fileSeek(struct gdIOCtx *ctx, const int pos) | static int fileSeek(gdIOCtxPtr ctx, const int pos) | |||
{ | { | |||
fileIOCtx *fctx; | fileIOCtx *fctx; | |||
fctx = (fileIOCtx *)ctx; | fctx = (fileIOCtx *)ctx; | |||
return (fseek(fctx->f, pos, SEEK_SET) == 0); | return (fseek(fctx->f, pos, SEEK_SET) == 0); | |||
} | } | |||
static long fileTell (struct gdIOCtx *ctx) | static long fileTell(gdIOCtxPtr ctx) | |||
{ | { | |||
fileIOCtx *fctx; | fileIOCtx *fctx; | |||
fctx = (fileIOCtx *)ctx; | fctx = (fileIOCtx *)ctx; | |||
return ftell(fctx->f); | return ftell(fctx->f); | |||
} | } | |||
End of changes. 11 change blocks. | ||||
18 lines changed or deleted | 18 lines changed or added |