Skip to content

Commit

Permalink
Moved the declaration of tmpfd in main()
Browse files Browse the repository at this point in the history
Since tmpfd is only used if HAVE_MKSTEMPS is defined, I moved the declaration from the declaration area down to where it is being used directly, thus avoiding an unused-but-set-variable warning.
  • Loading branch information
Waldemar M authored Oct 18, 2017
1 parent d31c67f commit 98e3dd6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions jpegoptim.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* requires libjpeg (Independent JPEG Group's JPEG software
* release 6a or later...)
*
* $Id$
* $Id: b5d97f2a4d2b8196ca662c8dd0bedffb8d3fbe71 $
*/

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -56,7 +56,7 @@ struct my_error_mgr {
};
typedef struct my_error_mgr * my_error_ptr;

const char *rcsid = "$Id$";
const char *rcsid = "$Id: b5d97f2a4d2b8196ca662c8dd0bedffb8d3fbe71 $";


int verbose_mode = 0;
Expand Down Expand Up @@ -305,7 +305,7 @@ int main(int argc, char **argv)
char tmpfilename[MAXPATHLEN],tmpdir[MAXPATHLEN];
char newname[MAXPATHLEN], dest_path[MAXPATHLEN];
volatile int i;
int c,j, tmpfd, searchcount, searchdone;
int c,j, searchcount, searchdone;
int opt_index = 0;
long insize = 0, outsize = 0, lastsize = 0;
int oldquality;
Expand Down Expand Up @@ -828,14 +828,13 @@ int main(int argc, char **argv)
/* rely on mkstemps() to create us temporary file safely... */
snprintf(tmpfilename,sizeof(tmpfilename),
"%sjpegoptim-%d-%d.XXXXXX.tmp", tmpdir, (int)getuid(), (int)getpid());
if ((tmpfd = mkstemps(tmpfilename,4)) < 0)
if ((int tmpfd = mkstemps(tmpfilename,4)) < 0)
fatal("%s, error creating temp file %s: mkstemps() failed",(stdin_mode?"stdin":argv[i]),tmpfilename);
if ((outfile=fdopen(tmpfd,"wb"))==NULL)
#else
/* if platform is missing mkstemps(), try to create at least somewhat "safe" temp file... */
snprintf(tmpfilename,sizeof(tmpfilename),
"%sjpegoptim-%d-%d.%ld.tmp", tmpdir, (int)getuid(), (int)getpid(),(long)time(NULL));
tmpfd=0;
if ((outfile=fopen(tmpfilename,"wb"))==NULL)
#endif
fatal("error opening temporary file: %s",tmpfilename);
Expand Down

0 comments on commit 98e3dd6

Please sign in to comment.