diff --git a/djpeg.c b/djpeg.c index b30a5e43..dfd6d900 100644 --- a/djpeg.c +++ b/djpeg.c @@ -647,7 +647,7 @@ main(int argc, char **argv) fprintf(stderr, "%s: memory allocation failure\n", progname); exit(EXIT_FAILURE); } - nbytes = JFREAD(input_file, &inbuffer[insize], INPUT_BUF_SIZE); + nbytes = fread(&inbuffer[insize], 1, INPUT_BUF_SIZE, input_file); if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) { if (file_index < argc) fprintf(stderr, "%s: can't read from %s\n", progname, diff --git a/jdatadst.c b/jdatadst.c index fe8c0543..6b4fed23 100644 --- a/jdatadst.c +++ b/jdatadst.c @@ -111,7 +111,7 @@ empty_output_buffer(j_compress_ptr cinfo) { my_dest_ptr dest = (my_dest_ptr)cinfo->dest; - if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != + if (fwrite(dest->buffer, 1, OUTPUT_BUF_SIZE, dest->outfile) != (size_t)OUTPUT_BUF_SIZE) ERREXIT(cinfo, JERR_FILE_WRITE); @@ -170,7 +170,7 @@ term_destination(j_compress_ptr cinfo) /* Write any data remaining in the buffer */ if (datacount > 0) { - if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) + if (fwrite(dest->buffer, 1, datacount, dest->outfile) != datacount) ERREXIT(cinfo, JERR_FILE_WRITE); } fflush(dest->outfile); diff --git a/jdatasrc.c b/jdatasrc.c index eadb4a2c..e36a30d8 100644 --- a/jdatasrc.c +++ b/jdatasrc.c @@ -5,7 +5,7 @@ * Copyright (C) 1994-1996, Thomas G. Lane. * Modified 2009-2011 by Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2013, 2016, D. R. Commander. + * Copyright (C) 2013, 2016, 2022, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -104,7 +104,7 @@ fill_input_buffer(j_decompress_ptr cinfo) my_src_ptr src = (my_src_ptr)cinfo->src; size_t nbytes; - nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); + nbytes = fread(src->buffer, 1, INPUT_BUF_SIZE, src->infile); if (nbytes <= 0) { if (src->start_of_file) /* Treat empty input file as fatal error */ diff --git a/jinclude.h b/jinclude.h index 23248767..6ed982d3 100644 --- a/jinclude.h +++ b/jinclude.h @@ -34,14 +34,3 @@ #include #include #include - -/* - * The modules that use fread() and fwrite() always invoke them through - * these macros. On some systems you may need to twiddle the argument casts. - * CAUTION: argument order is different from underlying functions! - */ - -#define JFREAD(file, buf, sizeofbuf) \ - ((size_t)fread((void *)(buf), (size_t)1, (size_t)(sizeofbuf), (file))) -#define JFWRITE(file, buf, sizeofbuf) \ - ((size_t)fwrite((const void *)(buf), (size_t)1, (size_t)(sizeofbuf), (file))) diff --git a/rdbmp.c b/rdbmp.c index 0124f4d2..433ebe2e 100644 --- a/rdbmp.c +++ b/rdbmp.c @@ -39,7 +39,7 @@ typedef unsigned char U_CHAR; #define ReadOK(file, buffer, len) \ - (JFREAD(file, buffer, len) == ((size_t)(len))) + (fread(buffer, 1, len, file) == ((size_t)(len))) static int alpha_index[JPEG_NUMCS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 diff --git a/rdgif.c b/rdgif.c index 36f0929f..bdf74012 100644 --- a/rdgif.c +++ b/rdgif.c @@ -5,7 +5,7 @@ * Copyright (C) 1991-1997, Thomas G. Lane. * Modified 2019 by Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2021, D. R. Commander. + * Copyright (C) 2021-2022, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -45,7 +45,7 @@ typedef unsigned char U_CHAR; #define ReadOK(file, buffer, len) \ - (JFREAD(file, buffer, len) == ((size_t)(len))) + (fread(buffer, 1, len, file) == ((size_t)(len))) #define MAXCOLORMAPSIZE 256 /* max # of colors in a GIF colormap */ diff --git a/rdppm.c b/rdppm.c index 439eefb6..409497d6 100644 --- a/rdppm.c +++ b/rdppm.c @@ -48,7 +48,7 @@ typedef unsigned char U_CHAR; #define ReadOK(file, buffer, len) \ - (JFREAD(file, buffer, len) == ((size_t)(len))) + (fread(buffer, 1, len, file) == ((size_t)(len))) static int alpha_index[JPEG_NUMCS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 diff --git a/rdtarga.c b/rdtarga.c index 8f2d0316..3ed7eb34 100644 --- a/rdtarga.c +++ b/rdtarga.c @@ -5,7 +5,7 @@ * Copyright (C) 1991-1996, Thomas G. Lane. * Modified 2017 by Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2018, 2021, D. R. Commander. + * Copyright (C) 2018, 2021-2022, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -33,7 +33,7 @@ typedef unsigned char U_CHAR; #define ReadOK(file, buffer, len) \ - (JFREAD(file, buffer, len) == ((size_t)(len))) + (fread(buffer, 1, len, file) == ((size_t)(len))) /* Private version of data source object */ diff --git a/wrbmp.c b/wrbmp.c index 56a53a44..45fff684 100644 --- a/wrbmp.c +++ b/wrbmp.c @@ -165,7 +165,7 @@ put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, *outptr++ = 0; if (!dest->use_inversion_array) - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->row_width); + fwrite(dest->iobuffer, 1, dest->row_width, dest->pub.output_file); } METHODDEF(void) @@ -200,7 +200,7 @@ put_gray_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, *outptr++ = 0; if (!dest->use_inversion_array) - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->row_width); + fwrite(dest->iobuffer, 1, dest->row_width, dest->pub.output_file); } @@ -281,9 +281,9 @@ write_bmp_header(j_decompress_ptr cinfo, bmp_dest_ptr dest) PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */ /* we leave biClrImportant = 0 */ - if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t)14) + if (fwrite(bmpfileheader, 1, 14, dest->pub.output_file) != (size_t)14) ERREXIT(cinfo, JERR_FILE_WRITE); - if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t)40) + if (fwrite(bmpinfoheader, 1, 40, dest->pub.output_file) != (size_t)40) ERREXIT(cinfo, JERR_FILE_WRITE); if (cmap_entries > 0) @@ -342,9 +342,9 @@ write_os2_header(j_decompress_ptr cinfo, bmp_dest_ptr dest) PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */ PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */ - if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t)14) + if (fwrite(bmpfileheader, 1, 14, dest->pub.output_file) != (size_t)14) ERREXIT(cinfo, JERR_FILE_WRITE); - if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t)12) + if (fwrite(bmpcoreheader, 1, 12, dest->pub.output_file) != (size_t)12) ERREXIT(cinfo, JERR_FILE_WRITE); if (cmap_entries > 0) @@ -456,7 +456,7 @@ finish_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) ((j_common_ptr)cinfo, dest->whole_image, row - 1, (JDIMENSION)1, FALSE); data_ptr = image_ptr[0]; - (void)JFWRITE(outfile, data_ptr, dest->row_width); + fwrite(data_ptr, 1, dest->row_width, outfile); } if (progress != NULL) progress->completed_extra_passes++; diff --git a/wrgif.c b/wrgif.c index bac672c6..620a3ba9 100644 --- a/wrgif.c +++ b/wrgif.c @@ -114,8 +114,8 @@ flush_packet(gif_dest_ptr dinfo) { if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */ dinfo->packetbuf[0] = (char)dinfo->bytesinpkt++; - if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt) != - (size_t)dinfo->bytesinpkt) + if (fwrite(dinfo->packetbuf, 1, dinfo->bytesinpkt, + dinfo->pub.output_file) != (size_t)dinfo->bytesinpkt) ERREXIT(dinfo->cinfo, JERR_FILE_WRITE); dinfo->bytesinpkt = 0; } diff --git a/wrppm.c b/wrppm.c index ffa4f89e..57c8aaff 100644 --- a/wrppm.c +++ b/wrppm.c @@ -92,7 +92,7 @@ put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, { ppm_dest_ptr dest = (ppm_dest_ptr)dinfo; - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } @@ -121,7 +121,7 @@ copy_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, PUTPPMSAMPLE(bufferptr, *ptr++); } #endif - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } @@ -149,7 +149,7 @@ put_rgb(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied) PUTPPMSAMPLE(bufferptr, ptr[bindex]); ptr += ps; } - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } @@ -175,7 +175,7 @@ put_cmyk(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, PUTPPMSAMPLE(bufferptr, g); PUTPPMSAMPLE(bufferptr, b); } - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } @@ -205,7 +205,7 @@ put_demapped_rgb(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, PUTPPMSAMPLE(bufferptr, color_map1[pixval]); PUTPPMSAMPLE(bufferptr, color_map2[pixval]); } - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } @@ -224,7 +224,7 @@ put_demapped_gray(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, for (col = cinfo->output_width; col > 0; col--) { PUTPPMSAMPLE(bufferptr, color_map[*ptr++]); } - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } diff --git a/wrtarga.c b/wrtarga.c index 57c6a2ff..67ca1f00 100644 --- a/wrtarga.c +++ b/wrtarga.c @@ -79,7 +79,7 @@ write_header(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors) } } - if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t)18) + if (fwrite(targaheader, 1, 18, dinfo->output_file) != (size_t)18) ERREXIT(cinfo, JERR_FILE_WRITE); } @@ -107,7 +107,7 @@ put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, outptr[2] = inptr[0]; inptr += 3, outptr += 3; } - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } METHODDEF(void) @@ -122,7 +122,7 @@ put_gray_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, inptr = dest->pub.buffer[0]; outptr = dest->iobuffer; memcpy(outptr, inptr, cinfo->output_width); - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); } @@ -146,7 +146,7 @@ put_demapped_gray(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, for (col = cinfo->output_width; col > 0; col--) { *outptr++ = color_map0[*inptr++]; } - (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file); }