|
| 1 | +project( |
| 2 | + 'safeclib', |
| 3 | + 'c', |
| 4 | + version: '3.9.1', |
| 5 | + license: 'MIT', |
| 6 | + meson_version: '>=1.3.0', |
| 7 | +) |
| 8 | + |
| 9 | +cc = meson.get_compiler('c') |
| 10 | + |
| 11 | +conf = configuration_data() |
| 12 | + |
| 13 | +conf.set( |
| 14 | + 'INSERT_BOOL_SUPPORT', |
| 15 | + cc.check_header('stdbool.h') ? '#include <stdbool.h>' : '', |
| 16 | +) |
| 17 | +conf.set( |
| 18 | + 'INSERT_INTTYPES_H', |
| 19 | + cc.check_header('inttypes.h') ? '#include <inttypes.h>' : '', |
| 20 | +) |
| 21 | +conf.set( |
| 22 | + 'INSERT_STDINT_H', |
| 23 | + cc.check_header('stdint.h') ? '#include <stdint.h>' : '', |
| 24 | +) |
| 25 | +conf.set( |
| 26 | + 'INSERT_SYS_TYPES_H', |
| 27 | + cc.check_header('sys/types.h') ? '#include <sys/types.h>' : '', |
| 28 | +) |
| 29 | +conf.set('INSERT_ERRNO_H', cc.check_header('errno.h') ? '#include <errno.h>' : '') |
| 30 | + |
| 31 | +funcs = ('vswprintf vswscanf mbsrtowcs ' + |
| 32 | +'__bnd_chk_ptr_bounds __bnd_set_ptr_bounds __bnd_null_ptr_bounds ' + |
| 33 | +'__memcpy_chk __memmove_chk __memset_chk ' + |
| 34 | +'__strcpy_chk __strncpy_chk __strcat_chk __strncat_chk ' + |
| 35 | +'__printf_chk __sprintf_chk __snprintf_chk ' + |
| 36 | +'__vfprintf_chk __vfwprintf_chk __vsprintf_chk __vsnprintf_chk ' + |
| 37 | +'__vsscanf_chk ' + |
| 38 | +'memset strcmp strcasecmp strcasestr strcspn strpbrk strspn ' + |
| 39 | +'strnstr strnlen strrchr memrchr strstr bcmp secure_getenv timingsafe_memcmp ' + |
| 40 | +'timingsafe_bcmp explicit_bzero explicit_memset ' + |
| 41 | +'asctime_r ctime_r gmtime_r localtime_r memccpy stpcpy stpncpy strerror ' + |
| 42 | +'fileno ftruncate isinfl ' + |
| 43 | +'wmemchr wmemcmp wcscmp wcsstr ' + |
| 44 | +'vswprintf vsnwprintf vswscanf mbsrtowcs mbstowcs iswdigit iswspace ' + |
| 45 | +'towlower towupper towctrans ' + |
| 46 | +'_memcpy_s_chk _memmove_s_chk _memset_s_chk _memcmp_s_chk ' + |
| 47 | +'_strcpy_s_chk _strncpy_s_chk _strcat_s_chk _strncat_s_chk _strnlen_s_chk ' + |
| 48 | +'_printf_s_chk _sprintf_s_chk _snprintf_s_chk ' + |
| 49 | +'_vfprintf_s_chk _vsprintf_s_chk _vsnprintf_s_chk ' + |
| 50 | +'memset_s memcpy_s memmove_s memzero_s memchr_s memrchr_s memccpy_s ' + |
| 51 | +'sprintf_s strcat_s strcpy_s strncat_s strncpy_s ' + |
| 52 | +'strnlen_s strtok_s strerror_s vsprintf_s tmpnam_s snprintf_s vsnprintf_s ' + |
| 53 | +'strspn_s strset_s strchr_s strrchr_s strstr_s strzero_s strnset_s ' + |
| 54 | +'stpcpy_s stpncpy_s ' + |
| 55 | +'sscanf_s fscanf_s scanf_s vfscanf_s ' + |
| 56 | +'vsscanf_s vscanf_s printf_s fprintf_s tmpfile_s vfprintf_s vprintf_s ' + |
| 57 | +'fopen_s freopen_s gets_s bsearch_s qsort_s gmtime_s localtime_s ' + |
| 58 | +'asctime_s ctime_s getenv_s feenableexcept ' + |
| 59 | +'mbsrtowcs_s mbstowcs_s wcsrtombs_s wcstombs_s ' + |
| 60 | +'wcrtomb_s wctomb_s wcsnlen_s wcscpy_s wcsncpy_s wcscat_s wcsncat_s ' + |
| 61 | +'wmemcpy_s wmemmove_s wcstok_s vswprintf_s swprintf_s vfwprintf_s ' + |
| 62 | +'vwprintf_s wprintf_s snwprintf_s fwprintf_s swscanf_s vswscanf_s wscanf_s ' + |
| 63 | +'vfwscanf_s fwscanf_s vwscanf_s vsnwprintf_s wcsstr_s wmemcmp_s ' + |
| 64 | +'wcscmp_s wcsncmp_s wcsicmp_s wcsset_s wcsnset_s wcscoll_s wcslwr_s ' + |
| 65 | +'wcsupr_s towfc_s wcsfc_s ' + |
| 66 | +'_swprintf_s_chk _vfwprintf_s_chk').split(' ') |
| 67 | +foreach f : funcs |
| 68 | + conf.set('HAVE_@0@'.format(f.underscorify().to_upper()), cc.has_function(f)) |
| 69 | +endforeach |
| 70 | + |
| 71 | +headers = [ |
| 72 | + 'sys/time.h', |
| 73 | + 'stdlib.h', |
| 74 | + 'memory.h', |
| 75 | + 'ctype.h', |
| 76 | + 'malloc.h', |
| 77 | + 'string.h', |
| 78 | + 'limits.h', |
| 79 | + 'stddef.h', |
| 80 | + 'unistd.h', |
| 81 | + 'float.h', |
| 82 | + 'math.h', |
| 83 | + 'sys/types.h', |
| 84 | + 'inttypes.h', |
| 85 | + 'stdint.h', |
| 86 | + 'errno.h', |
| 87 | + 'wchar.h', |
| 88 | + 'langinfo.h', |
| 89 | + 'valgrind/valgrind.h', |
| 90 | + 'fenv.h', |
| 91 | + 'intrin.h', |
| 92 | + 'xmmintrin.h', |
| 93 | + 'emmintrin.h', |
| 94 | + 'x86intrin.h', |
| 95 | + 'arm_neon.h', |
| 96 | + 'arm_acle.h', |
| 97 | + 'mmintrin.h', |
| 98 | + 'altivec.h', |
| 99 | + 'spe.h', |
| 100 | + 'mbarrier.h', |
| 101 | +] |
| 102 | +foreach h : headers |
| 103 | + conf.set( |
| 104 | + 'HAVE_@0@'.format(h.underscorify().to_upper()), |
| 105 | + cc.check_header(h) |
| 106 | + ) |
| 107 | +endforeach |
| 108 | + |
| 109 | +sizeofs = ['size_t', 'wchar_t', 'time_t'] |
| 110 | +foreach s : sizeofs |
| 111 | + conf.set('SIZEOF_@0@'.format(s.underscorify().to_upper()), cc.sizeof(s)) |
| 112 | +endforeach |
| 113 | + |
| 114 | +conf.set( |
| 115 | + 'HAVE_TM_GMTOFF', |
| 116 | + cc.has_member( |
| 117 | + 'struct tm', |
| 118 | + 'tm_gmtoff', |
| 119 | + prefix: '#include <time.h>', |
| 120 | + ), |
| 121 | +) |
| 122 | +conf.set('HAVE_FLOAT128', cc.compiles('int main(void) { __float128 x = 1.0Q; }')) |
| 123 | +conf.set( |
| 124 | + 'HAVE_TOWUPPER_OK', |
| 125 | + cc.run( |
| 126 | + ''' |
| 127 | +#include <wctype.h> |
| 128 | +int main(void) { |
| 129 | + return (towupper(0x1C80) == 0x412 |
| 130 | + && towupper(0xB5) == 0x3BC |
| 131 | + && towupper(0x432) == 0x1C80) |
| 132 | + ? 0 : 1; |
| 133 | +} |
| 134 | +''', |
| 135 | + ).returncode() == 0, |
| 136 | +) |
| 137 | +conf.set( |
| 138 | + 'HAVE_STRNSTR_OK', |
| 139 | + cc.run( |
| 140 | + ''' |
| 141 | +#include <string.h> |
| 142 | +int main(void) { |
| 143 | + return strnstr("%s %n", "%n", 6) ? 0 : 1; |
| 144 | +} |
| 145 | +''', |
| 146 | + ).returncode() == 0 ? '1' : false, |
| 147 | +) |
| 148 | + |
| 149 | +conf.set( |
| 150 | + 'PRINTF_DISABLE_SUPPORT_FLOAT', |
| 151 | + get_option('float').allowed() ? false : 1, |
| 152 | +) |
| 153 | +conf.set( |
| 154 | + 'PRINTF_DISABLE_SUPPORT_EXPONENTIAL', |
| 155 | + get_option('float-exp').allowed() ? false : 1, |
| 156 | +) |
| 157 | +conf.set( |
| 158 | + 'PRINTF_DISABLE_SUPPORT_LONG_LONG', |
| 159 | + get_option('long-long').allowed() ? false : 1, |
| 160 | +) |
| 161 | +conf.set( |
| 162 | + 'PRINTF_DISABLE_SUPPORT_LONG_DOUBLE', |
| 163 | + get_option('long-double').allowed() ? false : 1, |
| 164 | +) |
| 165 | +conf.set( |
| 166 | + 'PRINTF_DISABLE_SUPPORT_PTRDIFF_T', |
| 167 | + get_option('printf-ptrdiff').allowed() ? false : 1, |
| 168 | +) |
| 169 | + |
| 170 | +conf.set( |
| 171 | + 'INSERT_EXTS', |
| 172 | + get_option('extensions').allowed() ? '#undef SAFECLIB_DISABLE_EXTENSIONS' : '#define SAFECLIB_DISABLE_EXTENSIONS 1', |
| 173 | +) |
| 174 | +conf.set( |
| 175 | + 'INSERT_NULLSLACK', |
| 176 | + get_option('nullslack').allowed() ? '#define SAFECLIB_STR_NULL_SLACK 1' : '#undef SAFECLIB_STR_NULL_SLACK', |
| 177 | +) |
| 178 | +conf.set( |
| 179 | + 'INSERT_CONSTRAINT_HANDLER', |
| 180 | + get_option('constraint-handler').allowed() ? '#undef SAFECLIB_DISABLE_CONSTRAINT_HANDLER' : '#define SAFECLIB_DISABLE_CONSTRAINT_HANDLER 1', |
| 181 | +) |
| 182 | +conf.set( |
| 183 | + 'INSERT_UNSAFE', |
| 184 | + get_option('unsafe').allowed() ? '#define SAFECLIB_ENABLE_UNSAFE 1' : '#undef SAFECLIB_ENABLE_UNSAFE', |
| 185 | +) |
| 186 | +haveBuiltinObjectSize = cc.has_function('__builtin_object_size') |
| 187 | +conf.set('HAVE___BUILTIN_OBJECT_SIZE', haveBuiltinObjectSize ? '1' : false) |
| 188 | +conf.set( |
| 189 | + 'INSERT_OBJECT_SIZE', |
| 190 | + haveBuiltinObjectSize ? '#define HAVE___BUILTIN_OBJECT_SIZE 1' : '', |
| 191 | +) |
| 192 | +conf.set( |
| 193 | + 'INSERT_WARN_DMAX', |
| 194 | + (get_option('warn-dmax').allowed() or get_option('error-dmax').allowed()) and haveBuiltinObjectSize ? '#define HAVE_WARN_DMAX 1' : '', |
| 195 | +) |
| 196 | +conf.set( |
| 197 | + 'INSERT_ERROR_DMAX', |
| 198 | + get_option('error-dmax').allowed() and haveBuiltinObjectSize ? '#define HAVE_ERROR_DMAX 1' : '', |
| 199 | +) |
| 200 | +conf.set( |
| 201 | + 'INSERT_DEFAULT_HANDLER', |
| 202 | + get_option('default-handler') == 'no' ? '#undef SAFECLIB_DEFAULT_HANDLER' : '#define SAFECLIB_DEFAULT_HANDLER @0@_handler_s'.format( |
| 203 | + get_option('default-handler'), |
| 204 | + ), |
| 205 | +) |
| 206 | +conf.set( |
| 207 | + 'INSERT_CONSTANT_P', |
| 208 | + cc.has_function('__builtin_constant_p') ? '#define HAVE___BUILTIN_CONSTANT_P 1' : '#undef HAVE___BUILTIN_CONSTANT_P', |
| 209 | +) |
| 210 | +conf.set('INSERT_DISABLE_DLLIMPORT', '#undef DISABLE_DLLIMPORT') |
| 211 | +conf.set( |
| 212 | + 'INSERT_DISABLE_WCHAR', |
| 213 | + get_option('wchar').allowed() ? '#undef SAFECLIB_DISABLE_WCHAR' : '#define SAFECLIB_DISABLE_WCHAR 1', |
| 214 | +) |
| 215 | +conf.set('INSERT_SAFECLIB_HAVE_C99', '#define SAFECLIB_HAVE_C99 1') |
| 216 | +conf.set('RSIZE_MAX_MEM', get_option('memmax')) |
| 217 | +conf.set('RSIZE_MAX_STR', get_option('strmax')) |
| 218 | +conf.set( |
| 219 | + 'FALLBACK_ERRNO_T', |
| 220 | + cc.has_type( |
| 221 | + 'errno_t', |
| 222 | + prefix: '#include <errno.h>', |
| 223 | + ) ? '' : 'typedef int errno_t;', |
| 224 | +) |
| 225 | +conf.set('HAVE_ATTRIBUTE_FORMAT_WPRINTF', '0') |
| 226 | +conf.set('HAVE_ATTRIBUTE_FORMAT_WSCANF', '0') |
| 227 | +conf.set('STDC_HEADERS', true) |
| 228 | +conf.set('configure_input', '') |
| 229 | + |
| 230 | +subdir('include') |
| 231 | +subdir('src') |
| 232 | + |
| 233 | +libsafec_dep = declare_dependency( |
| 234 | + include_directories: inc, |
| 235 | + link_with: libsafec, |
| 236 | +) |
0 commit comments