fixed temp file creation issues on win32

This commit is contained in:
Jeff Hill
2004-04-27 17:39:25 +00:00
parent d844c2dd61
commit b76257a0d6
11 changed files with 91 additions and 82 deletions
+13 -14
View File
@@ -15,7 +15,7 @@
#include <limits.h>
#define epicsExportSharedSymbols
#include "truncateFile.h"
#include "epicsStdio.h"
#ifndef SEEK_END
#define SEEK_END 2
@@ -27,9 +27,8 @@
*/
epicsShareFunc enum TF_RETURN epicsShareAPI truncateFile (const char *pFileName, unsigned size)
{
char tmpName[L_tmpnam];
char tmpName[256>L_tmpnam?256:L_tmpnam];
long filePos;
char *pTmpFN;
FILE *pFile;
FILE *ptmp;
int status;
@@ -68,18 +67,18 @@ epicsShareFunc enum TF_RETURN epicsShareAPI truncateFile (const char *pFileName
return TF_OK;
}
pTmpFN = tmpnam (tmpName);
if (!pTmpFN) {
epicsTempName ( tmpName, sizeof (tmpName) );
if ( tmpName[0] == '\0' ) {
fprintf (stderr,"Unable to create tmp file name?\n");
fclose (pFile);
return TF_ERROR;
}
ptmp = fopen (pTmpFN, "w");
ptmp = fopen (tmpName, "w");
if (!ptmp) {
fprintf (stderr,
"File access problems to `%s' because `%s'\n",
pTmpFN,
tmpName,
strerror(errno));
fclose (pFile);
return TF_ERROR;
@@ -95,18 +94,18 @@ epicsShareFunc enum TF_RETURN epicsShareAPI truncateFile (const char *pFileName
strerror(errno));
fclose (pFile);
fclose (ptmp);
remove (pTmpFN);
remove (tmpName);
return TF_ERROR;
}
status = putc (c, ptmp);
if (status==EOF) {
fprintf(stderr,
"File access problems to `%s' because `%s'\n",
pTmpFN,
tmpName,
strerror(errno));
fclose (pFile);
fclose (ptmp);
remove (pTmpFN);
remove (tmpName);
return TF_ERROR;
}
charNo++;
@@ -119,17 +118,17 @@ epicsShareFunc enum TF_RETURN epicsShareAPI truncateFile (const char *pFileName
"Unable to remove `%s' during truncate because `%s'\n",
pFileName,
strerror(errno));
remove (pTmpFN);
remove (tmpName);
return TF_ERROR;
}
status = rename (pTmpFN, pFileName);
status = rename (tmpName, pFileName);
if (status!=TF_OK) {
fprintf (stderr,
"Unable to rename %s to `%s' because `%s'\n",
pTmpFN,
tmpName,
pFileName,
strerror(errno));
remove (pTmpFN);
remove (tmpName);
return TF_ERROR;
}
return TF_OK;
-35
View File
@@ -1,35 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#include "shareLib.h"
/*
* truncate to specified size (we dont use truncate()
* because it is not portable)
*
* pFileName - name (and optionally path) of file
* size - the new file size (if file is curretly larger)
*
* returns TF_OK if the file is less than size bytes
* or if it was successfully truncated. Returns
* TF_ERROR if the file could not be truncated.
*/
#ifdef __cplusplus
extern "C" {
#endif
enum TF_RETURN {TF_OK=0, TF_ERROR=1};
epicsShareFunc enum TF_RETURN epicsShareAPI truncateFile (const char *pFileName, unsigned size);
#ifdef __cplusplus
}
#endif