Skip to content

Commit

Permalink
Merge pull request #224 from N-R-K/sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
N-R-K authored Mar 17, 2023
2 parents a12d23f + 612cba7 commit f1b195f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/scrot.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,32 @@ static Imlib_Image scrotGrabAutoselect(void)
return im;
}

/* similar to sleep, but deals with EINTR.
* ideally, we'd want to sleep against an absolute time to prevent any drift
* but clock_nanosleep doesn't seem to be widely implemented.
*/
static void scrotSleep(int sec)
{
assert(sec > 0);
struct timespec delay = { .tv_sec = sec };
while (nanosleep(&delay, &delay) < 0 && errno == EINTR);
}

void scrotDoDelay(void)
{
if (opt.delay) {
if (opt.countdown) {
int i;

printf("Taking shot in %d.. ", opt.delay);
fflush(stdout);
sleep(1);
dprintf(STDERR_FILENO, "Taking shot in %d.. ", opt.delay);
scrotSleep(1);
for (i = opt.delay - 1; i > 0; i--) {
printf("%d.. ", i);
fflush(stdout);
sleep(1);
dprintf(STDERR_FILENO, "%d.. ", i);
scrotSleep(1);
}
printf("0.\n");
fflush(stdout);
dprintf(STDERR_FILENO, "0.\n");
} else
sleep(opt.delay);
scrotSleep(opt.delay);
}
}

Expand Down

0 comments on commit f1b195f

Please sign in to comment.