<commit_before>// NanoWin32
// -----------------------------------------------------------------------
// Simple library to subset Win32(64) API functions implemenation on POSIX
// This software distributed by MIT license

// Microsoft safe string extensions

#if !defined(NanoWinMsvcSafeStringIncluded)
#define NanoWinMsvcSafeStringIncluded

#if defined(__GNUC__)

#if !defined(_countof)
#define _countof(arr)		(sizeof(arr)/sizeof(arr[0]))
#endif

#if !defined(NW_ERRNO_T_DEFINED)
#define NW_ERRNO_T_DEFINED
typedef int errno_t;		// Not defined by GNU C (standard assumed errno is int always)
#endif

#include <string.h>
#include <stdarg.h>

#ifndef NW_EXTERN_C_BEGIN
#ifdef __cplusplus
#define NW_EXTERN_C_BEGIN  extern "C" {
#define NW_EXTERN_C_END    }
#else
#define NW_EXTERN_C_BEGIN  // None
#define NW_EXTERN_C_END    // None
#endif
#endif

#if !defined(RSIZE_MAX)

typedef size_t rsize_t;

#ifndef RSIZE_MAX_MEM
#define RSIZE_MAX_MEM (0x03FFFFFF)      // "reasonable" max for memory operations: 64M
#endif

#ifndef RSIZE_MAX_STR
#define RSIZE_MAX_STR (256*1024)        // "reasonable" max for string operations: 256K
#endif

#define RSIZE_MAX     (((RSIZE_MAX_MEM) > (RSIZE_MAX_STR)) ? (RSIZE_MAX_MEM) : (RSIZE_MAX_STR))

#else

#ifndef RSIZE_MAX_MEM
#define RSIZE_MAX_MEM RSIZE_MAX         // "reasonable" max for memory operations: RSIZE_MAX
#endif

#ifndef RSIZE_MAX_STR
#define RSIZE_MAX_STR (RSIZE_MAX/2)     // "reasonable" max for string operations: RSIZE_MAX/2
#endif

#endif


#ifndef NW_NO_MS_STR_S_TRUNCATE // Support _TRUNCATE semanic a-la MS VisualC [define this to turn support off]
#define NW_STR_S_TRUNCATE     // define this if you need MS-compatible _TRUNCATE semantic to be supported in module body
#define _TRUNCATE (RSIZE_MAX) // Value to pass to strncpy_s and alike to allow return truncated results as-is // (Relay fact that on RSIZE_MAX anyway is quit hight)
#define STRUNCATE (-11111)    // error_t value to return in case of truncation occurs
#endif

// NanoWin add-ons
// -----------------------------------------------------

#ifdef __cplusplus

// Returns count of items in array
template<typename T1, size_t size1>
size_t NanoWinCountOf(T1(&)[size1])
{ 
  return(size1);
};

#endif

// Macroses to convert safe string to safe templates
// -----------------------------------------------------

#ifdef __cplusplus

// Templates for funcs that return specific O_t

#define NW_T_STR_DN_S0Param(O_t,strfunc_s)                           \
template<typename TD, size_t sizeD>                                  \
O_t strfunc_s(TD (&dest)[sizeD])                                     \
{                                                                    \
  return(strfunc_s(dest, sizeD));                                    \
};

#define NW_T_STR_DN_S1Param(O_t,strfunc_s,arg1_t)                    \
template<typename TD, size_t sizeD>                                  \
O_t strfunc_s(TD (&dest)[sizeD], arg1_t arg1)                        \
{                                                                    \
  return(strfunc_s(dest, sizeD, arg1));                              \
};

#define NW_T_STR_DN_S2Param(O_t,strfunc_s,arg1_t,arg2_t)             \
template<typename TD, size_t sizeD>                                  \
O_t strfunc_s(TD (&dest)[sizeD], arg1_t arg1, arg2_t arg2)           \
{                                                                    \
  return(strfunc_s(dest, sizeD, arg1, arg2));                        \
};

// Templates for funcs that return errno_t

#define NW_STR_DN0Param(strfunc_s)                                   NW_T_STR_DN_S0Param(errno_t,strfunc_s)
#define NW_STR_DN1Param(strfunc_s,arg1_t)                            NW_T_STR_DN_S1Param(errno_t,strfunc_s,arg1_t)
#define NW_STR_DN2Param(strfunc_s,arg1_t,arg2_t)                     NW_T_STR_DN_S2Param(errno_t,strfunc_s,arg1_t,arg2_t)

#endif

// Memory functions
// -----------------------------------------------------

NW_EXTERN_C_BEGIN

// Fills count items(bytes) with ch(lower byte) to dest, dest size is limited to destsz items(bytes). returns errno_t (0 if ok)
extern errno_t memset_s      (void *dest, rsize_t destsz, int ch, rsize_t count);

// Copy count items(bytes) of src to dest, src and dest must not overlap, dest size is limited to destsz items(bytes). returns errno_t (0 if ok)
extern errno_t memcpy_s      (void *dest, rsize_t destsz, const void *src, rsize_t count);

// Copy count items(wchar_t) of src to dest, src and dest must not overlap, dest size is limited to destsz items(wchar_t). returns errno_t (0 if ok)
extern errno_t wmemcpy_s     (wchar_t *dest, rsize_t destsz, const wchar_t *src, rsize_t count);

// Copy count items(bytes) of src to dest, guaranteeing correct behavior for overlapping memeory, dest size is limited to destsz items(bytes). returns errno_t (0 if ok)
extern errno_t memmove_s     (void *dest, rsize_t destsz, const void *src, rsize_t count);

// Copy count items(wchar_t) of src to dest, guaranteeing correct behavior for overlapping memory, dest size is limited to destsz items(wchar_t). returns errno_t (0 if ok)
extern errno_t wmemmove_s    (void *dest, rsize_t destsz, const void *src, rsize_t count);
<commit_msg>Added NW_T_STR_DN_S3Param and NW_T_STR_DN_S4Param safe dates macroses<commit_after>// NanoWin32
// -----------------------------------------------------------------------
// Simple library to subset Win32(64) API functions implemenation on POSIX
// This software distributed by MIT license

// Microsoft safe string extensions

#if !defined(NanoWinMsvcSafeStringIncluded)
#define NanoWinMsvcSafeStringIncluded

#if defined(__GNUC__)

#if !defined(_countof)
#define _countof(arr)		(sizeof(arr)/sizeof(arr[0]))
#endif

#if !defined(NW_ERRNO_T_DEFINED)
#define NW_ERRNO_T_DEFINED
typedef int errno_t;		// Not defined by GNU C (standard assumed errno is int always)
#endif

#include <string.h>
#include <stdarg.h>

#ifndef NW_EXTERN_C_BEGIN
#ifdef __cplusplus
#define NW_EXTERN_C_BEGIN  extern "C" {
#define NW_EXTERN_C_END    }
#else
#define NW_EXTERN_C_BEGIN  // None
#define NW_EXTERN_C_END    // None
#endif
#endif

#if !defined(RSIZE_MAX)

typedef size_t rsize_t;

#ifndef RSIZE_MAX_MEM
#define RSIZE_MAX_MEM (0x03FFFFFF)      // "reasonable" max for memory operations: 64M
#endif

#ifndef RSIZE_MAX_STR
#define RSIZE_MAX_STR (256*1024)        // "reasonable" max for string operations: 256K
#endif

#define RSIZE_MAX     (((RSIZE_MAX_MEM) > (RSIZE_MAX_STR)) ? (RSIZE_MAX_MEM) : (RSIZE_MAX_STR))

#else

#ifndef RSIZE_MAX_MEM
#define RSIZE_MAX_MEM RSIZE_MAX         // "reasonable" max for memory operations: RSIZE_MAX
#endif

#ifndef RSIZE_MAX_STR
#define RSIZE_MAX_STR (RSIZE_MAX/2)     // "reasonable" max for string operations: RSIZE_MAX/2
#endif

#endif


#ifndef NW_NO_MS_STR_S_TRUNCATE // Support _TRUNCATE semanic a-la MS VisualC [define this to turn support off]
#define NW_STR_S_TRUNCATE     // define this if you need MS-compatible _TRUNCATE semantic to be supported in module body
#define _TRUNCATE (RSIZE_MAX) // Value to pass to strncpy_s and alike to allow return truncated results as-is // (Relay fact that on RSIZE_MAX anyway is quit hight)
#define STRUNCATE (-11111)    // error_t value to return in case of truncation occurs
#endif

// NanoWin add-ons
// -----------------------------------------------------

#ifdef __cplusplus

// Returns count of items in array
template<typename T1, size_t size1>
size_t NanoWinCountOf(T1(&)[size1])
{ 
  return(size1);
};

#endif

// Macroses to convert safe string to safe templates
// -----------------------------------------------------

#ifdef __cplusplus

// Templates for funcs that return specific O_t

#define NW_T_STR_DN_S0Param(O_t,strfunc_s)                           \
template<typename TD, size_t sizeD>                                  \
O_t strfunc_s(TD (&dest)[sizeD])                                     \
{                                                                    \
  return(strfunc_s(dest, sizeD));                                    \
};

#define NW_T_STR_DN_S1Param(O_t,strfunc_s,arg1_t)                    \
template<typename TD, size_t sizeD>                                  \
O_t strfunc_s(TD (&dest)[sizeD], arg1_t arg1)                        \
{                                                                    \
  return(strfunc_s(dest, sizeD, arg1));                              \
};

#define NW_T_STR_DN_S2Param(O_t,strfunc_s,arg1_t,arg2_t)             \
template<typename TD, size_t sizeD>                                  \
O_t strfunc_s(TD (&dest)[sizeD], arg1_t arg1, arg2_t arg2)           \
{                                                                    \
  return(strfunc_s(dest, sizeD, arg1, arg2));                        \
};

#define NW_T_STR_DN_S3Param(O_t,strfunc_s,arg1_t,arg2_t,arg3_t)           \
template<typename TD, size_t sizeD>                                       \
O_t strfunc_s(TD (&dest)[sizeD], arg1_t arg1, arg2_t arg2, arg3_t arg3)   \
{                                                                         \
  return(strfunc_s(dest, sizeD, arg1, arg2, arg3));                       \
};

#define NW_T_STR_DN_S4Param(O_t,strfunc_s,arg1_t,arg2_t,arg3_t,arg4_t)                   \
template<typename TD, size_t sizeD>                                                      \
O_t strfunc_s(TD (&dest)[sizeD], arg1_t arg1, arg2_t arg2, arg3_t arg3, arg4_t arg4)     \
{                                                                                        \
  return(strfunc_s(dest, sizeD, arg1, arg2, arg3, arg4));                                \
};


// Templates for funcs that return errno_t

#define NW_STR_DN0Param(strfunc_s)                                   NW_T_STR_DN_S0Param(errno_t,strfunc_s)
#define NW_STR_DN1Param(strfunc_s,arg1_t)                            NW_T_STR_DN_S1Param(errno_t,strfunc_s,arg1_t)
#define NW_STR_DN2Param(strfunc_s,arg1_t,arg2_t)                     NW_T_STR_DN_S2Param(errno_t,strfunc_s,arg1_t,arg2_t)

#endif

// Memory functions
// -----------------------------------------------------

NW_EXTERN_C_BEGIN

// Fills count items(bytes) with ch(lower byte) to dest, dest size is limited to destsz items(bytes). returns errno_t (0 if ok)
extern errno_t memset_s      (void *dest, rsize_t destsz, int ch, rsize_t count);

// Copy count items(bytes) of src to dest, src and dest must not overlap, dest size is limited to destsz items(bytes). returns errno_t (0 if ok)
extern errno_t memcpy_s      (void *dest, rsize_t destsz, const void *src, rsize_t count);

// Copy count items(wchar_t) of src to dest, src and dest must not overlap, dest size is limited to destsz items(wchar_t). returns errno_t (0 if ok)
extern errno_t wmemcpy_s     (wchar_t *dest, rsize_t destsz, const wchar_t *src, rsize_t count);

// Copy count items(bytes) of src to dest, guaranteeing correct behavior for overlapping memeory, dest size is limited to destsz items(bytes). returns errno_t (0 if ok)
extern errno_t memmove_s     (void *dest, rsize_t destsz, const void *src, rsize_t count);

// Copy count items(wchar_t) of src to dest, guaranteeing correct behavior for overlapping memory, dest size is limited to destsz items(wchar_t). returns errno_t (0 if ok)
extern errno_t wmemmove_s    (void *dest, rsize_t destsz, const void *src, rsize_t count);

{'fraction_non_alphanumeric': 0.12141846480367881, 'fraction_numerical': 0.014503006720905553, 'mean_word_length': 2.176685393258427, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1749053', 'n_tokens_mistral': 3790, 'n_tokens_neox': 3585, 'n_words': 1009}