Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librt Keep in sync with libpthread: Fix error handling.



details:   https://anonhg.NetBSD.org/src/rev/983917a736d5
branches:  trunk
changeset: 777942:983917a736d5
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sat Mar 10 19:59:21 2012 +0000

description:
Keep in sync with libpthread: Fix error handling.

diffstat:

 lib/librt/sem.c |  23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diffs (70 lines):

diff -r 577f825813d3 -r 983917a736d5 lib/librt/sem.c
--- a/lib/librt/sem.c   Sat Mar 10 19:38:16 2012 +0000
+++ b/lib/librt/sem.c   Sat Mar 10 19:59:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.c,v 1.6 2012/03/08 21:59:29 joerg Exp $    */
+/*     $NetBSD: sem.c,v 1.7 2012/03/10 19:59:21 joerg Exp $    */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: sem.c,v 1.6 2012/03/08 21:59:29 joerg Exp $");
+__RCSID("$NetBSD: sem.c,v 1.7 2012/03/10 19:59:21 joerg Exp $");
 
 /*
  * If an application is linked against both librt and libpthread, the
@@ -163,6 +163,7 @@
 int
 sem_destroy(sem_t *sem)
 {
+       int error, save_errno;
 
 #ifdef ERRORCHECK
        if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
@@ -171,12 +172,12 @@
        }
 #endif
 
-       if (_ksem_destroy((*sem)->ksem_semid) == -1)
-               return (-1);
+       error = _ksem_destroy((*sem)->ksem_semid);
+       save_errno = errno;
+       sem_free(*sem);
+       errno = save_errno;
 
-       sem_free(*sem);
-
-       return (0);
+       return error;
 }
 
 sem_t *
@@ -241,6 +242,7 @@
 int
 sem_close(sem_t *sem)
 {
+       int error, save_errno;
 
 #ifdef ERRORCHECK
        if (sem == NULL || *sem == NULL || (*sem)->ksem_magic != KSEM_MAGIC) {
@@ -249,13 +251,14 @@
        }
 #endif
 
-       if (_ksem_close((*sem)->ksem_semid) == -1)
-               return (-1);
+       error = _ksem_close((*sem)->ksem_semid);
 
        LIST_REMOVE((*sem), ksem_list);
+       save_errno = errno;
        sem_free(*sem);
        free(sem);
-       return (0);
+       errno = save_errno;
+       return error;
 }
 
 int



Home | Main Index | Thread Index | Old Index