Fix {clock,pthread}_getcpuclockid to return an error number on

failure, to match OpenGroup specifications.
This commit is contained in:
njoly 2017-03-04 11:16:33 +00:00
parent 0d9606d5f1
commit 5e0724b3f9
4 changed files with 32 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock_getcpuclockid.c,v 1.1 2016/04/23 23:11:31 christos Exp $ */
/* $NetBSD: clock_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@ -30,14 +30,22 @@
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: clock_getcpuclockid.c,v 1.1 2016/04/23 23:11:31 christos Exp $");
__RCSID("$NetBSD: clock_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <errno.h>
#include <time.h>
int
clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
{
return clock_getcpuclockid2(P_PID, (id_t)pid, clock_id);
int error = 0, saved_errno;
saved_errno = errno;
if (clock_getcpuclockid2(P_PID, (id_t)pid, clock_id) == -1)
error = errno;
errno = saved_errno;
return error;
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: clock_getcpuclockid2.2,v 1.2 2016/04/24 08:59:30 wiz Exp $
.\" $NetBSD: clock_getcpuclockid2.2,v 1.3 2017/03/04 11:16:33 njoly Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd April 23, 2016
.Dd March 3, 2017
.Dt CLOCK_GETCPUCLOCKID2 2
.Os
.Sh NAME
@ -81,17 +81,12 @@ function can be used with the returned
.Fa clock_id
to retrieve process and LWP times.
.Sh RETURN VALUES
The
.Rv -std clock_getcpuclockid2
.Pp
If successful, the
.Fn clock_getcpuclockid
and
.Fn clock_getcpuclockid2
functions succeed and return 0, placing the requested
.Fa clock_id
in the argument.
On error, the value \-1 is returned
and the value of
.Va errno
is set to reflect what went wrong.
function will return 0.
Otherwise an error number will be returned.
.Sh ERRORS
These functions fail if:
.Bl -tag -width Er

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pthread_getcpuclockid.3,v 1.3 2016/04/24 09:01:45 wiz Exp $
.\" $NetBSD: pthread_getcpuclockid.3,v 1.4 2017/03/04 11:16:33 njoly Exp $
.\"
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd April 23, 2016
.Dd March 3, 2017
.Dt PTHREAD_GETCPUCLOCKID 3
.Os
.Sh NAME
@ -58,10 +58,7 @@ On success the
function returns 0, placing the requested
.Fa clock_id
in the argument.
On error, the value \-1 is returned
and the value of
.Va errno
is set to reflect what went wrong.
Otherwise an error number will be returned.
.Sh ERRORS
These functions fail if:
.Bl -tag -width Er

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp $ */
/* $NetBSD: pthread_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@ -30,10 +30,11 @@
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp $");
__RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <errno.h>
#include <pthread.h>
#include <time.h>
@ -42,5 +43,12 @@ __RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp
int
pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id)
{
return clock_getcpuclockid2(P_LWPID, (id_t)thread->pt_lid, clock_id);
int error = 0, saved_errno;
saved_errno = errno;
if (clock_getcpuclockid2(P_LWPID, (id_t)thread->pt_lid, clock_id) == -1)
error = errno;
errno = saved_errno;
return error;
}