Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:12

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup POSIXAPI
0007  *
0008  * @brief This header file provides interfaces used by the POSIX API
0009  *   implementation.
0010  */
0011 
0012 /*
0013  *  COPYRIGHT (c) 1989-2011.
0014  *  On-Line Applications Research Corporation (OAR).
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifndef _RTEMS_POSIX_POSIXAPI_H
0039 #define _RTEMS_POSIX_POSIXAPI_H
0040 
0041 #include <rtems/config.h>
0042 #include <rtems/score/assert.h>
0043 #include <rtems/score/objectimpl.h>
0044 #include <rtems/score/threadimpl.h>
0045 #include <rtems/seterr.h>
0046 
0047 #include <pthread.h>
0048 
0049 /**
0050  * @defgroup POSIXAPI POSIX API
0051  *
0052  * @ingroup RTEMSImpl
0053  *
0054  * @brief This group contains definitions and modules which are used to
0055  *   implement the POSIX APIs supported by RTEMS.
0056  *
0057  * @{
0058  */
0059 
0060 extern const int _POSIX_Get_by_name_error_table[ 3 ];
0061 
0062 static inline int _POSIX_Get_by_name_error(
0063   Objects_Get_by_name_error error
0064 )
0065 {
0066   _Assert( (size_t) error < RTEMS_ARRAY_SIZE( _POSIX_Get_by_name_error_table ) );
0067   return _POSIX_Get_by_name_error_table[ error ];
0068 }
0069 
0070 static inline int _POSIX_Get_error( Status_Control status )
0071 {
0072   return STATUS_GET_POSIX( status );
0073 }
0074 
0075 static inline int _POSIX_Get_error_after_wait(
0076   const Thread_Control *executing
0077 )
0078 {
0079   return _POSIX_Get_error( _Thread_Wait_get_status( executing ) );
0080 }
0081 
0082 static inline int _POSIX_Zero_or_minus_one_plus_errno(
0083   Status_Control status
0084 )
0085 {
0086   if ( status == STATUS_SUCCESSFUL ) {
0087     return 0;
0088   }
0089 
0090   rtems_set_errno_and_return_minus_one( _POSIX_Get_error( status ) );
0091 }
0092 
0093 /*
0094  * See also The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008,
0095  * 2016 Edition, subsection 2.9.9, Synchronization Object Copies and
0096  * Alternative Mappings.
0097  *
0098  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_09
0099  */
0100 static inline bool _POSIX_Is_valid_pshared( int pshared )
0101 {
0102   return pshared == PTHREAD_PROCESS_PRIVATE ||
0103     pshared == PTHREAD_PROCESS_SHARED;
0104 }
0105 
0106 /** @} */
0107 
0108 #endif
0109 /* end of include file */