<commit_before>/*
    Copyright (C) 1998-2001 by <NAME>
    Written by <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifdef __CS_CSSYSDEFS_H__
#error Do not include cssysdef.h from header files please!
#else
#define __CS_CSSYSDEFS_H__

#define CSDEF_FRIEND
#include "csdef.h"
#undef CSDEF_FRIEND

/** \file

    This include file should be included from every source file.
    Just before #include directive it can contain several #define's
    that specify what the source file requires.

    The following variables can be defined:

    #define CS_SYSDEF_PROVIDE_MKDIR
      Include definition for MKDIR()

    #define CS_SYSDEF_PROVIDE_GETCWD
      Include definition for getcwd()

    #define CS_SYSDEF_PROVIDE_TEMP
      Include definitions for TEMP_DIR and TEMP_FILE.

    #define CS_SYSDEF_PROVIDE_DIR
      Include definitions required for opendir(), readdir(), closedir()
      and isdir().
 
    #define CS_SYSDEF_PROVIDE_UNLINK
      Include definitions required for unlink()

    #define CS_SYSDEF_PROVIDE_ACCESS
      Include definitions required for access()

    #define CS_SYSDEF_PROVIDE_GETOPT
      For getopt() and GNU getopt_long()

    #define CS_SYSDEF_PROVIDE_SELECT
      Includes definitions required for select(), FD_* macros, and
      struct timeval.

    The system-dependent include files can undefine some or all
    CS_SYSDEF_PROVIDE_xxx macros to avoid further definitions in this file.
    For example, if a system-dependent file defines everything needed for
    CS_SYSDEF_PROVIDE_GETOPT it should #undefine CS_SYSDEF_PROVIDE_GETOPT to
    avoid including util/gnu/getopt.h at the bottom of this file.
*/

/*
 * Pull in platform-specific overrides of the requested functionality.
 */
#include "csutil/csosdefs.h"

#include "csextern.h"

/*
 * Default definitions for requested functionality.  Platform-specific
 * configuration files may override these.
 */

/**\def TEMP_DIR
 * Directory for temporary files
 */
#ifdef CS_SYSDEF_PROVIDE_TEMP
#  ifndef TEMP_DIR
#    if defined(OS_UNIX)
#      define TEMP_DIR "/tmp/"
#    else
#      define TEMP_DIR ""
#    endif
#  endif
#  ifndef TEMP_FILE
#    if defined(OS_UNIX)
#      include <unistd.h>
/// Name for temporary file
#      define TEMP_FILE "cs%lud.tmp", (unsigned long)getpid()
#    else
/// Name for temporary file
#      define TEMP_FILE "$cs$.tmp"
#    endif
#  endif
#endif // CS_SYSDEF_PROVIDE_TEMP

/**\def MKDIR(path)
 * How to make a directory (not entire path, only the last on the path)
 */
#ifdef CS_SYSDEF_PROVIDE_MKDIR
#  ifndef MKDIR
#    if defined(OS_WIN32) || (defined(OS_DOS) && !defined(COMP_GCC))
#      define MKDIR(path) _mkdir (path)
#    else
#      define MKDIR(path) mkdir (path, 0755)
#    endif
#  endif
#endif // CS_SYSDEF_PROVIDE_MKDIR

#ifdef CS_SYSDEF_PROVIDE_GETCWD
#  if !defined(COMP_VC) && !defined(COMP_BC)
#    include <unistd.h>
#  endif
#endif // CS_SYSDEF_PROVIDE_GETCWD

#ifdef CS_SYSDEF_PROVIDE_DIR
// For systems without opendir()
// Although COMP_GCC has opendir, readdir, CS' versions are preferred.
# if defined(__NEED_OPENDIR_PROTOTYPE)
     struct DIR;
     struct dirent;
     extern "C" CS_CSUTIL_EXPORT DIR *opendir (const char *name);
     extern "C" CS_CSUTIL_EXPORT dirent *readdir (DIR *dirp);
     extern "C" CS_CSUTIL_EXPORT int closedir (DIR *dirp);
     //extern "C" void seekdir (DIR *dirp, long off);
     //extern "C" long telldir (DIR *dirp);
     //extern "C" void rewinddir (DIR *dirp);
# endif
// Generic ISDIR where needed
#  ifdef __NEED_GENERIC_ISDIR
#    if defined (OS_WIN32) || defined (OS_DOS)
#      include <io.h>
#    endif
#    include <sys/types.h>
#    if !defined(OS_WIN32)
#      include <dirent.h>
#    endif
#    include <sys/stat.h>
     static inline bool isdir (const char *path, struct dirent *de)
     {
       int pathlen = strlen (path);
       CS_ALLOC_STACK_ARRAY(char, fullname, pathlen + 2 + strlen (de->d_name));
       memcpy (fullname, path, pathlen + 1);
       
       if ((pathlen) && (fullname[pathlen-1] != PATH_SEPARATOR))
       {
	 fullname[pathlen++] = PATH_SEPARATOR;
	 fullname[pathlen] = 0;
       }
              
       strcat (&fullname [pathlen], de->d_name);
       struct stat st;
       stat (fullname, &st);
       return ((st.st_mode & S_IFMT) == S_IFDIR);
     }
#  endif
#endif // CS_SYSDEF_PROVIDE_DIR

#ifdef CS_SYSDEF_PROVIDE_UNLINK
#  if !defined(COMP_VC) && !defined(COMP_BC)
#    include <unistd.h>
#  endif
#endif

/**\def CS_ALLOC_STACK_ARRAY(type, var, size)
 * Dynamic stack memory allocation.
 * \param type Type of the array elements.
 * \param var Name of the array to be allocated.
 * \param size Number of elements to be allocated.
 */
#ifdef COMP_GCC
// In GCC we are able to declare stack vars of dynamic size directly
#  define CS_ALLOC_STACK_ARRAY(type, var, size) \
      type var [size]
#else
#  include <malloc.h>
#  define CS_ALLOC_STACK_ARRAY(type, var, size) \
      type *var = (type *)alloca ((size) * sizeof (type))
#endif

#ifdef CS_SYSDEF_PROVIDE_ACCESS
#  if !defined(COMP_VC) && !defined(COMP_BC)
#    include <unistd.h>
#  endif
#  ifndef F_OK
#    define F_OK 0
#  endif
#  ifndef R_OK
#    define R_OK 2
#  endif
#  ifndef W_OK
#    define W_OK 4
#  endif
#endif

#ifdef CS_SYSDEF_PROVIDE_GETOPT
#  ifndef __STDC__
#    define __STDC__ 1
#  endif
#  include "csutil/getopt.h"
#endif

#ifdef CS_SYSDEF_PROVIDE_SOCKETS
# ifdef __GNUC__
#  warning CS_SYSDEF_PROVIDE_SOCKETS is deprecated, include cssys/sockets.h instead<commit_msg>Fixed compiling of generic isdir<commit_after>/*
    Copyright (C) 1998-2001 by <NAME>
    Written by <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifdef __CS_CSSYSDEFS_H__
#error Do not include cssysdef.h from header files please!
#else
#define __CS_CSSYSDEFS_H__

#define CSDEF_FRIEND
#include "csdef.h"
#undef CSDEF_FRIEND

/** \file

    This include file should be included from every source file.
    Just before #include directive it can contain several #define's
    that specify what the source file requires.

    The following variables can be defined:

    #define CS_SYSDEF_PROVIDE_MKDIR
      Include definition for MKDIR()

    #define CS_SYSDEF_PROVIDE_GETCWD
      Include definition for getcwd()

    #define CS_SYSDEF_PROVIDE_TEMP
      Include definitions for TEMP_DIR and TEMP_FILE.

    #define CS_SYSDEF_PROVIDE_DIR
      Include definitions required for opendir(), readdir(), closedir()
      and isdir().
 
    #define CS_SYSDEF_PROVIDE_UNLINK
      Include definitions required for unlink()

    #define CS_SYSDEF_PROVIDE_ACCESS
      Include definitions required for access()

    #define CS_SYSDEF_PROVIDE_GETOPT
      For getopt() and GNU getopt_long()

    #define CS_SYSDEF_PROVIDE_SELECT
      Includes definitions required for select(), FD_* macros, and
      struct timeval.

    The system-dependent include files can undefine some or all
    CS_SYSDEF_PROVIDE_xxx macros to avoid further definitions in this file.
    For example, if a system-dependent file defines everything needed for
    CS_SYSDEF_PROVIDE_GETOPT it should #undefine CS_SYSDEF_PROVIDE_GETOPT to
    avoid including util/gnu/getopt.h at the bottom of this file.
*/

/*
 * Pull in platform-specific overrides of the requested functionality.
 */
#include "csutil/csosdefs.h"

#include "csextern.h"

/*
 * Default definitions for requested functionality.  Platform-specific
 * configuration files may override these.
 */

/**\def CS_ALLOC_STACK_ARRAY(type, var, size)
 * Dynamic stack memory allocation.
 * \param type Type of the array elements.
 * \param var Name of the array to be allocated.
 * \param size Number of elements to be allocated.
 */
#ifdef COMP_GCC
// In GCC we are able to declare stack vars of dynamic size directly
#  define CS_ALLOC_STACK_ARRAY(type, var, size) \
      type var [size]
#else
#  include <malloc.h>
#  define CS_ALLOC_STACK_ARRAY(type, var, size) \
      type *var = (type *)alloca ((size) * sizeof (type))
#endif

/**\def TEMP_DIR
 * Directory for temporary files
 */
#ifdef CS_SYSDEF_PROVIDE_TEMP
#  ifndef TEMP_DIR
#    if defined(OS_UNIX)
#      define TEMP_DIR "/tmp/"
#    else
#      define TEMP_DIR ""
#    endif
#  endif
#  ifndef TEMP_FILE
#    if defined(OS_UNIX)
#      include <unistd.h>
/// Name for temporary file
#      define TEMP_FILE "cs%lud.tmp", (unsigned long)getpid()
#    else
/// Name for temporary file
#      define TEMP_FILE "$cs$.tmp"
#    endif
#  endif
#endif // CS_SYSDEF_PROVIDE_TEMP

/**\def MKDIR(path)
 * How to make a directory (not entire path, only the last on the path)
 */
#ifdef CS_SYSDEF_PROVIDE_MKDIR
#  ifndef MKDIR
#    if defined(OS_WIN32) || (defined(OS_DOS) && !defined(COMP_GCC))
#      define MKDIR(path) _mkdir (path)
#    else
#      define MKDIR(path) mkdir (path, 0755)
#    endif
#  endif
#endif // CS_SYSDEF_PROVIDE_MKDIR

#ifdef CS_SYSDEF_PROVIDE_GETCWD
#  if !defined(COMP_VC) && !defined(COMP_BC)
#    include <unistd.h>
#  endif
#endif // CS_SYSDEF_PROVIDE_GETCWD

#ifdef CS_SYSDEF_PROVIDE_DIR
// For systems without opendir()
// Although COMP_GCC has opendir, readdir, CS' versions are preferred.
# if defined(__NEED_OPENDIR_PROTOTYPE)
     struct DIR;
     struct dirent;
     extern "C" CS_CSUTIL_EXPORT DIR *opendir (const char *name);
     extern "C" CS_CSUTIL_EXPORT dirent *readdir (DIR *dirp);
     extern "C" CS_CSUTIL_EXPORT int closedir (DIR *dirp);
     //extern "C" void seekdir (DIR *dirp, long off);
     //extern "C" long telldir (DIR *dirp);
     //extern "C" void rewinddir (DIR *dirp);
# endif
// Generic ISDIR where needed
#  ifdef __NEED_GENERIC_ISDIR
#    if defined (OS_WIN32) || defined (OS_DOS)
#      include <io.h>
#    endif
#    include <sys/types.h>
#    if !defined(OS_WIN32)
#      include <dirent.h>
#    endif
#    include <sys/stat.h>
     static inline bool isdir (const char *path, struct dirent *de)
     {
       int pathlen = strlen (path);
       CS_ALLOC_STACK_ARRAY(char, fullname, pathlen + 2 + strlen (de->d_name));
       memcpy (fullname, path, pathlen + 1);
       
       if ((pathlen) && (fullname[pathlen-1] != PATH_SEPARATOR))
       {
	 fullname[pathlen++] = PATH_SEPARATOR;
	 fullname[pathlen] = 0;
       }
              
       strcat (&fullname [pathlen], de->d_name);
       struct stat st;
       stat (fullname, &st);
       return ((st.st_mode & S_IFMT) == S_IFDIR);
     }
#  endif
#endif // CS_SYSDEF_PROVIDE_DIR

#ifdef CS_SYSDEF_PROVIDE_UNLINK
#  if !defined(COMP_VC) && !defined(COMP_BC)
#    include <unistd.h>
#  endif
#endif

#ifdef CS_SYSDEF_PROVIDE_ACCESS
#  if !defined(COMP_VC) && !defined(COMP_BC)
#    include <unistd.h>
#  endif
#  ifndef F_OK
#    define F_OK 0
#  endif
#  ifndef R_OK
#    define R_OK 2
#  endif
#  ifndef W_OK
#    define W_OK 4
#  endif
#endif

#ifdef CS_SYSDEF_PROVIDE_GETOPT
#  ifndef __STDC__
#    define __STDC__ 1
#  endif
#  include "csutil/getopt.h"
#endif

#ifdef CS_SYSDEF_PROVIDE_SOCKETS
# ifdef __GNUC__
#  warning CS_SYSDEF_PROVIDE_SOCKETS is deprecated, include cssys/sockets.h instead
{'fraction_non_alphanumeric': 0.0881996607705355, 'fraction_numerical': 0.00565382440836766, 'mean_word_length': 3.364469510045823, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1955398', 'n_tokens_mistral': 4299, 'n_tokens_neox': 4081, 'n_words': 1335}