From: Ilia Alshanetsky Date: Thu, 13 Mar 2003 02:22:31 +0000 (+0000) Subject: Cleanup. X-Git-Tag: RELEASE_0_5~496 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6a02110b081fd5195d6f7a1436933e4b9563f66;p=php Cleanup. --- diff --git a/ext/gd/libgd/gd_io.c b/ext/gd/libgd/gd_io.c index 7cc49d28fd..9dbd1862a2 100644 --- a/ext/gd/libgd/gd_io.c +++ b/ext/gd/libgd/gd_io.c @@ -23,153 +23,124 @@ #define IO_DBG(s) +#define GD_IO_EOF_CHK(r) \ + if (r == EOF) { \ + return 0; \ + } \ + /* * Write out a word to the I/O context pointer */ -void -Putword (int w, gdIOCtx * ctx) +void Putword (int w, gdIOCtx * ctx) { - unsigned char buf[2]; - buf[0] = w & 0xff; - buf[1] = (w / 256) & 0xff; - (ctx->putBuf) (ctx, (char *) buf, 2); + unsigned char buf[2]; + + buf[0] = w & 0xff; + buf[1] = (w / 256) & 0xff; + (ctx->putBuf) (ctx, (char *) buf, 2); } -void -Putchar (int c, gdIOCtx * ctx) +void Putchar (int c, gdIOCtx * ctx) { - (ctx->putC) (ctx, c & 0xff); + (ctx->putC) (ctx, c & 0xff); } -void -gdPutC (const unsigned char c, gdIOCtx * ctx) +void gdPutC (const unsigned char c, gdIOCtx * ctx) { - (ctx->putC) (ctx, c); + (ctx->putC) (ctx, c); } -void -gdPutWord (int w, gdIOCtx * ctx) +void gdPutWord (int w, gdIOCtx * ctx) { - IO_DBG (printf ("Putting word...\n")); - (ctx->putC) (ctx, (unsigned char) (w >> 8)); - (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); - IO_DBG (printf ("put.\n")); + IO_DBG (php_gd_error("Putting word...\n")); + (ctx->putC) (ctx, (unsigned char) (w >> 8)); + (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); + IO_DBG (php_gd_error("put.\n")); } -void -gdPutInt (int w, gdIOCtx * ctx) +void gdPutInt (int w, gdIOCtx * ctx) { - IO_DBG (printf ("Putting int...\n")); - (ctx->putC) (ctx, (unsigned char) (w >> 24)); - (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF)); - (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF)); - (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); - IO_DBG (printf ("put.\n")); + IO_DBG (php_gd_error("Putting int...\n")); + (ctx->putC) (ctx, (unsigned char) (w >> 24)); + (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF)); + (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF)); + (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); + IO_DBG (php_gd_error("put.\n")); } -int -gdGetC (gdIOCtx * ctx) +int gdGetC (gdIOCtx * ctx) { - return ((ctx->getC) (ctx)); + return ((ctx->getC) (ctx)); } - - -int -gdGetByte (int *result, gdIOCtx * ctx) +int gdGetByte (int *result, gdIOCtx * ctx) { - int r; - r = (ctx->getC) (ctx); - if (r == EOF) - { - return 0; - } - *result = r; - return 1; + int r; + r = (ctx->getC) (ctx); + GD_IO_EOF_CHK(r); + *result = r; + return 1; } -int -gdGetWord (int *result, gdIOCtx * ctx) +int gdGetWord (int *result, gdIOCtx * ctx) { - int r; - r = (ctx->getC) (ctx); - if (r == EOF) - { - return 0; - } - *result = r << 8; - r = (ctx->getC) (ctx); - if (r == EOF) - { - return 0; - } - *result += r; - return 1; + int r; + r = (ctx->getC) (ctx); + GD_IO_EOF_CHK(r); + *result = r << 8; + r = (ctx->getC) (ctx); + GD_IO_EOF_CHK(r); + *result += r; + return 1; } -int -gdGetInt (int *result, gdIOCtx * ctx) +int gdGetInt (int *result, gdIOCtx * ctx) { - int r; - r = (ctx->getC) (ctx); - if (r == EOF) - { - return 0; - } - *result = r << 24; - - r = (ctx->getC) (ctx); - if (r == EOF) - { - return 0; - } - *result += r << 16; - - r = (ctx->getC) (ctx); - if (r == EOF) - { - return 0; - } - *result += r << 8; - - r = (ctx->getC) (ctx); - if (r == EOF) - { - return 0; - } - *result += r; - - return 1; + int r; + r = (ctx->getC) (ctx); + GD_IO_EOF_CHK(r); + *result = r << 24; + + r = (ctx->getC) (ctx); + GD_IO_EOF_CHK(r); + *result += r << 16; + + r = (ctx->getC) (ctx); + if (r == EOF) { + return 0; + } + *result += r << 8; + + r = (ctx->getC) (ctx); + GD_IO_EOF_CHK(r); + *result += r; + + return 1; } -int -gdPutBuf (const void *buf, int size, gdIOCtx * ctx) +int gdPutBuf (const void *buf, int size, gdIOCtx * ctx) { - IO_DBG (printf ("Putting buf...\n")); - return (ctx->putBuf) (ctx, buf, size); - IO_DBG (printf ("put.\n")); + IO_DBG (php_gd_error("Putting buf...\n")); + return (ctx->putBuf) (ctx, buf, size); + IO_DBG (php_gd_error("put.\n")); } -int -gdGetBuf (void *buf, int size, gdIOCtx * ctx) +int gdGetBuf (void *buf, int size, gdIOCtx * ctx) { - return (ctx->getBuf) (ctx, buf, size); + return (ctx->getBuf) (ctx, buf, size); } - -int -gdSeek (gdIOCtx * ctx, const int pos) +int gdSeek (gdIOCtx * ctx, const int pos) { - IO_DBG (printf ("Seeking...\n")); - return ((ctx->seek) (ctx, pos)); - IO_DBG (printf ("Done.\n")); + IO_DBG (php_gd_error("Seeking...\n")); + return ((ctx->seek) (ctx, pos)); + IO_DBG (php_gd_error("Done.\n")); } -long -gdTell (gdIOCtx * ctx) +long gdTell (gdIOCtx * ctx) { - IO_DBG (printf ("Telling...\n")); - return ((ctx->tell) (ctx)); - IO_DBG (printf ("told.\n")); + IO_DBG (php_gd_error("Telling...\n")); + return ((ctx->tell) (ctx)); + IO_DBG (php_gd_error ("told.\n")); } diff --git a/ext/gd/libgd/gd_io.h b/ext/gd/libgd/gd_io.h index c28379abd8..fdb68ac8a7 100644 --- a/ext/gd/libgd/gd_io.h +++ b/ext/gd/libgd/gd_io.h @@ -7,13 +7,13 @@ typedef struct gdIOCtx { int (*getC)(struct gdIOCtx*); int (*getBuf)(struct gdIOCtx*, void*, int); - void (*putC)(struct gdIOCtx*, int); + void (*putC)(struct gdIOCtx*, int); int (*putBuf)(struct gdIOCtx*, const void*, int); int (*seek)(struct gdIOCtx*, const int); long (*tell)(struct gdIOCtx*); - void (*gd_free)(struct gdIOCtx*); + void (*gd_free)(struct gdIOCtx*); } gdIOCtx; diff --git a/ext/gd/libgd/gd_io_dp.c b/ext/gd/libgd/gd_io_dp.c index 06c3ae80b6..8872afa213 100644 --- a/ext/gd/libgd/gd_io_dp.c +++ b/ext/gd/libgd/gd_io_dp.c @@ -27,25 +27,22 @@ /* this is used for creating images in main memory */ typedef struct dpStruct - { - void *data; - int logicalSize; - int realSize; - int dataGood; - int pos; - } -dynamicPtr; +{ + void *data; + int logicalSize; + int realSize; + int dataGood; + int pos; +} dynamicPtr; typedef struct dpIOCtx - { - gdIOCtx ctx; - dynamicPtr *dp; - } -dpIOCtx; +{ + gdIOCtx ctx; + dynamicPtr *dp; +} dpIOCtx; typedef struct dpIOCtx *dpIOCtxPtr; - /* these functions operate on in-memory dynamic pointers */ static int allocDynamic (dynamicPtr * dp, int initialSize, void *data); static int appendDynamic (dynamicPtr * dp, const void *src, int size); @@ -64,157 +61,126 @@ static int dynamicSeek (struct gdIOCtx *, const int); static long dynamicTell (struct gdIOCtx *); /* return data as a dynamic pointer */ -gdIOCtx * -gdNewDynamicCtx (int initialSize, void *data) +gdIOCtx * gdNewDynamicCtx (int initialSize, void *data) { - dpIOCtx *ctx; - dynamicPtr *dp; + dpIOCtx *ctx; + dynamicPtr *dp; - ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx)); - if (ctx == NULL) - { - return NULL; - } + ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx)); - dp = newDynamic (initialSize, data); - if (!dp) - { - gdFree (ctx); - return NULL; - }; + dp = newDynamic(initialSize, data); - ctx->dp = dp; + ctx->dp = dp; - ctx->ctx.getC = dynamicGetchar; - ctx->ctx.putC = dynamicPutchar; + ctx->ctx.getC = dynamicGetchar; + ctx->ctx.putC = dynamicPutchar; - ctx->ctx.getBuf = dynamicGetbuf; - ctx->ctx.putBuf = dynamicPutbuf; + ctx->ctx.getBuf = dynamicGetbuf; + ctx->ctx.putBuf = dynamicPutbuf; - ctx->ctx.seek = dynamicSeek; - ctx->ctx.tell = dynamicTell; + ctx->ctx.seek = dynamicSeek; + ctx->ctx.tell = dynamicTell; - ctx->ctx.gd_free = gdFreeDynamicCtx; + ctx->ctx.gd_free = gdFreeDynamicCtx; - return (gdIOCtx *) ctx; + return (gdIOCtx *) ctx; } -void * -gdDPExtractData (struct gdIOCtx *ctx, int *size) +void * gdDPExtractData (struct gdIOCtx *ctx, int *size) { - dynamicPtr *dp; - dpIOCtx *dctx; - void *data; - - dctx = (dpIOCtx *) ctx; - dp = dctx->dp; - - /* clean up the data block and return it */ - if (dp->dataGood) - { - trimDynamic (dp); - *size = dp->logicalSize; - data = dp->data; - } - else - { - *size = 0; - data = NULL; - if (dp->data != NULL) - { - gdFree (dp->data); + dynamicPtr *dp; + dpIOCtx *dctx; + void *data; + + dctx = (dpIOCtx *) ctx; + dp = dctx->dp; + + /* clean up the data block and return it */ + if (dp->dataGood) { + trimDynamic (dp); + *size = dp->logicalSize; + data = dp->data; + } else { + *size = 0; + data = NULL; + if (dp->data != NULL) { + gdFree(dp->data); + } } - } - dp->data = NULL; - dp->realSize = 0; - dp->logicalSize = 0; + dp->data = NULL; + dp->realSize = 0; + dp->logicalSize = 0; - return data; + return data; } -static -void -gdFreeDynamicCtx (struct gdIOCtx *ctx) +static void gdFreeDynamicCtx (struct gdIOCtx *ctx) { - dynamicPtr *dp; - dpIOCtx *dctx; - - dctx = (dpIOCtx *) ctx; - dp = dctx->dp; + dynamicPtr *dp; + dpIOCtx *dctx; - gdFree (ctx); + dctx = (dpIOCtx *) ctx; + dp = dctx->dp; - dp->realSize = 0; - dp->logicalSize = 0; + gdFree(ctx); - gdFree (dp); + dp->realSize = 0; + dp->logicalSize = 0; + gdFree(dp); } -static long -dynamicTell (struct gdIOCtx *ctx) +static long dynamicTell (struct gdIOCtx *ctx) { - dpIOCtx *dctx; + dpIOCtx *dctx; - dctx = (dpIOCtx *) ctx; - return (dctx->dp->pos); + dctx = (dpIOCtx *) ctx; + + return (dctx->dp->pos); } -static int -dynamicSeek (struct gdIOCtx *ctx, const int pos) +static int dynamicSeek (struct gdIOCtx *ctx, const int pos) { - int bytesNeeded; - dynamicPtr *dp; - dpIOCtx *dctx; + int bytesNeeded; + dynamicPtr *dp; + dpIOCtx *dctx; - dctx = (dpIOCtx *) ctx; - dp = dctx->dp; + dctx = (dpIOCtx *) ctx; + dp = dctx->dp; - if (!dp->dataGood) - return FALSE; + if (!dp->dataGood) { + return FALSE; + } - bytesNeeded = pos; - if (bytesNeeded > dp->realSize) - { - if (!gdReallocDynamic (dp, dp->realSize * 2)) - { - dp->dataGood = FALSE; - return FALSE; + bytesNeeded = pos; + if (bytesNeeded > dp->realSize) { + gdReallocDynamic (dp, dp->realSize * 2); } - } - /* if we get here, we can be sure that we have enough bytes - to copy safely */ + /* if we get here, we can be sure that we have enough bytes to copy safely */ - /* Extend the logical size if we seek beyond EOF. */ - if (pos > dp->logicalSize) - { - dp->logicalSize = pos; - }; + /* Extend the logical size if we seek beyond EOF. */ + if (pos > dp->logicalSize) { + dp->logicalSize = pos; + } - dp->pos = pos; + dp->pos = pos; - return TRUE; + return TRUE; } /* return data as a dynamic pointer */ -static dynamicPtr * -newDynamic (int initialSize, void *data) +static dynamicPtr * newDynamic (int initialSize, void *data) { - dynamicPtr *dp; - dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr)); - if (dp == NULL) - { - return NULL; - } + dynamicPtr *dp; + dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr)); - if (!allocDynamic (dp, initialSize, data)) - return NULL; + allocDynamic (dp, initialSize, data); - dp->pos = 0; + dp->pos = 0; - return dp; + return dp; } static int @@ -236,64 +202,53 @@ dynamicPutbuf (struct gdIOCtx *ctx, const void *buf, int size) } -static void -dynamicPutchar (struct gdIOCtx *ctx, int a) +static void dynamicPutchar (struct gdIOCtx *ctx, int a) { - unsigned char b; - dpIOCtxPtr dctx; + unsigned char b; + dpIOCtxPtr dctx; - b = a; - dctx = (dpIOCtxPtr) ctx; + b = a; + dctx = (dpIOCtxPtr) ctx; - appendDynamic (dctx->dp, &b, 1); + appendDynamic(dctx->dp, &b, 1); } -static int -dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len) +static int dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len) { - int rlen, remain; - dpIOCtxPtr dctx; - dynamicPtr *dp; - - dctx = (dpIOCtxPtr) ctx; - dp = dctx->dp; - - remain = dp->logicalSize - dp->pos; - if (remain >= len) - { - rlen = len; - } - else - { - if (remain == 0) - { - return EOF; + int rlen, remain; + dpIOCtxPtr dctx; + dynamicPtr *dp; + + dctx = (dpIOCtxPtr) ctx; + dp = dctx->dp; + + remain = dp->logicalSize - dp->pos; + if (remain >= len) { + rlen = len; + } else { + if (remain == 0) { + return EOF; + } + rlen = remain; } - rlen = remain; - } - memcpy (buf, (void *) ((char *) dp->data + dp->pos), rlen); - dp->pos += rlen; + memcpy(buf, (void *) ((char *) dp->data + dp->pos), rlen); + dp->pos += rlen; - return rlen; + return rlen; } -static int -dynamicGetchar (gdIOCtxPtr ctx) +static int dynamicGetchar (gdIOCtxPtr ctx) { - unsigned char b; - int rv; - - rv = dynamicGetbuf (ctx, &b, 1); - - if (rv != 1) - { - return EOF; - } - else - { - return b; /* (b & 0xff); */ - } + unsigned char b; + int rv; + + rv = dynamicGetbuf (ctx, &b, 1); + if (rv != 1) { + return EOF; + } else { + return b; /* (b & 0xff); */ + } } /* ********************************************************************* @@ -306,106 +261,81 @@ static int allocDynamic (dynamicPtr * dp, int initialSize, void *data) { - if (data == NULL) - { - dp->logicalSize = 0; - dp->dataGood = FALSE; - dp->data = gdMalloc (initialSize); - } - else - { - dp->logicalSize = initialSize; - dp->dataGood = TRUE; - dp->data = data; - } + if (data == NULL) { + dp->logicalSize = 0; + dp->dataGood = FALSE; + dp->data = gdMalloc(initialSize); + } else { + dp->logicalSize = initialSize; + dp->dataGood = TRUE; + dp->data = data; + } - if (dp->data != NULL) - { - dp->realSize = initialSize; - dp->dataGood = TRUE; - dp->pos = 0; - return TRUE; - } - else - { - dp->realSize = 0; - return FALSE; - } + dp->realSize = initialSize; + dp->dataGood = TRUE; + dp->pos = 0; + + return TRUE; } /* append bytes to the end of a dynamic pointer */ -static int -appendDynamic (dynamicPtr * dp, const void *src, int size) +static int appendDynamic (dynamicPtr * dp, const void *src, int size) { - int bytesNeeded; - char *tmp; + int bytesNeeded; + char *tmp; - if (!dp->dataGood) - return FALSE; + if (!dp->dataGood) { + return FALSE; + } -/* bytesNeeded = dp->logicalSize + size; */ - bytesNeeded = dp->pos + size; + /* bytesNeeded = dp->logicalSize + size; */ + bytesNeeded = dp->pos + size; - if (bytesNeeded > dp->realSize) - { - if (!gdReallocDynamic (dp, bytesNeeded * 2)) - { - dp->dataGood = FALSE; - return FALSE; + if (bytesNeeded > dp->realSize) { + gdReallocDynamic(dp, bytesNeeded * 2); } - } - /* if we get here, we can be sure that we have enough bytes - to copy safely */ - /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */ + /* if we get here, we can be sure that we have enough bytes to copy safely */ + /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */ - tmp = (char *) dp->data; - memcpy ((void *) (tmp + (dp->pos)), src, size); - dp->pos += size; + tmp = (char *) dp->data; + memcpy((void *) (tmp + (dp->pos)), src, size); + dp->pos += size; - if (dp->pos > dp->logicalSize) - { - dp->logicalSize = dp->pos; - }; + if (dp->pos > dp->logicalSize) { + dp->logicalSize = dp->pos; + } - return TRUE; + return TRUE; } /* grow (or shrink) dynamic pointer */ -static int -gdReallocDynamic (dynamicPtr * dp, int required) +static int gdReallocDynamic (dynamicPtr * dp, int required) { - void *newPtr; + void *newPtr; - /* First try gdRealloc(). If that doesn't work, make a new - memory block and copy. */ - if ((newPtr = gdRealloc (dp->data, required))) - { - dp->realSize = required; - dp->data = newPtr; - return TRUE; - } + /* First try gdRealloc(). If that doesn't work, make a new memory block and copy. */ + if ((newPtr = gdRealloc(dp->data, required))) { + dp->realSize = required; + dp->data = newPtr; + return TRUE; + } - /* create a new pointer */ - newPtr = gdMalloc (required); - if (!newPtr) - { - dp->dataGood = FALSE; - return FALSE; - } + /* create a new pointer */ + newPtr = gdMalloc(required); - /* copy the old data into it */ - memcpy (newPtr, dp->data, dp->logicalSize); - gdFree (dp->data); - dp->data = newPtr; + /* copy the old data into it */ + memcpy(newPtr, dp->data, dp->logicalSize); + gdFree(dp->data); + dp->data = newPtr; - dp->realSize = required; - return TRUE; + dp->realSize = required; + + return TRUE; } /* trim pointer so that its real and logical sizes match */ -static int -trimDynamic (dynamicPtr * dp) +static int trimDynamic (dynamicPtr * dp) { - return gdReallocDynamic (dp, dp->logicalSize); + return gdReallocDynamic(dp, dp->logicalSize); } diff --git a/ext/gd/libgd/gd_io_file.c b/ext/gd/libgd/gd_io_file.c index 713646120e..4544489890 100644 --- a/ext/gd/libgd/gd_io_file.c +++ b/ext/gd/libgd/gd_io_file.c @@ -29,11 +29,10 @@ /* this is used for creating images in main memory */ typedef struct fileIOCtx - { - gdIOCtx ctx; - FILE *f; - } -fileIOCtx; +{ + gdIOCtx ctx; + FILE *f; +} fileIOCtx; struct fileIOCtx *fileIOCtxPtr; @@ -49,97 +48,83 @@ static long fileTell (struct gdIOCtx *); static void gdFreeFileCtx (gdIOCtx * ctx); /* return data as a dynamic pointer */ -gdIOCtx * -gdNewFileCtx (FILE * f) +gdIOCtx * gdNewFileCtx (FILE * f) { - fileIOCtx *ctx; + fileIOCtx *ctx; - ctx = (fileIOCtx *) gdMalloc (sizeof (fileIOCtx)); - if (ctx == NULL) - { - return NULL; - } + ctx = (fileIOCtx *) gdMalloc(sizeof (fileIOCtx)); - ctx->f = f; + ctx->f = f; - ctx->ctx.getC = fileGetchar; - ctx->ctx.putC = filePutchar; + ctx->ctx.getC = fileGetchar; + ctx->ctx.putC = filePutchar; - ctx->ctx.getBuf = fileGetbuf; - ctx->ctx.putBuf = filePutbuf; + ctx->ctx.getBuf = fileGetbuf; + ctx->ctx.putBuf = filePutbuf; - ctx->ctx.tell = fileTell; - ctx->ctx.seek = fileSeek; + ctx->ctx.tell = fileTell; + ctx->ctx.seek = fileSeek; - ctx->ctx.gd_free = gdFreeFileCtx; + ctx->ctx.gd_free = gdFreeFileCtx; - return (gdIOCtx *) ctx; + return (gdIOCtx *) ctx; } -static -void -gdFreeFileCtx (gdIOCtx * ctx) +static void gdFreeFileCtx (gdIOCtx * ctx) { - gdFree (ctx); + gdFree(ctx); } -static int -filePutbuf (gdIOCtx * ctx, const void *buf, int size) +static int filePutbuf (gdIOCtx * ctx, const void *buf, int size) { - fileIOCtx *fctx; - fctx = (fileIOCtx *) ctx; + fileIOCtx *fctx; + 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 (gdIOCtx * ctx, void *buf, int size) { - fileIOCtx *fctx; - fctx = (fileIOCtx *) ctx; - - return (fread (buf, 1, size, fctx->f)); + fileIOCtx *fctx; + fctx = (fileIOCtx *) ctx; + return fread(buf, 1, size, fctx->f); } -static void -filePutchar (gdIOCtx * ctx, int a) +static void filePutchar (gdIOCtx * ctx, int a) { - unsigned char b; - fileIOCtx *fctx; - fctx = (fileIOCtx *) ctx; + unsigned char b; + fileIOCtx *fctx; + fctx = (fileIOCtx *) ctx; - b = a; + b = a; - putc (b, fctx->f); + putc (b, fctx->f); } -static int -fileGetchar (gdIOCtx * ctx) +static int fileGetchar (gdIOCtx * ctx) { - fileIOCtx *fctx; - fctx = (fileIOCtx *) ctx; + fileIOCtx *fctx; + fctx = (fileIOCtx *) ctx; - return getc (fctx->f); + return getc (fctx->f); } -static int -fileSeek (struct gdIOCtx *ctx, const int pos) +static int fileSeek (struct gdIOCtx *ctx, const int pos) { - fileIOCtx *fctx; - fctx = (fileIOCtx *) ctx; + fileIOCtx *fctx; + 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 (struct gdIOCtx *ctx) { - fileIOCtx *fctx; - fctx = (fileIOCtx *) ctx; + fileIOCtx *fctx; + fctx = (fileIOCtx *) ctx; - return ftell (fctx->f); + return ftell (fctx->f); } diff --git a/ext/gd/libgd/gd_io_ss.c b/ext/gd/libgd/gd_io_ss.c index dd96fdfa45..15ab18d9bb 100644 --- a/ext/gd/libgd/gd_io_ss.c +++ b/ext/gd/libgd/gd_io_ss.c @@ -30,12 +30,11 @@ /* this is used for creating images in main memory */ typedef struct ssIOCtx - { - gdIOCtx ctx; - gdSourcePtr src; - gdSinkPtr snk; - } -ssIOCtx; +{ + gdIOCtx ctx; + gdSourcePtr src; + gdSinkPtr snk; +} ssIOCtx; typedef struct ssIOCtx *ssIOCtxPtr; @@ -48,118 +47,92 @@ static void sinkPutchar (gdIOCtx * ctx, int a); static void gdFreeSsCtx (gdIOCtx * ctx); /* return data as a dynamic pointer */ -gdIOCtx * -gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk) +gdIOCtx * gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk) { - ssIOCtxPtr ctx; + ssIOCtxPtr ctx; - ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx)); - if (ctx == NULL) - { - return NULL; - } + ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx)); - ctx->src = src; - ctx->snk = snk; + ctx->src = src; + ctx->snk = snk; - ctx->ctx.getC = sourceGetchar; - ctx->ctx.getBuf = sourceGetbuf; + ctx->ctx.getC = sourceGetchar; + ctx->ctx.getBuf = sourceGetbuf; - ctx->ctx.putC = sinkPutchar; - ctx->ctx.putBuf = sinkPutbuf; + ctx->ctx.putC = sinkPutchar; + ctx->ctx.putBuf = sinkPutbuf; - ctx->ctx.tell = NULL; - ctx->ctx.seek = NULL; + ctx->ctx.tell = NULL; + ctx->ctx.seek = NULL; - ctx->ctx.gd_free = gdFreeSsCtx; + ctx->ctx.gd_free = gdFreeSsCtx; - return (gdIOCtx *) ctx; + return (gdIOCtx *) ctx; } -static -void -gdFreeSsCtx (gdIOCtx * ctx) +static void gdFreeSsCtx (gdIOCtx * ctx) { - gdFree (ctx); + gdFree(ctx); } -static int -sourceGetbuf (gdIOCtx * ctx, void *buf, int size) +static int sourceGetbuf (gdIOCtx * ctx, void *buf, int size) { - ssIOCtx *lctx; - int res; - - lctx = (ssIOCtx *) ctx; + ssIOCtx *lctx; + int res; - res = ((lctx->src->source) (lctx->src->context, buf, size)); + lctx = (ssIOCtx *) ctx; -/* - ** Translate the return values from the Source object: - ** 0 is EOF, -1 is error - */ + res = ((lctx->src->source) (lctx->src->context, buf, size)); - if (res == 0) - { - return EOF; - } - else if (res < 0) - { - return 0; - } - else - { - return res; - }; + /* + * Translate the return values from the Source object: + * 0 is EOF, -1 is error + */ + if (res == 0) { + return EOF; + } else if (res < 0) { + return 0; + } else { + return res; + } } -static int -sourceGetchar (gdIOCtx * ctx) +static int sourceGetchar (gdIOCtx * ctx) { - int res; - unsigned char buf; + int res; + unsigned char buf; - res = sourceGetbuf (ctx, &buf, 1); - - if (res == 1) - { - return buf; - } - else - { - return EOF; - }; + res = sourceGetbuf (ctx, &buf, 1); + if (res == 1) { + return buf; + } else { + return EOF; + } } -static int -sinkPutbuf (gdIOCtx * ctx, const void *buf, int size) +static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size) { - ssIOCtxPtr lctx; - int res; - - lctx = (ssIOCtx *) ctx; + ssIOCtxPtr lctx; + int res; - res = (lctx->snk->sink) (lctx->snk->context, buf, size); + lctx = (ssIOCtx *) ctx; - if (res <= 0) - { - return 0; - } - else - { - return res; - }; + res = (lctx->snk->sink) (lctx->snk->context, buf, size); + if (res <= 0) { + return 0; + } else { + return res; + } } -static void -sinkPutchar (gdIOCtx * ctx, int a) +static void sinkPutchar (gdIOCtx * ctx, int a) { - unsigned char b; - - b = a; - sinkPutbuf (ctx, &b, 1); + unsigned char b; + b = a; + sinkPutbuf (ctx, &b, 1); }