-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I've created the new files src/compat/compat.{hc}. These are available to all binaries by adding src to the include directories, and src/compat/compat.c to the sources. Several functions are implemented here which one or more target operating systems are missing, right now all related to time. This includes clock_nanosleep(), which is missing on OS X and DragonFly BSD. Eliminate the other three definitions of timespec_to_ns() and friends. Standardize on NANOSECS_IN_SEC rather than the more opaque GIG. Progress on #1121.
- Loading branch information
1 parent
e7d0b18
commit 8283adc
Showing
15 changed files
with
99 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef __linux__ | ||
#ifndef __FreeBSD__ | ||
#include <time.h> | ||
// clock_nanosleep is unavailable on DragonFly BSD and Mac OS X | ||
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *request, | ||
struct timespec *remain){ | ||
struct timespec now; | ||
if(clock_gettime(clockid, &now)){ | ||
return -1; | ||
} | ||
uint64_t nowns = timespec_to_ns(&now); | ||
uint64_t targns = timespec_to_ns(&request); | ||
if(flags != TIMER_ABSTIME){ | ||
targns += nowns; | ||
} | ||
if(nowns < targns){ | ||
uint64_t waitns = targns - nowns; | ||
struct timespec waitts = { | ||
.tv_sec = waitns / 1000000000, | ||
.tv_nsec = waitns % 1000000000, | ||
}; | ||
return nanosleep(&waitts, remain); | ||
} | ||
return 0; | ||
|
||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef NOTCURSES_COMPAT | ||
#define NOTCURSES_COMPAT | ||
|
||
#include <time.h> | ||
|
||
#define NANOSECS_IN_SEC 1000000000ul | ||
|
||
static inline uint64_t | ||
timespec_to_ns(const struct timespec* ts){ | ||
return ts->tv_sec * NANOSECS_IN_SEC + ts->tv_nsec; | ||
} | ||
|
||
static inline struct timespec* | ||
ns_to_timespec(uint64_t ns, struct timespec* ts){ | ||
ts->tv_sec = ns / NANOSECS_IN_SEC; | ||
ts->tv_nsec = ns % NANOSECS_IN_SEC; | ||
return ts; | ||
} | ||
|
||
// compatibility wrappers for code available only on certain operating systems. | ||
// this file is not installed, but only consumed during compilation. if we're | ||
// on an operating system which implements a given function, it won't be built. | ||
int clock_nanosleep(clockid_t clockid, int flags, | ||
const struct timespec *request, | ||
struct timespec *remain); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.