Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *  @brief Implementation for confstr method
0006  */
0007 
0008 /*
0009  * Copyright (C) 2020 Eshan Dhawan
0010  *
0011  * Redistribution and use in source and binary forms, with or without
0012  * modification, are permitted provided that the following conditions
0013  * are met:
0014  * 1. Redistributions of source code must retain the above copyright
0015  *    notice, this list of conditions and the following disclaimer.
0016  * 2. Redistributions in binary form must reproduce the above copyright
0017  *    notice, this list of conditions and the following disclaimer in the
0018  *    documentation and/or other materials provided with the distribution.
0019  *
0020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0030  * POSSIBILITY OF SUCH DAMAGE.
0031  */
0032 
0033 
0034 #include <sys/cdefs.h>
0035 #include <sys/param.h>
0036 #include <errno.h>
0037 #include <limits.h>
0038 #include <string.h>
0039 #include <unistd.h>
0040 
0041 /* Many programming environment flags have same values
0042 * this block is added to raise error if the flags value change
0043 */
0044 
0045 #if (_CS_POSIX_V6_ILP32_OFF32_CFLAGS != _CS_POSIX_V7_ILP32_OFF32_CFLAGS)
0046 #error "_CS_POSIX_V6_ILP32_OFF32_CFLAGS and _CS_POSIX_V7_ILP32_OFF32_CFLAGS flag values not equal"
0047 #endif
0048 
0049 #if (_CS_POSIX_V6_ILP32_OFF32_LDFLAGS != _CS_POSIX_V7_ILP32_OFF32_LDFLAGS)
0050 #error "_CS_POSIX_V6_ILP32_OFF32_LDFLAGS and _CS_POSIX_V7_ILP32_OFF32_LDFLAGS flag values not equal"
0051 #endif
0052 
0053 #if (_CS_POSIX_V6_ILP32_OFF32_LIBS!= _CS_POSIX_V7_ILP32_OFF32_LIBS)
0054 #error "_CS_POSIX_V6_ILP32_OFF32_LIBS and _CS_POSIX_V7_ILP32_OFF32_LIBS flag values not equal"
0055 #endif
0056 
0057 #if (_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS != _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS)
0058 #error "_CS_POSIX_V6_LPBIG_OFFBIG_CFLAG and _CS_POSIX_V7_LPBIG_OFFBIG_CFLAG flag values not equal"
0059 #endif
0060 
0061 #if (_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS != _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS)
0062 #error "_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS and _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS flag values not equal"
0063 #endif
0064 
0065 #if (_CS_POSIX_V7_LPBIG_OFFBIG_LIBS != _CS_POSIX_V7_LPBIG_OFFBIG_LIBS)
0066 #error "_CS_POSIX_V6_LPBIG_OFFBIG_LIBS and _CS_POSIX_V7_LPBIG_OFFBIG_LIBS flag values not equal"
0067 #endif
0068 
0069 #if (_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS != _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS)
0070 #error "_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS and _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS flag values not equal"
0071 #endif
0072 
0073 #if (_CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS != _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS)
0074 #error "_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS and _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS flag values not equal"
0075 #endif
0076 
0077 #if (_CS_POSIX_V7_ILP32_OFFBIG_LIBS != _CS_POSIX_V7_ILP32_OFFBIG_LIBS)
0078 #error "_CS_POSIX_V6_ILP32_OFFBIG_LIBS and _CS_POSIX_V7_ILP32_OFFBIG_LIBS flag values not equal"
0079 #endif
0080 
0081 #if (_CS_POSIX_V6_LP64_OFF64_CFLAGS != _CS_POSIX_V7_LP64_OFF64_CFLAGS)
0082 #error "_CS_POSIX_V6_LP64_OFF64_CFLAGS and _CS_POSIX_V7_LP64_OFF64_CFLAGS flag values not equal"
0083 #endif
0084 
0085 #if (_CS_POSIX_V6_LP64_OFF64_LDFLAGS != _CS_POSIX_V7_LP64_OFF64_LDFLAGS)
0086 #error "_CS_POSIX_V6_LP64_OFF64_LDFLAGS and _CS_POSIX_V7_LP64_OFF64_LDFLAGS flag values not equal"
0087 #endif
0088 
0089 #if (_CS_POSIX_V7_LP64_OFF64_LIBS != _CS_POSIX_V7_LP64_OFF64_LIBS)
0090 #error "_CS_POSIX_V6_LP64_OFF64_LIBS and _CS_POSIX_V7_LP64_OFF64_LIBS flag values not equal"
0091 #endif
0092 
0093 #if (_CS_V6_ENV != _CS_V7_ENV)
0094 #error "_CS_V6_ENV and _CS_V7_ENV flag values not equal"
0095 #endif
0096 
0097 size_t confstr(int name, char *buf, size_t len){
0098   const char *p;
0099   const char UPE[] = "unsupported programming environment";
0100 
0101   switch (name) {
0102     case _CS_PATH:
0103       errno = EINVAL;
0104       return (0);
0105     case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
0106     case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
0107     case _CS_POSIX_V7_ILP32_OFF32_LIBS:
0108     case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS:
0109     case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS:
0110     case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS:
0111     case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
0112     case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
0113     case _CS_POSIX_V7_ILP32_OFFBIG_LIBS:
0114     case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
0115     case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
0116     case _CS_POSIX_V7_LP64_OFF64_LIBS:
0117     case _CS_V7_ENV:
0118       p = UPE;
0119       if (len != 0 && buf != NULL){
0120         strlcpy(buf, p, len);
0121       }
0122       return (strlen(p) + 1);
0123     default:
0124       errno = EINVAL;
0125       return (0);
0126   }
0127 }