Remove epicsTempName() routine

It's unsafe and generates obnoxious warnings on modern compilers.
This also replaces internal useage with epicsTempFile().
There appears to be no external code that calls this routine.
This commit is contained in:
Eric Norum
2018-12-14 11:38:31 -06:00
committed by Andrew Johnson
parent 84b7612036
commit 6201d37756
7 changed files with 35 additions and 88 deletions
+3 -11
View File
@@ -98,7 +98,6 @@ int num_backtracking, bol_needed;
FILE *temp_action_file;
FILE *backtrack_file;
int end_of_buffer_state;
char action_file_name[256>L_tmpnam?256:L_tmpnam];
char **input_files;
int num_input_files;
char *program_name;
@@ -210,10 +209,7 @@ void flexend(int status)
else if ( fclose( temp_action_file ) )
flexfatal( "error occurred when closing temporary action file" );
else if ( unlink( action_file_name ) )
flexfatal( "error occurred when deleting temporary action file" );
}
}
if ( status != 0 && outfile_created )
{
@@ -598,15 +594,11 @@ get_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */
if ( (skelfile = fopen( skelname, "r" )) == NULL )
lerrsf( "can't open skeleton file %s", skelname );
epicsTempName ( action_file_name, sizeof ( action_file_name ) );
if ( action_file_name[0] == '\0' )
if ( ( temp_action_file = epicsTempFile () ) == NULL )
{
lerrsf( "can't create temporary file name", "" );
lerrsf( "can't create temporary action file", "" );
}
if ( ( temp_action_file = fopen ( action_file_name, "w" ) ) == NULL )
lerrsf( "can't open temporary action file %s", action_file_name );
lastdfa = lastnfa = num_rules = numas = numsnpairs = tmpuses = 0;
numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0;
numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
-2
View File
@@ -350,7 +350,6 @@ extern int yymore_really_used, reject_really_used;
* temp_action_file - temporary file to hold actions
* backtrack_file - file to summarize backtracking states to
* infilename - name of input file
* action_file_name - name of the temporary file
* input_files - array holding names of input files
* num_input_files - size of input_files array
* program_name - name with which program was invoked
@@ -359,7 +358,6 @@ extern int yymore_really_used, reject_really_used;
extern int datapos, dataline, linenum;
extern FILE *skelfile, *yyin, *temp_action_file, *backtrack_file;
extern char *infilename;
extern char action_file_name[];
extern char **input_files;
extern int num_input_files;
extern char *program_name;
+2 -7
View File
@@ -1164,13 +1164,8 @@ void make_tables(void)
if ( ferror( temp_action_file ) )
flexfatal( "error occurred when writing temporary action file" );
else if ( fclose( temp_action_file ) )
flexfatal( "error occurred when closing temporary action file" );
temp_action_file = fopen( action_file_name, "r" );
if ( temp_action_file == NULL )
flexfatal( "could not re-open temporary action file" );
else if ( fseek( temp_action_file, 0L, SEEK_SET) != 0 )
flexfatal( "error occurred when rewinding temporary action file" );
/* copy prolog from action_file to output file */
action_out();
+30 -31
View File
@@ -27,7 +27,6 @@
*/
epicsShareFunc enum TF_RETURN truncateFile (const char *pFileName, unsigned long size)
{
char tmpName[256>L_tmpnam?256:L_tmpnam];
long filePos;
FILE *pFile;
FILE *ptmp;
@@ -67,18 +66,10 @@ epicsShareFunc enum TF_RETURN truncateFile (const char *pFileName, unsigned lon
return TF_OK;
}
epicsTempName ( tmpName, sizeof (tmpName) );
if ( tmpName[0] == '\0' ) {
fprintf (stderr,"Unable to create tmp file name?\n");
fclose (pFile);
return TF_ERROR;
}
ptmp = fopen (tmpName, "w");
ptmp = epicsTempFile();
if (!ptmp) {
fprintf (stderr,
"File access problems to `%s' because `%s'\n",
tmpName,
"File access problems to temp file because `%s'\n",
strerror(errno));
fclose (pFile);
return TF_ERROR;
@@ -89,48 +80,56 @@ epicsShareFunc enum TF_RETURN truncateFile (const char *pFileName, unsigned lon
c = getc (pFile);
if (c==EOF) {
fprintf (stderr,
"File access problems to `%s' because `%s'\n",
pFileName,
"File access problems to temp file because `%s'\n",
strerror(errno));
fclose (pFile);
fclose (ptmp);
remove (tmpName);
return TF_ERROR;
}
status = putc (c, ptmp);
if (status==EOF) {
fprintf(stderr,
"File access problems to `%s' because `%s'\n",
tmpName,
"File access problems to temp file because `%s'\n",
strerror(errno));
fclose (pFile);
fclose (ptmp);
remove (tmpName);
return TF_ERROR;
}
charNo++;
}
fclose (pFile);
fclose (ptmp);
status = remove (pFileName);
if (status!=TF_OK) {
pFile = fopen(pFileName, "w");
if (!pFile) {
fprintf (stderr,
"Unable to remove `%s' during truncate because `%s'\n",
"File access problems to `%s' because `%s'\n",
pFileName,
strerror(errno));
remove (tmpName);
fclose (ptmp);
return TF_ERROR;
}
status = rename (tmpName, pFileName);
if (status!=TF_OK) {
fprintf (stderr,
"Unable to rename %s to `%s' because `%s'\n",
tmpName,
pFileName,
strerror(errno));
remove (tmpName);
return TF_ERROR;
rewind (ptmp);
while ((c = getc (ptmp)) != EOF) {
if (ferror(ptmp)) {
fprintf (stderr,
"File access problems to temp file because `%s'\n",
strerror(errno));
fclose (pFile);
fclose (ptmp);
return TF_ERROR;
}
status = putc (c, pFile);
if (status==EOF) {
fprintf(stderr,
"File access problems to `%s' because `%s'\n",
pFileName,
strerror(errno));
fclose (pFile);
fclose (ptmp);
return TF_ERROR;
}
}
fclose(ptmp);
fclose(pFile);
return TF_OK;
}
-1
View File
@@ -20,7 +20,6 @@
extern "C" {
#endif
epicsShareFunc void epicsShareAPI epicsTempName(char *pbuf, size_t bufLen);
epicsShareFunc FILE * epicsShareAPI epicsTempFile(void);
#ifdef __cplusplus
-22
View File
@@ -21,28 +21,6 @@
#define epicsExportSharedSymbols
#include "epicsTempFile.h"
//
// epicsTempName
//
// allow the teporary file directory to be set with the
// TMP environment varianble
//
extern "C"
epicsShareFunc void epicsShareAPI epicsTempName (
char * pNameBuf, size_t nameBufLength )
{
if ( nameBufLength ) {
pNameBuf[0] = '\0';
char * pName = _tempnam ( "c:\\tmp", "epics" );
if ( pName ) {
if ( nameBufLength > strlen ( pName ) ) {
strncpy ( pNameBuf, pName, nameBufLength );
}
free ( pName );
}
}
}
//
// epicsTmpFile
//
-14
View File
@@ -14,20 +14,6 @@
#include "epicsTempFile.h"
extern "C"
epicsShareFunc void epicsShareAPI epicsTempName (
char * pNameBuf, size_t nameBufLength )
{
if ( nameBufLength ) {
pNameBuf[0] = '\0';
char nameBuf[L_tmpnam];
if ( tmpnam ( nameBuf ) ) {
if ( nameBufLength > strlen ( nameBuf ) ) {
strncpy ( pNameBuf, nameBuf, nameBufLength );
}
}
}
}
extern "C"
epicsShareFunc FILE * epicsShareAPI epicsTempFile ( void )