This is Unofficial EPICS BASE Doxygen Site
epicsTempFile.c File Reference
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "epicsTempFile.h"
+ Include dependency graph for epicsTempFile.c:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

LIBCOM_API FILE *epicsStdCall epicsTempFile ()
 Create and open a temporary file. More...
 

Function Documentation

LIBCOM_API FILE* epicsStdCall epicsTempFile ( void  )

Create and open a temporary file.

Returns
NULL or a FILE pointer to a temporary file.

Definition at line 28 of file epicsTempFile.c.

29 {
30  char * pName = _tempnam("c:\\tmp", "epics");
31  if (pName) {
32  /* We use open followed by fdopen so that the _O_EXCL
33  * flag can be used. This causes detection of a race
34  * condition where two programs end up receiving the
35  * same temporary file name.
36  *
37  * _O_CREAT create if non-existant
38  * _O_EXCL file must not exist
39  * _O_RDWR read and write the file
40  * _O_TEMPORARY delete file on close
41  * _O_BINARY no translation
42  * _O_SHORT_LIVED avoid flush to disk
43  */
44  int openFlag = _O_CREAT | _O_EXCL | _O_RDWR |
45  _O_SHORT_LIVED | _O_BINARY | _O_TEMPORARY;
46  int fd = open(pName, openFlag, _S_IWRITE);
47  FILE * pNewFile = 0;
48  if (fd >=0) {
49  pNewFile = _fdopen(fd, "w+b");
50  }
51  else {
52  printf("Temporary file \"%s\" open failed because "
53  "\"%s\"\n", pName, strerror(errno));
54  }
55  free(pName);
56  return pNewFile;
57  }
58  return 0;
59 }
#define printf
Definition: epicsStdio.h:41