Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
python-RAT/cpp/RAT/coder_posix_time.c at pybind_demo · RascalSoftware/python-RAT · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
RascalSoftware
/
python-RAT
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
3
Code
Issues
3
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
pybind_demo
Breadcrumbs
python-RAT
/
cpp
/
RAT
/
coder_posix_time.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
162 lines (147 loc) · 4.82 KB
pybind_demo
Breadcrumbs
python-RAT
/
cpp
/
RAT
/
coder_posix_time.c
Copy path
Top
File metadata and controls
Code
Blame
162 lines (147 loc) · 4.82 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* MATLAB Coder time APIs */
/* Copyright 2020-2022 The MathWorks, Inc. */
/* Sort out the defines early before any headers are included
* to avoid includes with inconsistent defines
*/
#if
(!defined(
CODER_WINAPI
))
&&
(defined(
_WIN32
))
#define
CODER_WINAPI
#endif
/* Ensure we get the right _POSIX_C_SOURCE and isolate our define to just this C file */
#if
!defined(
CODER_WINAPI
)
#undef
_POSIX_C_SOURCE
#if
defined(
__QNX__
)
/* QNX wants a newer POSIX version to make CLOCK_MONOTONIC available */
#define
_POSIX_C_SOURCE
200112L
#else
#define
_POSIX_C_SOURCE
199309L
#endif
/* defined(__QNX__) */
#endif
/* !defined(CODER_WINAPI) */
#ifdef
CODER_WINAPI
#define
NOMINMAX
#include
<windows.h>
#endif
/* CODER_WINAPI */
#include
"coder_posix_time.h"
#include
<math.h>
#include
<stdlib.h>
#include
<time.h>
/* Prototypes */
#ifndef
CODER_WINAPI
/**
* @brief Convert coderTimeSpec to POSIX timespec
*
*/
static
void
coderToPOSIXTimespec
(
coderTimespec
const
*
const
aCoderTimespec
,
struct
timespec
*
const
aTimespec
);
/**
* @brief Convert POSIX timespec to coderTimeSpec
*
*/
static
void
posixToCoderTimespec
(
const
struct
timespec
*
const
aTimespec
,
coderTimespec
*
const
aCoderTimespec
);
static
void
coderToPOSIXTimespec
(
coderTimespec
const
*
const
aCoderTimespec
,
struct
timespec
*
const
aTimespec
) {
aTimespec
->
tv_sec
=
(
time_t
)(
aCoderTimespec
->
tv_sec
);
aTimespec
->
tv_nsec
=
(
long
)(
aCoderTimespec
->
tv_nsec
);
}
static
void
posixToCoderTimespec
(
const
struct
timespec
*
const
aTimespec
,
coderTimespec
*
const
aCoderTimespec
) {
aCoderTimespec
->
tv_sec
=
(
double
)(
aTimespec
->
tv_sec
);
aCoderTimespec
->
tv_nsec
=
(
double
)(
aTimespec
->
tv_nsec
);
}
#endif
/* CODER_WINAPI */
int
coderInitTimeFunctions
(
double
*
const
aFrequency
) {
#ifdef
CODER_WINAPI
LARGE_INTEGER
freqL
;
int
status
;
status
=
QueryPerformanceFrequency
(
&
freqL
);
*
aFrequency
=
(
double
)
freqL
.
QuadPart
;
/* Invert status since in Windows, 0 means failure */
return
status
==
0
;
#else
*
aFrequency
=
0.0
;
return
0
;
#endif
}
int
coderTimeClockGettimeMonotonic
(
coderTimespec
*
const
aCoderTimespec
,
double
aFrequency
) {
#ifdef
CODER_WINAPI
static
const
double
BILLION
=
1e9
;
LARGE_INTEGER
timeL
;
double
timeDouble
,
timeRemainder
,
seconds
,
nanoseconds
;
BOOL
status
=
QueryPerformanceCounter
(
&
timeL
);
timeDouble
=
(
double
)
timeL
.
QuadPart
;
timeRemainder
=
fmod
(
timeDouble
,
aFrequency
);
seconds
=
(
timeDouble
-
timeRemainder
) /
aFrequency
;
nanoseconds
=
(
timeRemainder
*
BILLION
) /
aFrequency
;
aCoderTimespec
->
tv_sec
=
seconds
;
aCoderTimespec
->
tv_nsec
=
nanoseconds
;
/* Invert status since in Windows, 0 means failure */
return
status
==
0
;
#else
struct
timespec
tspec
;
int
status
;
(
void
)
aFrequency
;
status
=
clock_gettime
(
CLOCK_MONOTONIC
,
&
tspec
);
posixToCoderTimespec
(
&
tspec
,
aCoderTimespec
);
return
status
;
#endif
/* defined(_WIN32) || defined(WIN32) */
}
int
coderTimeSleep
(
coderTimespec
const
*
const
aCoderTimespec
) {
#ifdef
CODER_WINAPI
/* WIndows */
static
const
double
MILLI
=
1e3
;
static
const
double
BILLION
=
1e9
;
double
delayMilli
,
delay
;
DWORD
delayUint32
;
delayMilli
=
floor
(
aCoderTimespec
->
tv_nsec
/ (
BILLION
/
MILLI
));
delay
=
MILLI
*
aCoderTimespec
->
tv_sec
+
delayMilli
;
delayUint32
=
(
DWORD
)
ceil
(
delay
);
Sleep
(
delayUint32
);
return
0
;
#else
/* POSIX */
struct
timespec
ts
;
coderToPOSIXTimespec
(
aCoderTimespec
,
&
ts
);
return
nanosleep
(
&
ts
,
NULL
);
#endif
}
int
coderLocalTime
(
coderTm
*
const
aTm
) {
#ifdef
CODER_WINAPI
/* WIndows */
SYSTEMTIME
sysTime
;
TIME_ZONE_INFORMATION
tzInfo
;
DWORD
dstInfo
;
GetLocalTime
(
&
sysTime
);
aTm
->
tm_nsec
=
((
long
)
sysTime
.
wMilliseconds
)
*
1000000
;
aTm
->
tm_sec
=
sysTime
.
wSecond
;
aTm
->
tm_min
=
sysTime
.
wMinute
;
aTm
->
tm_hour
=
sysTime
.
wHour
;
aTm
->
tm_mday
=
sysTime
.
wDay
;
aTm
->
tm_mon
=
sysTime
.
wMonth
;
aTm
->
tm_year
=
sysTime
.
wYear
;
aTm
->
tm_wday
=
0
;
aTm
->
tm_yday
=
0
;
dstInfo
=
GetTimeZoneInformation
(
&
tzInfo
);
aTm
->
tm_isdst
=
dstInfo
==
TIME_ZONE_ID_DAYLIGHT
;
return
0
;
#else
/* POSIX */
struct
timespec
ts
;
struct
tm
*
tmVal
;
int
status
;
const
int
YEAR_OFFSET
=
1900
;
/* +1900 for human year */
const
int
MONTH_OFFSET
=
1
;
/* +1 for 1-based month */
status
=
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
tmVal
=
localtime
(
&
ts
.
tv_sec
);
aTm
->
tm_nsec
=
ts
.
tv_nsec
;
aTm
->
tm_sec
=
tmVal
->
tm_sec
;
aTm
->
tm_min
=
tmVal
->
tm_min
;
aTm
->
tm_hour
=
tmVal
->
tm_hour
;
aTm
->
tm_mday
=
tmVal
->
tm_mday
;
aTm
->
tm_mon
=
tmVal
->
tm_mon
+
MONTH_OFFSET
;
aTm
->
tm_year
=
tmVal
->
tm_year
+
YEAR_OFFSET
;
aTm
->
tm_wday
=
tmVal
->
tm_wday
;
aTm
->
tm_yday
=
tmVal
->
tm_yday
;
aTm
->
tm_isdst
=
tmVal
->
tm_isdst
;
return
status
;
#endif
}
You can’t perform that action at this time.