Skip to content

Commit bf81968

Browse files
committed
getpid: use pid_t
1 parent 50799dc commit bf81968

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

include/ffilesystem.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#ifndef FFILESYSTEM_H
22
#define FFILESYSTEM_H
33

4+
#include <sys/types.h> // for pid_t
5+
#ifdef _WIN32
6+
#include <windef.h>
7+
#ifndef pid_t
8+
#define pid_t DWORD
9+
#endif
10+
#endif
11+
412
#ifdef __cplusplus
513

614
constexpr int fs_trace =
@@ -267,7 +275,7 @@ size_t fs_max_component(const char*);
267275

268276
bool fs_is_optimized();
269277

270-
int fs_getpid();
278+
pid_t fs_getpid();
271279

272280
char fs_pathsep();
273281
const char* fs_devnull();

src/c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ std::string::size_type fs_with_suffix(const char* path, const char* new_suffix,
378378
return {};
379379
}
380380

381-
int fs_getpid(){
381+
pid_t fs_getpid(){
382382
fs_print_error("", __func__, std::make_error_code(std::errc::function_not_supported));
383383
return -1;
384384
}

src/extra/uid.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
bool fs_is_admin(){
19-
// running as admin / root / superuser
19+
// is running as admin / root / superuser
2020
#if defined(_WIN32)
2121
HANDLE h = nullptr;
2222
TOKEN_ELEVATION elevation;
@@ -36,12 +36,16 @@ bool fs_is_admin(){
3636
}
3737

3838

39-
int fs_getpid()
39+
pid_t fs_getpid()
4040
{
41+
// get process ID
4142
#if defined(_WIN32)
42-
return static_cast<int>(GetCurrentProcessId());
43+
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocessid
44+
return GetCurrentProcessId();
4345
#else
44-
return static_cast<int>(getpid());
46+
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getpid.2.html
47+
// https://www.man7.org/linux/man-pages/man2/getpid.2.html
48+
return getpid();
4549
#endif
4650
}
4751

src/fortran/filesystem.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ integer(C_INT) function is_wsl() bind(C, name="fs_is_wsl")
112112
import
113113
end function
114114

115-
integer(C_INT) function fs_getpid() bind(C)
115+
integer(C_LONG) function fs_getpid() bind(C)
116116
!! process ID
117117
import
118118
end function

0 commit comments

Comments
 (0)