Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
into-cpp-fmi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Into-cps
github-into-cps
into-cpp-fmi
Commits
e3ffafb5
Commit
e3ffafb5
authored
7 years ago
by
Kenneth Lausdahl
Browse files
Options
Downloads
Patches
Plain Diff
windows tewaks
parent
e0719bd3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/FilesystemUtil.cpp
+25
-27
25 additions, 27 deletions
src/FilesystemUtil.cpp
with
25 additions
and
27 deletions
src/FilesystemUtil.cpp
+
25
−
27
View file @
e3ffafb5
...
...
@@ -7,12 +7,10 @@
#include
"FilesystemUtil.h"
bool
isDirExist
(
const
std
::
string
&
path
)
{
bool
isDirExist
(
const
std
::
string
&
path
)
{
#if defined(_WIN32)
struct
_stat
info
;
if
(
_stat
(
path
.
c_str
(),
&
info
)
!=
0
)
{
if
(
_stat
(
path
.
c_str
(),
&
info
)
!=
0
)
{
return
false
;
}
return
(
info
.
st_mode
&
_S_IFDIR
)
!=
0
;
...
...
@@ -26,9 +24,9 @@ bool isDirExist(const std::string& path)
#endif
}
bool
makePath
(
const
std
::
string
&
path
)
{
bool
makePath
(
const
std
::
string
&
path
)
{
#if defined(_WIN32)
printf
(
"Making dir: %s
\n
"
,
path
.
c_str
());
int
ret
=
_mkdir
(
path
.
c_str
());
#else
mode_t
mode
=
0755
;
...
...
@@ -37,8 +35,7 @@ bool makePath(const std::string& path)
if
(
ret
==
0
)
return
true
;
switch
(
errno
)
{
switch
(
errno
)
{
case
ENOENT
:
// parent didn't exist, try to create it
{
...
...
@@ -46,13 +43,13 @@ bool makePath(const std::string& path)
if
(
pos
==
std
::
string
::
npos
)
#if defined(_WIN32)
pos
=
path
.
find_last_of
(
'\\'
);
if
(
pos
==
std
::
string
::
npos
)
if
(
pos
==
std
::
string
::
npos
)
#endif
return
false
;
if
(
!
makePath
(
path
.
substr
(
0
,
pos
)))
if
(
!
makePath
(
path
.
substr
(
0
,
pos
)))
{
return
false
;
}
// now, try to create again
}
}
// now, try to create again
#if defined(_WIN32)
return
0
==
_mkdir
(
path
.
c_str
());
#else
...
...
@@ -68,8 +65,7 @@ bool makePath(const std::string& path)
}
}
bool
removePath
(
const
std
::
string
&
path
)
{
bool
removePath
(
const
std
::
string
&
path
)
{
if
(
path
.
size
()
<
1
||
!
isDirExist
(
path
))
return
false
;
#if defined(_WIN32)
...
...
@@ -82,8 +78,7 @@ bool removePath(const std::string& path)
#endif
}
shared_ptr
<
string
>
getTempDir
()
{
shared_ptr
<
string
>
getTempDir
()
{
#if defined(_WIN32)
#define BUFSIZE 512
...
...
@@ -92,7 +87,7 @@ shared_ptr<string> getTempDir()
DWORD
dwRetVal
,
dwRetVal2
;
DWORD
dwBytesRead
;
DWORD
dwBytesWritten
;
DWORD
dwBufSize
=
BUFSIZE
;
DWORD
dwBufSize
=
BUFSIZE
;
UINT
uRetVal
;
char
szTempName
[
BUFSIZE
];
char
buffer
[
BUFSIZE
];
...
...
@@ -100,23 +95,26 @@ shared_ptr<string> getTempDir()
BOOL
fSuccess
;
dwRetVal
=
GetTempPath
(
dwBufSize
,
// length of the buffer
lpPathBuffer
);
// buffer for path
if
(
dwRetVal
>
dwBufSize
||
(
dwRetVal
==
0
))
{
lpPathBuffer
);
// buffer for path
if
(
dwRetVal
>
dwBufSize
||
(
dwRetVal
==
0
))
{
return
NULL
;
}
// Create a temporary file.
uRetVal
=
GetTempFileName
(
lpPathBuffer
,
// directory for tmp files
"fmu-"
,
// temp file name prefix
0
,
// create unique name
szTempName
);
// buffer for name
if
(
uRetVal
==
0
)
{
uRetVal
=
GetTempFileName
(
lpPathBuffer
,
// directory for tmp files
"fmu-"
,
// temp file name prefix
0
,
// create unique name
szTempName
);
// buffer for name
if
(
uRetVal
==
0
)
{
return
NULL
;
}
return
make_shared
<
string
>
(
szTempName
);
//string s(szTempName);
//std::replace( s.begin(), s.end(), 'x', 'y');
auto
str
=
make_shared
<
string
>
(
szTempName
);
str
->
erase
(
std
::
remove
(
str
->
begin
(),
str
->
end
(),
'.'
),
str
->
end
());
return
str
;
#else
char
template_name
[]
=
"/tmp/fmu-XXXXXX"
;
char
*
name
=
mkdtemp
(
template_name
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment