### getenv_s Usage Example Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html Example demonstrating how to use the getenv_s function to retrieve the value of an environment variable. ```c char env_value[255]; getenv_s(NULL, env_value, sizeof(env_value), "PATH"); ``` -------------------------------- ### Example usage of strcpy_s Source: https://github.com/sbaresearch/slibc/blob/master/README.md Demonstrates how to use the secure `strcpy_s` function in C. ```c #include int main(int argc, char *argv[]) { char dest[10]; strcpy_s(dest, sizeof(dest), argv[0]); } ``` -------------------------------- ### Using SLIBC with your program Source: https://github.com/sbaresearch/slibc/blob/master/docs/index.html Example demonstrating how to use the _s functions in C code, including necessary includes and function calls. ```c #include int main(int argc, char *argv[]) { char dest[10]; strcpy_s(dest, sizeof(dest), argv[0]); } ``` -------------------------------- ### strcpy_s usage example Source: https://github.com/sbaresearch/slibc/blob/master/docs/string__templates___8hpp.html Example demonstrating the usage of the overloaded strcpy_s template function in C++. ```cpp char buf[10]; char *input = "123456789ABCDEF"; // ContstraintHandler is called, because the input // contains more than 10 characters strcpy_s(buf, input) ``` -------------------------------- ### Using the _s functions in your code Source: https://github.com/sbaresearch/slibc/blob/master/mainpage.dox Example of using the secure strcpy_s function from SLIBC. ```c #include int main(int argc, char *argv[]) { char dest[10]; strcpy_s(dest, sizeof(dest), argv[0]); } ``` -------------------------------- ### getenv_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html The getenv_s function gets the value of an environment variable. ```c errno_t getenv_s(size_t *restrict len, char *restrict value, rsize_t maxsize, const char *restrict name) ``` -------------------------------- ### getenv_s function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html The getenv_s function gets the value of an environment variable. ```c errno_t getenv_s( size_t *restrict _len_, char *restrict _value_, rsize_t _maxsize_, const char *restrict _name_ ) ``` -------------------------------- ### qsort_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html This function sorts an array in ascending order. ```c errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *x, const void *y, void *context), void *context) ``` -------------------------------- ### bsearch_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html This function performs a binary search of a sorted array. ```c void *bsearch_s(const void *key, const void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *, const void *, void *context), void *context) ``` -------------------------------- ### ignore_handler_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html the ignore_handler_s is used to ignore constraint violations it does nothing ```c void ignore_handler_s(const char *restrict msg, void *restrict ptr, errno_t error) ``` -------------------------------- ### tmpfile_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html Creates a temporary binary file that will be automatically deleted when it is closed. ```c errno_t tmpfile_s(FILE *restrict *restrict _streamptr); ``` -------------------------------- ### constraint_handler_t Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html Definition of callback-type constraint_handler_t. ```c typedef void(* constraint_handler_t)(const char *restrict msg, void *restrict ptr, errno_t error) ``` -------------------------------- ### bsearch_s function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html This function performs a binary search of a sorted array. ```c void* bsearch_s( const void* _key_, const void* _base_, rsize_t _nmemb_, rsize_t _size_, int(*)(const void *, const void *, void *context) _compar_, void* _context_ ) ``` -------------------------------- ### tmpfile_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html Creates a temporary binary file that is automatically removed upon closing or program termination. It guarantees a unique file and opens in w+b mode with exclusive access and 600 permissions. ```c FILE *streamptr; errno_t tmpfile_s(FILE **streamptr); ``` -------------------------------- ### fopen_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html The fopen_s function opens the file specified by filename. ```c errno_t fopen_s(FILE *restrict *restrict streamptr, const char *restrict filename, const char *restrict mode); ``` -------------------------------- ### stdint.h Source Code Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdint_8h_source.html The source code of the stdint.h file, including copyright and license information, and conditional macros. ```c /* Copyright (C) 2011-2012 SBA Research gGmbH This file is part of the Slibc Library. The Slibc Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The Slibc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the Slibc Library; if not, see . */ #ifdef __cplusplus // In C++ we explicitly have to request that the // SIZE_MAX macro is defined by defining __STDC_LIMIT_MACROS. #define __STDC_LIMIT_MACROS #endif // include the system-header first #include_next #ifndef SLIBC_STDINT_H #define SLIBC_STDINT_H // TR 24731-1 is not available if __STDC_WANT_LIB_EXT1__ equals 0 #if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) #define RSIZE_MAX (SIZE_MAX >> 1) #endif //(!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) #endif ``` -------------------------------- ### set_constraint_handler_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html The set_constraint_handler function sets a user-specified constraint handler. ```c errno_t set_constraint_handler_s(constraint_handler_t handler) ``` -------------------------------- ### fopen_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the fopen_s function, which opens a file specified by filename. ```c errno_t fopen_s(FILE * restrict * restrict streamptr, const char * restrict filename, const char * restrict mode); ``` -------------------------------- ### time.h Header Content Source: https://github.com/sbaresearch/slibc/blob/master/docs/time_8h_source.html This snippet shows the content of the time.h header file, including copyright information and conditional inclusions. ```c /* Copyright (C) 2011-2012 SBA Research gGmbH This file is part of the Slibc Library. The Slibc Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The Slibc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the Slibc Library; if not, see . */ #include_next // Glibc headers often include time.h only to get some types // in that case the caller defined __need_TYPE (e.g. __need_time_t) // If time.h is included in a normal way, it will define the macro _TIME_H // (Let's hope that this macro name is portable) #if defined(_TIME_H) && !defined(SLIBC_TIME_H) #define SLIBC_TIME_H // TR 24731-1 is not available if __STDC_WANT_LIB_EXT1__ equals 0 #if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) #include "./base_.h" #include "./errno.h " #include "./stddef.h " SLIBC_BEGIN_DECLS errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *timeptr); errno_t ctime_s(char *s, rsize_t maxsize, const time_t *timer); struct tm *gmtime_s(const time_t * restrict timer, struct tm * restrict result); struct tm *localtime_s(const time_t * restrict timer, struct tm * restrict result); SLIBC_END_DECLS #endif //#if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) #endif ``` -------------------------------- ### string.h Header File Content Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h_source.html This snippet shows the content of the string.h header file, including copyright information and function declarations for string manipulation functions. ```c /* Copyright (C) 2011-2012 SBA Research gGmbH This file is part of the Slibc Library. The Slibc Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The Slibc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the Slibc Library; if not, see . */ #include_next #ifndef SLIBC_STRING_H #define SLIBC_STRING_H // TR 24731-1 is not available if __STDC_WANT_LIB_EXT1__ equals 0 #if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) #include "./base_.h" #include "./stddef.h" "TR 24731-1 stddef.h defines the type rsize_t." #include "./errno.h" "TR 24731-1 errno.h defines the type errno_t." SLIBC_BEGIN_DECLS size_t strnlen_s(const char *s, size_t maxsize); errno_t strcpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2); errno_t strncpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2, rsize_t n); errno_t strcat_s(char * restrict s1, rsize_t s1max, const char * restrict s2); errno_t strncat_s(char * restrict s1, rsize_t s1max, const char * restrict s2, rsize_t n); errno_t memcpy_s(void * restrict s1, rsize_t s1max, const void * restrict s2, rsize_t n); errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n); char *strtok_s(char * restrict s1, rsize_t * restrict s1max, const char * restrict delim, char ** restrict ptr); errno_t strerror_s(char *s, rsize_t maxsize, errno_t errnum); size_t strerrorlen_s(errno_t errnum); SLIBC_END_DECLS #if defined(__cplusplus) && (defined(SLIBC_WANT_TEMPLATES)) # include "./string_templates_.hpp" "Contains overloaded templates for some _s-functions defined in string.h." #endif #endif //#if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) #endif ``` -------------------------------- ### vprintf_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html Writes formatted output to stdout using a va_list argument. It is equivalent to printf_s but accepts a va_list. ```c int vprintf_s(const char *restrict format, va_list arg); ``` -------------------------------- ### stdlib.h Header Guard and TR 24731-1 Check Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h_source.html This snippet shows the standard header guard for stdlib.h and a conditional check for the TR 24731-1 extensions. ```c #include "./base_.h" #include "./errno.h" #include "./stddef.h" SLIBC_BEGIN_DECLS //TR 24731-1 addition to stdlib.h /* Definition of callback-type constraint_handler_t. */ typedef void (*constraint_handler_t)(const char * restrict msg, void * restrict ptr, errno_t error); /* The set_constraint_handler function sets a user-specified constraint handler. */ constraint_handler_t set_constraint_handler_s(constraint_handler_t handler); /* The abort handler gives out an errormessage on stderr before it ends the program with the function ab... */ void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error); /* the ignore_handler_s is used to ignore constraint violations it does nothing */ void ignore_handler_s(const char * restrict msg, void * restrict ptr, errno_t error); /* The getenv_s function gets the value of an environment variable. */ errno_t getenv_s(size_t * restrict len, char * restrict value, rsize_t maxsize, const char * restrict name); /* This function sorts an array in ascending order. */ errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size, int (*compar) (const void *x, const void *y, void *context), void *context ); /* This function performs a binary search of a sorted array. */ void *bsearch_s (const void *key, const void *base, rsize_t nmemb, rsize_t size, int (*compar) (const void *, const void *, void *context), void *context); // wctomb_s currently not implemented // mbstowcs_s currently not implemented // wcstombs_s currently not implemented SLIBC_END_DECLS #endif //#if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) ``` -------------------------------- ### snprintf_s template Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio__templates___8hpp_source.html This function allows formatted output into buffer s while taking into account its size. ```c++ template int snprintf_s(char (&s1) [n], const char * restrict format, ...) { va_list arg; va_start(arg, format); int r = vsnprintf_s(s1, n, format, arg); va_end(arg); return r; } ``` -------------------------------- ### gets_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the gets_s function, which reads one line from stdin into a buffer. ```c char *gets_s(char *s, rsize_t n); ``` -------------------------------- ### vfscanf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html vfscanf_s is equivalent to fscanf_s but expects a va_list argument. ```c int vfscanf_s(FILE *restrict stream, const char *restrict format, va_list arg); ``` -------------------------------- ### freopen_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the freopen_s function, which opens a filename and closes a stream. ```c errno_t freopen_s(FILE * restrict * restrict newstreamptr, const char * restrict filename, const char * restrict mode, FILE * restrict stream); ``` -------------------------------- ### vfprintf_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html Writes formatted output to a stream using a va_list argument. It is equivalent to fprintf_s but accepts a va_list. ```c int vfprintf_s(FILE *restrict stream, const char *restrict format, va_list arg); ``` -------------------------------- ### tmpnam_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the tmpnam_s function, which creates a unique file or directory name for the temporary directory. ```c errno_t tmpnam_s(char *s, rsize_t maxsize); ``` -------------------------------- ### sprintf_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the sprintf_s function, which allows formatted output into a buffer while considering its size. ```c int sprintf_s(char * restrict s, rsize_t n, const char * restrict format, ...) __attribute__ ((format (printf, 3, 4))); ``` -------------------------------- ### tmpnam_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html Generates a unique file or directory name within a specified temporary directory. The output buffer size requirement depends on the temporary directory's length. ```c (char *_s, rsize_t _maxsize) This function creates a file or directory name that is unique for the specified temporary directory. The generated file or directory name is guaranteed to be different from any other existing name in the temporary directory. The default temporary directory is /tmp but can be changed via slibc_set_tmp_dir. The output buffer needs to be at least of length L_tmpnam_s if the default directory location of /tmp is used. In case the slibc temporary directory is changed to a longer directory name by calling slibc_set_tmp_dir the output buffer is required to be of size L_tmpnam_s + strlen(set_tmp_dir). Otherwise calling tmpnam_s might fail. (It will never overflow the buffer though). The function is potentially capable of generating TMP_MAX_S different strings. **Remarks:** Use of this function is normally discouraged because this function does not create the file. It shares this isse wit the traditional tmpnam function. In more detail, a race condition between calling this function and the time of the actual file/directory creation exists. It is, thus, possible that an attacker creates a file with same name in the meantime. Thus, the ISO standard recommends using tmpfile_s where possible. One possible reasonable use of this function is when the user wants to create a temporary directory name. The use of this function is secure in the author's opinion when you have set the temporary directory to a non-shared directory where only your user is allowed to write. **Parameters:** s [out] On success s will contain the generated unique temporary file name. maxsize [in] The size of s. **Returns:** Zero on success. A non-zero value is returned in case of a runtime-constraint violation or if no suitable string can be generated. **See also:** tmpnam int tmpnam_s(char *s, rsize_t maxsize); ``` -------------------------------- ### vsnprintf_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the vsnprintf_s function, which is equivalent to snprintf_s but expects a va_list argument. ```c int vsnprintf_s(char * restrict s, rsize_t n, const char * restrict format, ``` -------------------------------- ### snprintf_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the snprintf_s function, which allows formatted output into a buffer while considering its size. ```c int snprintf_s(char * restrict s, rsize_t n, const char * restrict format, ...) __attribute__ ((format (printf, 3, 4))); ``` -------------------------------- ### strncat_s function signature and description Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h.html The strncat_s function copies at most n characters from string s2 to the end of s1. It requires the size of the destination buffer for safety. ```c errno_t strncat_s( char *restrict _s1_, rsize_t _s1max_, const char *restrict _s2_, rsize_t _n_ ) ``` -------------------------------- ### vsscanf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html The vsscanf_s function is equivalent to sscanf_s but expects a va_list argument. ```c int vsscanf_s(const char *restrict s, const char *restrict format, va_list arg); ``` -------------------------------- ### tmpfile_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the tmpfile_s function, which creates a temporary file. ```c errno_t tmpfile_s(FILE * restrict * restrict streamptr); ``` -------------------------------- ### vsprintf_s function declaration Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h_source.html Declaration of the vsprintf_s function, which is equivalent to sprintf_s but expects a va_list argument. ```c int vsprintf_s(char * restrict s, rsize_t n, const char * restrict format, va_list arg) __attribute__ ((format (printf, 3, 0))); ``` -------------------------------- ### strcpy_s function signature and description Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h.html The strcpy_s function copies the string s2 to s1, ensuring the destination buffer is not overflowed. The size of the destination buffer must be specified. ```c errno_t strcpy_s( char *restrict _s1_, rsize_t _s1max_, const char *restrict _s2_ ) ``` -------------------------------- ### strcpy_s template Source: https://github.com/sbaresearch/slibc/blob/master/docs/string__templates___8hpp_source.html The strcpy_s function copies the string s2 to s1. ```c++ #include "./string.h" template erfno_t strcpy_s(char (&s1)[s1max], const char * restrict s2) { return strcpy_s(s1, s1max, s2); } ``` -------------------------------- ### strcat_s function signature and description Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h.html The strcat_s function copies the string s2 to the end of s1. It requires the size of the destination buffer to perform bounds checking. ```c errno_t strcat_s( char *restrict _s1_, rsize_t _s1max_, const char *restrict _s2_ ) ``` -------------------------------- ### fprintf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html The fprintf_s function is analogous to the _fprintf_ function except that the _n_ specifier is not allowed. ```c int fprintf_s(FILE *restrict stream, const char *restrict format, ...); ``` -------------------------------- ### errno.h Header Content Source: https://github.com/sbaresearch/slibc/blob/master/docs/errno_8h_source.html The content of the errno.h header file, including copyright information, license details, and conditional definitions. ```c /* Copyright (C) 2011-2012 SBA Research gGmbH This file is part of the Slibc Library. The Slibc Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The Slibc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the Slibc Library; if not, see . */ // include the system-header first #include_next // Glibc headers often include errno.h only to get some types // in that case the caller defined __need_TYPE (e.g. __need_Emath) // If errno.h is included in a normal way, it will define the macro _ERRNO_H // (Let's hope that this macro name is portable) #if defined(_ERRNO_H) && !defined(SLIBC_ERRNO_H) #define SLIBC_ERRNO_H // TR 24731-1 is not available if __STDC_WANT_LIB_EXT1__ equals 0 #if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) //TR 24731-1 addition to errno.h typedef int errno_t; #endif #endif ``` -------------------------------- ### strtok_s function signature Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h.html The strtok_s function breaks a string into smaller strings according to a specified delimiter. A sequence of strok_s invocations is necessary to break up a string. On the first call, s1 points to the buffer to be tokenized, s1max denotes its size, delim points to the delimiter string, ptr points to a caller-provided char pointer. On successive calls, s1 should be NULL, while ptr should be unchanged from the previous call. ```c char* strtok_s( char *restrict _s1_, rsize_t *_restrict _s1max_, const char *restrict _delim_, char **restrict _ptr_ ) ``` -------------------------------- ### printf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html The printf_s function behaves like fprintf_s when called with stdout. ```c int printf_s(const char *restrict _format, ...); ``` -------------------------------- ### strncat_s template Source: https://github.com/sbaresearch/slibc/blob/master/docs/string__templates___8hpp_source.html The strncat_s function copies not more than n characters of the string s2 to the end of s1... ```c++ template erfno_t strncat_s(char (&s1)[s1max], const char * restrict s2, rsize_t n) { return strncat_s(s1, s1max, s2, n); } ``` -------------------------------- ### strerror_s function signature and description Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h.html The strerror_s function returns a human-readable error message for a specified error number, copying it to a provided buffer. The buffer size must be specified. ```c errno_t strerror_s( char *_s_, rsize_t _maxsize_, errno_t _errnum_ ) ``` -------------------------------- ### stddef.h Header Content Source: https://github.com/sbaresearch/slibc/blob/master/docs/stddef_8h_source.html The source code for the stddef.h file, including copyright, license information, and type definitions. ```c /* Copyright (C) 2011-2012 SBA Research gGmbH This file is part of the Slibc Library. The Slibc Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The Slibc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the Slibc Library; if not, see . */ // include the system-header first #include_next // Glibc headers often include stddef.h only to get some types. // In that case the caller defined __need_TYPE (e.g. __need_size_t). // If stddef.h is included in a normal way, it will define the macro _STDDEF_H // (Let's hope that this macro name is portable) #if defined(_STDDEF_H) && !defined(SLIBC_STDDEF_H) #define SLIBC_STDDEF_H // TR 24731-1 is not available if __STDC_WANT_LIB_EXT1__ equals 0 #if (!defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__ != 0)) // Not totally sure if this is the correct solution. // The problem is our stddef.h might get included with a // define such as __need_NULL. In that case the above stddef.h // will only define this one datatype and no size_t. // Update: should not be needed any longer since we check // whether _STDDEF_H was defined above //#define __need_size_t //#include_next // TR 24731-1 addition to stddef.h typedef size_t rsize_t; #endif #endif ``` -------------------------------- ### sprintf_s template Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio__templates___8hpp.html This function provides for formatted output into buffer s while taking into account the size of s. For statically allocated destination buffers this C++ template function automatically deducts _sprintf'_ size argument _n_. ```cpp template int sprintf_s( char(& _s1)[n], const char *restrict _format_, ... ) ``` -------------------------------- ### strcat_s template Source: https://github.com/sbaresearch/slibc/blob/master/docs/string__templates___8hpp_source.html The strcat_s function copies the string s2 to the end of s1. ```c++ template erfno_t strcat_s(char (&s1)[s1max], const char * restrict s2) { return strcat_s(s1, s1max, s2); } ``` -------------------------------- ### strncpy_s template function signature Source: https://github.com/sbaresearch/slibc/blob/master/docs/string__templates___8hpp.html The strncpy_s template function signature, which copies the string _s2_ to _s1_. ```cpp template errno_t strncpy_s( char(& _s1_)[s1max], const char *restrict _s2_, rsize_t _n_ ) ``` -------------------------------- ### vscanf_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html Reads formatted input from stdin using a va_list argument. It is equivalent to scanf_s but accepts a va_list. ```c int vscanf_s(const char *restrict format, va_list arg); ``` -------------------------------- ### snprintf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html This function allows formatted output into a buffer 's' while taking into account its size. A maximum of n-1 characters are written into the buffer s, followed by a zero byte. The output is made only without truncation, if the return value is positive (> 0) and the returned value < n. ```c int snprintf_s(char *restrict _s, rsize_t _n, const char *restrict _format, ...); ``` -------------------------------- ### strnlen_s function signature Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h.html The strnlen_s function determines the length of s. At most maxsize characters are accessed and maxsize is returned. Otherwise the number of characters before the nullbyte are returned. The only difference to strnlen is that in case of s being a null pointer this function gracefully returns 0. ```c size_t strnlen_s( const char *_s_, size_t _maxsize_ ) ``` -------------------------------- ### strncpy_s template Source: https://github.com/sbaresearch/slibc/blob/master/docs/string__templates___8hpp_source.html The strncpy_s function copies not more than n characters from s2 to s1. ```c++ template erfno_t strncpy_s(char (&s1)[s1max], const char * restrict s2, rsize_t n) { return strncpy_s(s1, s1max, s2, n); } ``` -------------------------------- ### sprintf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html This function allows formatted output into a buffer 's' while taking into account its size. A maximum of n-1 characters are written into the buffer s, followed by a zero byte. The sprintf_s function, unlike snprintf_s, treats a result too big for the array pointed to by s as a runtime-constraint violation. ```c int sprintf_s(char *restrict _s, rsize_t _n, const char *restrict _format, ...); ``` -------------------------------- ### abort_handler_s Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdlib_8h.html The abort handler gives out an errormessage on stderr before it ends the program with the function abort. ```c void abort_handler_s(const char *restrict msg, void *restrict ptr, errno_t error) ``` -------------------------------- ### scanf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html The scanf_s function behaves like fscanf_s when called with stdin. ```c int scanf_s(const char *restrict _format, ...); ``` -------------------------------- ### RSIZE_MAX Definition Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdint_8h.html Defines the RSIZE_MAX macro, which represents the highest number a value of type rsize_t can contain. ```c #define RSIZE_MAX (SIZE_MAX >> 1) ``` -------------------------------- ### fscanf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html A secure variant of fscanf that expects the caller to specify the size for each buffer argument. ```c int fscanf_s(FILE *restrict stream, const char *restrict format, ...); ``` -------------------------------- ### sscanf_s Function Source: https://github.com/sbaresearch/slibc/blob/master/docs/stdio_8h.html The sscanf_s function is analogous to fscanf_s but reads from a string instead of a stream. ```c int sscanf_s(const char *restrict s, const char *restrict format, ...); ``` -------------------------------- ### strncpy_s function signature Source: https://github.com/sbaresearch/slibc/blob/master/docs/string_8h.html The strncpy_s function copies not more than n characters from s2 to s1. In contrast to strncpy this functions expects the buffer size of s1 as a second parameter. The function will never write beyond the specified buffer size. ```c errno_t strncpy_s( char *restrict _s1_, rsize_t _s1max_, const char *restrict _s2_, rsize_t _n_ ) ```