Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abc
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
abc
Commits
573694f9
Commit
573694f9
authored
Feb 13, 2011
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing g++ compilation issue for tmpFile().
parent
8cc7b438
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
44 deletions
+29
-44
src/misc/util/utilFile.c
+29
-44
No files found.
src/misc/util/utilFile.c
View file @
573694f9
...
...
@@ -25,6 +25,14 @@
#include <fcntl.h>
#include <sys/stat.h>
#if defined(_MSC_VER)
#include <Windows.h>
#include <process.h>
#include <io.h>
#else
#include <unistd.h>
#endif
#include "abc_global.h"
ABC_NAMESPACE_IMPL_START
...
...
@@ -33,12 +41,6 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
#if defined(_MSC_VER)
#include <Windows.h>
#include <process.h>
#include <io.h>
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
...
...
@@ -56,6 +58,7 @@ ABC_NAMESPACE_IMPL_START
***********************************************************************/
static
ABC_UINT64_T
realTimeAbs
()
// -- absolute time in nano-seconds
{
#if defined(_MSC_VER)
LARGE_INTEGER
f
,
t
;
double
realTime_freq
;
int
ok
;
...
...
@@ -65,20 +68,16 @@ static ABC_UINT64_T realTimeAbs() // -- absolute time in nano-seconds
ok
=
QueryPerformanceCounter
(
&
t
);
assert
(
ok
);
return
(
ABC_UINT64_T
)(
__int64
)(((
__int64
)(((
ABC_UINT64_T
)
t
.
LowPart
|
((
ABC_UINT64_T
)
t
.
HighPart
<<
32
)))
*
realTime_freq
*
1000000000
));
}
#endif
// 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).
}
/**Function*************************************************************
Synopsis []
Synopsis [
Opens a temporary file.
]
Description []
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 []
...
...
@@ -87,9 +86,22 @@ static ABC_UINT64_T realTimeAbs() // -- absolute time in nano-seconds
***********************************************************************/
int
tmpFile
(
const
char
*
prefix
,
const
char
*
suffix
,
char
**
out_name
)
{
#if !defined(_MSC_VER)
#if defined(_MSC_VER)
int
i
,
fd
;
*
out_name
=
(
char
*
)
malloc
(
strlen
(
prefix
)
+
strlen
(
suffix
)
+
27
);
for
(
i
=
0
;
i
<
10
;
i
++
){
sprintf
(
*
out_name
,
"%s%I64X%d%s"
,
prefix
,
realTimeAbs
(),
_getpid
(),
suffix
);
fd
=
_open
(
*
out_name
,
O_CREAT
|
O_EXCL
|
O_BINARY
|
O_RDWR
,
_S_IREAD
|
_S_IWRITE
);
if
(
fd
==
-
1
){
free
(
*
out_name
);
*
out_name
=
NULL
;
}
return
fd
;
}
assert
(
0
);
// -- could not open temporary file
return
0
;
#else
int
fd
;
*
out_name
=
(
char
*
)
malloc
(
strlen
(
prefix
)
+
strlen
(
suffix
)
+
7
);
assert
(
*
out_name
!=
NULL
);
sprintf
(
*
out_name
,
"%sXXXXXX"
,
prefix
);
...
...
@@ -98,7 +110,6 @@ int tmpFile(const char* prefix, const char* suffix, char** out_name)
free
(
*
out_name
);
*
out_name
=
NULL
;
}
else
{
// Kludge:
close
(
fd
);
unlink
(
*
out_name
);
...
...
@@ -108,35 +119,11 @@ int tmpFile(const char* prefix, const char* suffix, char** out_name)
free
(
*
out_name
);
*
out_name
=
NULL
;
}
// assert( 0 );
// commented out because had problem with g++ saying that
// close() and unlink() are not defined in the namespace
}
return
fd
;
#else
int
i
,
fd
;
*
out_name
=
(
char
*
)
malloc
(
strlen
(
prefix
)
+
strlen
(
suffix
)
+
27
);
for
(
i
=
0
;
i
<
10
;
i
++
){
sprintf
(
*
out_name
,
"%s%I64X%d%s"
,
prefix
,
realTimeAbs
(),
_getpid
(),
suffix
);
fd
=
_open
(
*
out_name
,
O_CREAT
|
O_EXCL
|
O_BINARY
|
O_RDWR
,
_S_IREAD
|
_S_IWRITE
);
if
(
fd
==
-
1
){
free
(
*
out_name
);
*
out_name
=
NULL
;
}
return
fd
;
}
assert
(
0
);
// -- could not open temporary file
return
0
;
#endif
}
//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
/**Function*************************************************************
Synopsis []
...
...
@@ -165,8 +152,6 @@ int main(int argc, char** argv)
}
*/
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment