FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lpython/src/lpython/utils.cpp at main · caguerra/lpython · GitHub
caguerra
/
lpython
Public
forked from
lcompilers/lpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
lpython
/
src
/
lpython
/
utils.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
106 lines (91 loc) · 2.51 KB
Breadcrumbs
lpython
/
src
/
lpython
/
utils.cpp
Copy path
File metadata and controls
106 lines (91 loc) · 2.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
ifdef
_WIN32
#
ifndef
NOMINMAX
#
define
NOMINMAX
#
endif
//
NOMINMAX
#
include
<
windows.h
>
#
endif
#
include
<
fstream
>
#
include
<
bin/tpl/whereami/whereami.h
>
#
include
<
libasr/exception.h
>
#
include
<
lpython/utils.h
>
#
include
<
libasr/string_utils.h
>
#
include
<
sys/types.h
>
#
include
<
sys/stat.h
>
#
ifndef
_WIN32
#
include
<
unistd.h
>
#
endif
#
ifdef
_WIN32
#
define
stat
_stat
#
if
!defined S_ISDIR
#
define
S_ISDIR
(
m
) (((m) & _S_IFDIR) == _S_IFDIR)
#
endif
#
endif
namespace
LFortran
{
void
get_executable_path
(std::string &executable_path,
int
&dirname_length)
{
#
ifdef
HAVE_WHEREAMI
int
length;
length =
wai_getExecutablePath
(
NULL
,
0
, &dirname_length);
if
(length >
0
) {
std::string
path
(length+
1
,
'
\0
'
);
wai_getExecutablePath
(&path[
0
], length, &dirname_length);
executable_path = path;
if
(executable_path[executable_path.
size
()-
1
] ==
'
\0
'
) {
executable_path = executable_path.
substr
(
0
,executable_path.
size
()-
1
);
}
}
else
{
throw
LCompilersException
(
"
Cannot determine executable path.
"
);
}
#
else
executable_path =
"
src/bin/lpython.js
"
;
dirname_length =
7
;
#
endif
}
std::string
get_runtime_library_dir
()
{
char
*env_p =
std::getenv
(
"
LFORTRAN_RUNTIME_LIBRARY_DIR
"
);
if
(env_p)
return
env_p;
std::string path;
int
dirname_length;
get_executable_path
(path, dirname_length);
std::string dirname = path.
substr
(
0
,dirname_length);
if
(
endswith
(dirname,
"
src/bin
"
)
||
endswith
(dirname,
"
src
\\
bin
"
)
||
endswith
(dirname,
"
SRC
\\
BIN
"
)) {
//
Development version
return
dirname +
"
/../runtime
"
;
}
else
if
(
endswith
(dirname,
"
src/lpython/tests
"
) ||
endswith
(
to_lower
(dirname),
"
src
\\
lpython
\\
tests
"
)) {
//
CTest Tests
return
dirname +
"
/../../runtime
"
;
}
else
{
//
Installed version
return
dirname +
"
/../share/lpython/lib
"
;
}
}
std::string
get_runtime_library_header_dir
()
{
char
*env_p =
std::getenv
(
"
LFORTRAN_RUNTIME_LIBRARY_HEADER_DIR
"
);
if
(env_p)
return
env_p;
return
get_runtime_library_dir
() +
"
/impure
"
;
}
bool
is_directory
(std::string path) {
struct
stat
buffer;
if
(
stat
(path.
c_str
(), &buffer) ==
0
) {
if
(
S_ISDIR
(buffer.
st_mode
)) {
return
true
;
}
else
{
return
false
;
}
}
return
false
;
}
bool
path_exists
(std::string path) {
struct
stat
buffer;
if
(
stat
(path.
c_str
(), &buffer) ==
0
) {
return
true
;
}
else
{
return
false
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL