[rtems commit] score: Add rtems_set_errno_and_return_value()

Sebastian Huber sebh at rtems.org
Tue Mar 10 08:11:12 UTC 2015


Module:    rtems
Branch:    master
Commit:    f0ff18e03572debbbe7dc0132cf54a0eb03f0276
Changeset: http://git.rtems.org/rtems/commit/?id=f0ff18e03572debbbe7dc0132cf54a0eb03f0276

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar  9 13:18:32 2015 +0100

score: Add rtems_set_errno_and_return_value()

Remove rtems_set_errno_and_return_minus_one_cast().

---

 cpukit/posix/src/mqueueopen.c       | 14 ++++++++------
 cpukit/posix/src/semopen.c          |  4 ++--
 cpukit/score/include/rtems/seterr.h | 15 ++++++---------
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c
index 43e4082..96721d1 100644
--- a/cpukit/posix/src/mqueueopen.c
+++ b/cpukit/posix/src/mqueueopen.c
@@ -44,6 +44,8 @@
 #include <rtems/posix/time.h>
 #include <rtems/seterr.h>
 
+#define MQ_OPEN_FAILED ((mqd_t) -1)
+
 /*
  *  15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
  */
@@ -82,7 +84,7 @@ mqd_t mq_open(
   the_mq_fd = _POSIX_Message_queue_Allocate_fd();
   if ( !the_mq_fd ) {
     _Objects_Allocator_unlock();
-    rtems_set_errno_and_return_minus_one( ENFILE );
+    rtems_set_errno_and_return_value( ENFILE, MQ_OPEN_FAILED );
   }
   the_mq_fd->oflag = oflag;
 
@@ -102,7 +104,7 @@ mqd_t mq_open(
     if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
       _POSIX_Message_queue_Free_fd( the_mq_fd );
       _Objects_Allocator_unlock();
-      rtems_set_errno_and_return_minus_one_cast( status, mqd_t );
+      rtems_set_errno_and_return_value( status, MQ_OPEN_FAILED );
     }
 
   } else {                /* name -> ID translation succeeded */
@@ -112,7 +114,7 @@ mqd_t mq_open(
     if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
       _POSIX_Message_queue_Free_fd( the_mq_fd );
       _Objects_Allocator_unlock();
-      rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
+      rtems_set_errno_and_return_value( EEXIST, MQ_OPEN_FAILED );
     }
 
     /*
@@ -129,7 +131,7 @@ mqd_t mq_open(
     );
     _Thread_Enable_dispatch();
     _Objects_Allocator_unlock();
-    return (mqd_t)the_mq_fd->Object.id;
+    return the_mq_fd->Object.id;
 
   }
 
@@ -151,7 +153,7 @@ mqd_t mq_open(
   if ( status == -1 ) {
     _POSIX_Message_queue_Free_fd( the_mq_fd );
     _Objects_Allocator_unlock();
-    return (mqd_t) -1;
+    return MQ_OPEN_FAILED;
   }
 
   the_mq_fd->Queue = the_mq;
@@ -163,5 +165,5 @@ mqd_t mq_open(
 
   _Objects_Allocator_unlock();
 
-  return (mqd_t) the_mq_fd->Object.id;
+  return the_mq_fd->Object.id;
 }
diff --git a/cpukit/posix/src/semopen.c b/cpukit/posix/src/semopen.c
index 0b98ca6..0568ee6 100644
--- a/cpukit/posix/src/semopen.c
+++ b/cpukit/posix/src/semopen.c
@@ -92,7 +92,7 @@ sem_t *sem_open(
 
     if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
       _Objects_Allocator_unlock();
-      rtems_set_errno_and_return_minus_one_cast( status, sem_t * );
+      rtems_set_errno_and_return_value( status, SEM_FAILED );
     }
   } else {
 
@@ -102,7 +102,7 @@ sem_t *sem_open(
 
     if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
       _Objects_Allocator_unlock();
-      rtems_set_errno_and_return_minus_one_cast( EEXIST, sem_t * );
+      rtems_set_errno_and_return_value( EEXIST, SEM_FAILED );
     }
 
     the_semaphore = _POSIX_Semaphore_Get( (sem_t *) &the_semaphore_id, &location );
diff --git a/cpukit/score/include/rtems/seterr.h b/cpukit/score/include/rtems/seterr.h
index 1e9e0d0..22fddc8 100644
--- a/cpukit/score/include/rtems/seterr.h
+++ b/cpukit/score/include/rtems/seterr.h
@@ -31,25 +31,22 @@
 
 /**
  *  This is a helper macro which will set the variable errno and return
- *  -1 to the caller.  This pattern is common to many POSIX methods.
+ *  the specified value to the caller.
  *
  *  @param[in] _error is the error code
+ *  @param[in] _value is the value to return
  */
-#define rtems_set_errno_and_return_minus_one( _error ) \
-  do { errno = (_error); return -1; } while(0)
+#define rtems_set_errno_and_return_value( _error, _value ) \
+  do { errno = ( _error ); return ( _value ); } while ( 0 )
 
 /**
  *  This is a helper macro which will set the variable errno and return
  *  -1 to the caller.  This pattern is common to many POSIX methods.
  *
  *  @param[in] _error is the error code
- *  @param[in] _cast is the type to which -1 must be cast
- *
- *  @note It is similar to @ref rtems_set_errno_and_return_minus_one but
- *        this -1 value is cast to something other than an int.
  */
-#define rtems_set_errno_and_return_minus_one_cast( _error, _cast ) \
-  do { errno = (_error); return (_cast) -1; } while(0)
+#define rtems_set_errno_and_return_minus_one( _error ) \
+  rtems_set_errno_and_return_value( _error, -1 )
 
 /**@}*/
 #endif




More information about the vc mailing list