1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)alarm.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 /* 13 * Backwards compatible alarm. 14 */ 15 #include <sys/time.h> 16 #include <unistd.h> 17 18 unsigned int 19 alarm(secs) 20 unsigned int secs; 21 { 22 struct itimerval it, oitv; 23 register struct itimerval *itp = ⁢ 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); 30 if (oitv.it_value.tv_usec) 31 oitv.it_value.tv_sec++; 32 return (oitv.it_value.tv_sec); 33 } 34