Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for setitimer() on platforms lacking it
Implementation includes getitimer(), but for now it is static. Supports ITIMER_REAL only. We may need a separate compatibility header file for ITIMER_* and struct itimerval, but add only the prototype in git-compat-util.h for now, as the initial motivatin of this change, HP NonStop, has ITIMER_* and struct timeval in <sys/time>. Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
1 parent
fab4b04
commit 55c96a1
Showing
2 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "../git-compat-util.h" | ||
|
||
static int git_getitimer(int which, struct itimerval *value) | ||
{ | ||
int ret = 0; | ||
|
||
switch (which) { | ||
case ITIMER_REAL: | ||
value->it_value.tv_usec = 0; | ||
value->it_value.tv_sec = alarm(0); | ||
ret = 0; /* if alarm() fails, we get a SIGLIMIT */ | ||
break; | ||
case ITIMER_VIRTUAL: /* FALLTHRU */ | ||
case ITIMER_PROF: errno = ENOTSUP; ret = -1; break; | ||
default: errno = EINVAL; ret = -1; | ||
} | ||
return ret; | ||
} | ||
|
||
int git_setitimer(int which, const struct itimerval *value, | ||
struct itimerval *ovalue) | ||
{ | ||
int ret = 0; | ||
|
||
if (!value | ||
|| value->it_value.tv_usec < 0 | ||
|| value->it_value.tv_usec > 1000000 | ||
|| value->it_value.tv_sec < 0) { | ||
errno = EINVAL; | ||
return -1; | ||
} | ||
|
||
else if (ovalue) | ||
if (!git_getitimer(which, ovalue)) | ||
return -1; /* errno set in git_getitimer() */ | ||
|
||
else | ||
switch (which) { | ||
case ITIMER_REAL: | ||
alarm(value->it_value.tv_sec + | ||
(value->it_value.tv_usec > 0) ? 1 : 0); | ||
ret = 0; /* if alarm() fails, we get a SIGLIMIT */ | ||
break; | ||
case ITIMER_VIRTUAL: /* FALLTHRU */ | ||
case ITIMER_PROF: errno = ENOTSUP; ret = -1; break; | ||
default: errno = EINVAL; ret = -1; | ||
} | ||
|
||
return ret; | ||
} |
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