abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
utilSignal.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "abc_global.h"
#include "utilSignal.h"
#include <unistd.h>

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START int Util_SignalSystem (const char *cmd)
 DECLARATIONS ///. More...
 
int tmpFile (const char *prefix, const char *suffix, char **out_name)
 
int Util_SignalTmpFile (const char *prefix, const char *suffix, char **out_name)
 INCLUDES ///. More...
 
void Util_SignalTmpFileRemove (const char *fname, int fLeave)
 

Function Documentation

int tmpFile ( const char *  prefix,
const char *  suffix,
char **  out_name 
)

Function*************************************************************

Synopsis [Opens a temporary file.]

Description [Opens a temporary file with given prefix and returns file descriptor (-1 on failure) and a string containing the name of the file (to be freed by caller).]

SideEffects []

SeeAlso []

Definition at line 89 of file utilFile.c.

90 {
91 #if defined(_MSC_VER) || defined(__MINGW32__)
92  int i, fd;
93  *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 27);
94  for (i = 0; i < 10; i++){
95  sprintf(*out_name, "%s%I64X%d%s", prefix, realTimeAbs(), _getpid(), suffix);
96  fd = _open(*out_name, O_CREAT | O_EXCL | O_BINARY | O_RDWR, _S_IREAD | _S_IWRITE);
97  if (fd == -1){
98  free(*out_name);
99  *out_name = NULL;
100  }
101  return fd;
102  }
103  assert(0); // -- could not open temporary file
104  return 0;
105 #else
106  int fd;
107  *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 7);
108  assert(*out_name != NULL);
109  sprintf(*out_name, "%sXXXXXX", prefix);
110  fd = mkstemp(*out_name);
111  if (fd == -1){
112  free(*out_name);
113  *out_name = NULL;
114  }else{
115  // Kludge:
116  close(fd);
117  unlink(*out_name);
118  strcat(*out_name, suffix);
119  fd = open(*out_name, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE);
120  if (fd == -1){
121  free(*out_name);
122  *out_name = NULL;
123  }
124  }
125  return fd;
126 #endif
127 }
char * malloc()
VOID_HACK free()
char * sprintf()
char * strcat()
static ABC_NAMESPACE_IMPL_START ABC_UINT64_T realTimeAbs()
DECLARATIONS ///.
Definition: utilFile.c:59
#define assert(ex)
Definition: util_old.h:213
int strlen()
ABC_NAMESPACE_IMPL_START int Util_SignalSystem ( const char *  cmd)

DECLARATIONS ///.

CFile****************************************************************

FileName [utilSignal.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName []

Synopsis []

Author [Baruch Sterin]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - February 1, 2011.]

Revision [

Id:
utilSignal.c,v 1.00 2011/02/01 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS ///

Definition at line 46 of file utilSignal.c.

47 {
48  return system(cmd);
49 }
int system()
int Util_SignalTmpFile ( const char *  prefix,
const char *  suffix,
char **  out_name 
)

INCLUDES ///.

CFile****************************************************************

FileName [utilSignal.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Signal handling utilities.]

Synopsis [Signal handling utilities.]

Author [Baruch Sterin]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - February 1, 2011.]

Revision [

Id:
utilSignal.h,v 1.00 2011/02/01 00:00:00 alanmi Exp

]PARAMETERS ///BASIC TYPES ///MACRO DEFINITIONS ///FUNCTION DECLARATIONS ///

Definition at line 53 of file utilSignal.c.

54 {
55  return tmpFile(prefix, suffix, out_name);
56 }
int tmpFile(const char *prefix, const char *suffix, char **out_name)
Definition: utilFile.c:89
void Util_SignalTmpFileRemove ( const char *  fname,
int  fLeave 
)

Definition at line 58 of file utilSignal.c.

59 {
60  if (! fLeave)
61  {
62  unlink(fname);
63  }
64 }