4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / lib / libc / gen / alarm.c
CommitLineData
b8f253e8 1/*
74155b62
KB
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
d0286ffa 4 *
269a7923 5 * %sccs.include.redist.c%
b8f253e8
KM
6 */
7
2ce81398 8#if defined(LIBC_SCCS) && !defined(lint)
74155b62 9static char sccsid[] = "@(#)alarm.c 8.1 (Berkeley) %G%";
d0286ffa 10#endif /* LIBC_SCCS and not lint */
30e720bf
SL
11
12/*
13 * Backwards compatible alarm.
14 */
15#include <sys/time.h>
c5980113 16#include <unistd.h>
30e720bf 17
c5980113 18unsigned int
30e720bf 19alarm(secs)
c5980113 20 unsigned int secs;
30e720bf
SL
21{
22 struct itimerval it, oitv;
23 register struct itimerval *itp = &it;
24
25 timerclear(&itp->it_interval);
26 itp->it_value.tv_sec = secs;
27 itp->it_value.tv_usec = 0;
28 if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
29 return (-1);
27130bed
RC
30 if (oitv.it_value.tv_usec)
31 oitv.it_value.tv_sec++;
30e720bf
SL
32 return (oitv.it_value.tv_sec);
33}