diff --git a/libc/Android.mk b/libc/Android.mk index d4ccefbe5..4e6276520 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -104,7 +104,6 @@ libc_common_src_files := \ stdlib/putenv.c \ stdlib/setenv.c \ stdlib/strtod.c \ - unistd/alarm.c \ unistd/syslog.c \ unistd/time.c \ @@ -316,6 +315,7 @@ libc_upstream_netbsd_src_files := \ upstream-netbsd/lib/libc/unistd/killpg.c \ libc_upstream_openbsd_src_files := \ + upstream-openbsd/lib/libc/gen/alarm.c \ upstream-openbsd/lib/libc/gen/exec.c \ upstream-openbsd/lib/libc/gen/fnmatch.c \ upstream-openbsd/lib/libc/gen/ftok.c \ diff --git a/libc/unistd/alarm.c b/libc/upstream-openbsd/lib/libc/gen/alarm.c similarity index 78% rename from libc/unistd/alarm.c rename to libc/upstream-openbsd/lib/libc/gen/alarm.c index 53edea949..2af847a46 100644 --- a/libc/unistd/alarm.c +++ b/libc/upstream-openbsd/lib/libc/gen/alarm.c @@ -1,3 +1,4 @@ +/* $OpenBSD: alarm.c,v 1.7 2005/08/08 08:05:33 espie Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -10,7 +11,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -27,12 +28,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)alarm.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -//__FBSDID("$FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/alarm.c,v 1.3 2007/01/09 00:27:53 imp Exp $"); - /* * Backwards compatible alarm. */ @@ -40,22 +35,16 @@ static char sccsid[] = "@(#)alarm.c 8.1 (Berkeley) 6/4/93"; #include unsigned int -alarm(secs) - unsigned int secs; +alarm(unsigned int secs) { struct itimerval it, oitv; struct itimerval *itp = ⁢ - itp->it_interval.tv_usec = 0; - itp->it_interval.tv_sec = 0; + timerclear(&itp->it_interval); itp->it_value.tv_sec = secs; itp->it_value.tv_usec = 0; if (setitimer(ITIMER_REAL, itp, &oitv) < 0) -#if 1 /* BIONIC: Same behaviour than GLibc for errors */ - return 0; -#else - return (-1); -#endif + return ((unsigned int) -1); if (oitv.it_value.tv_usec) oitv.it_value.tv_sec++; return (oitv.it_value.tv_sec); diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 9969d49bc..f50c102f6 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -112,3 +112,7 @@ TEST(unistd, read_EBADF) { ASSERT_EQ(-1, read(-1, buf, sizeof(buf))); ASSERT_EQ(EBADF, errno); } + +TEST(unistd, alarm) { + ASSERT_EQ(0U, alarm(0)); +}