Permalink
Browse files

move itimerspec to create_timer since its local to the function

  • Loading branch information...
1 parent 726b044 commit 8b82eb63ac26518e2f6070294bc5813d531adcbe @falconindy falconindy committed Dec 6, 2011
Showing with 8 additions and 7 deletions.
  1. +8 −7 wakeup.c
View
@@ -180,26 +180,29 @@ parse_timespec(int optind, int argc, char **argv, struct timespec_t *ts)
}
static int
-create_alarm(struct itimerspec *wakeup, struct timespec_t *ts)
+create_alarm(struct timespec_t *ts)
{
+ struct itimerspec wakeup;
timer_t timerid;
+ memset(&wakeup, 0, sizeof(struct itimerspec));
+
/* init timer */
if(timer_create(CLOCK_REALTIME_ALARM, NULL, &timerid) != 0) {
perror("error: failed to create timer");
return 1;
}
/* init itimerspec */
- if(clock_gettime(CLOCK_REALTIME_ALARM, &wakeup->it_value)) {
+ if(clock_gettime(CLOCK_REALTIME_ALARM, &wakeup.it_value)) {
perror("error: failed to get time from RTC");
return 1;
}
/* set itimerspec to some future time */
- wakeup->it_value.tv_sec += timespec_to_seconds(ts);
+ wakeup.it_value.tv_sec += timespec_to_seconds(ts);
- if(timer_settime(timerid, TIMER_ABSTIME, wakeup, NULL)) {
+ if(timer_settime(timerid, TIMER_ABSTIME, &wakeup, NULL)) {
perror("error: failed to set wakeup time");
return 1;
}
@@ -213,7 +216,6 @@ create_alarm(struct itimerspec *wakeup, struct timespec_t *ts)
int
main(int argc, char *argv[])
{
- struct itimerspec wakeup;
struct timespec_t ts;
if(argc <= 1) {
@@ -222,7 +224,6 @@ main(int argc, char *argv[])
}
memset(&ts, 0, sizeof(struct timespec));
- memset(&wakeup, 0, sizeof(struct itimerspec));
if(parse_options(argc, argv) != 0) {
return 1;
@@ -232,7 +233,7 @@ main(int argc, char *argv[])
return 2;
}
- if(create_alarm(&wakeup, &ts) != 0) {
+ if(create_alarm(&ts) != 0) {
return 3;
}

0 comments on commit 8b82eb6

Please sign in to comment.