ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
utilSignal.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "abc_global.h"
#include "utilSignal.h"
#include <unistd.h>
Include dependency graph for utilSignal.c:

Go to the source code of this file.

Functions

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

Function Documentation

◆ tmpFile()

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 106 of file utilFile.c.

107{
108#if defined(_MSC_VER) || defined(__MINGW32__)
109 int i, fd;
110 *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 27);
111 for (i = 0; i < 10; i++){
112 sprintf(*out_name, "%s%I64X%d%s", prefix, realTimeAbs(), _getpid(), suffix);
113 fd = _open(*out_name, O_CREAT | O_EXCL | O_BINARY | O_RDWR, _S_IREAD | _S_IWRITE);
114 if (fd == -1){
115 free(*out_name);
116 *out_name = NULL;
117 }
118 return fd;
119 }
120 assert(0); // -- could not open temporary file
121 return 0;
122#elif defined(__wasm)
123 static int seq = 0; // no risk of collision since we're in a sandbox
124 int fd;
125 *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 9);
126 sprintf(*out_name, "%s%08d%s", prefix, seq++, suffix);
127 fd = open(*out_name, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE);
128 if (fd == -1){
129 free(*out_name);
130 *out_name = NULL;
131 }
132 return fd;
133#else
134 int fd;
135 *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 7);
136 assert(*out_name != NULL);
137 sprintf(*out_name, "%sXXXXXX", prefix);
138 fd = mkstemp(*out_name);
139 if (fd == -1){
140 free(*out_name);
141 *out_name = NULL;
142 }else{
143 // Kludge:
144 close(fd);
145 unlink(*out_name);
146 strcat(*out_name, suffix);
147 fd = open(*out_name, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE);
148 if (fd == -1){
149 free(*out_name);
150 *out_name = NULL;
151 }
152 }
153 return fd;
154#endif
155}
#define assert(ex)
Definition util_old.h:213
int strlen()
char * sprintf()
VOID_HACK free()
char * strcat()
char * malloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Util_SignalSystem()

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 44 of file utilSignal.c.

45{
46#if defined(__wasm)
47 return -1;
48#else
49 return system(cmd);
50#endif
51}
int system()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Util_SignalTmpFile()

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 55 of file utilSignal.c.

56{
57 return tmpFile(prefix, suffix, out_name);
58}
int tmpFile(const char *prefix, const char *suffix, char **out_name)
Definition utilFile.c:106
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Util_SignalTmpFileRemove()

void Util_SignalTmpFileRemove ( const char * fname,
int fLeave )

Definition at line 60 of file utilSignal.c.

61{
62 if (! fLeave)
63 {
64 unlink(fname);
65 }
66}
Here is the caller graph for this function: