<commit_before>/* 
 * (c) The GRASP/AQUA Project, Glasgow University, 1994-
 *
 * Directory Runtime Support
 */
#include "dirUtils.h"

#if defined(mingw32_TARGET_OS)
#include <windows.h>
#endif

#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif

HsInt
prel_mkdir(HsAddr pathName, HsInt mode)
{
#if defined(mingw32_TARGET_OS)
  return mkdir(pathName);
#else
  return mkdir(pathName,mode);
#endif
}

HsInt
prel_lstat(HsAddr fname, HsAddr st)
{
#ifdef HAVE_LSTAT
  return lstat((const char*)fname, (struct stat*)st);
#else
  return stat((const char*)fname, (struct stat*)st);
#endif
}

HsInt prel_s_ISDIR(mode_t m) {return S_ISDIR(m);}
HsInt prel_s_ISREG(mode_t m) {return S_ISREG(m);}

HsInt prel_path_max() { return PATH_MAX; }
mode_t prel_R_OK() { return R_OK; }
mode_t prel_W_OK() { return W_OK; }
mode_t prel_X_OK() { return X_OK; }

mode_t prel_S_IRUSR() { return S_IRUSR; }
mode_t prel_S_IWUSR() { return S_IWUSR; }
mode_t prel_S_IXUSR() { return S_IXUSR; }

HsAddr prel_d_name(struct dirent* d)
{ 
#ifndef mingw32_TARGET_OS
  return (HsAddr)(&d->d_name);
#else
  return (HsAddr)(d->d_name);
#endif
}

HsInt prel_end_of_dir()
{
#ifndef mingw32_TARGET_OS
  return 0;
#else
  return ENOENT;
#endif  
}

/*
 * read an entry from the directory stream; opt for the
 * re-entrant friendly way of doing this, if available.
 */
HsInt
prel_readdir(HsAddr dirPtr, HsAddr pDirEnt)
{
#if HAVE_READDIR_R
  struct dirent* p;
  struct dirent* r;
  int res;
  static unsigned int nm_max = -1;
  
  if ((struct dirent**)pDirEnt == NULL) {
    return -1;
  }
  if (nm_max == -1) {
#ifdef NAME_MAX
    nm_max = NAME_MAX;
#else
    char* res;
    nm_max = pathconf(res, _PC_NAME_MAX);
    if (nm_max == -1) { nm_max = 256; }
#endif
  }
  p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);
  res = readdir_r((DIR*)dirPtr, p, (struct dirent**)pDirEnt);
  if (res != 0) {
    *pDirEnt = NULL;
    free(p);
  }
  return res;
#else
  struct dirent **pDirE = (struct dirent**)pDirEnt;

  if (pDirE == NULL) {
    return -1;
  }

  *pDirE = readdir((DIR*)dirPtr);
  if (*pDirE == NULL) {
    return -1;
  } else {
    return 0;<commit_msg>[project @ 2002-01-04 23:21:18 by sof] prel_readdir: tidied<commit_after>/* 
 * (c) The GRASP/AQUA Project, Glasgow University, 1994-
 *
 * Directory Runtime Support
 */
#include "dirUtils.h"

#if defined(mingw32_TARGET_OS)
#include <windows.h>
#endif

#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif

HsInt
prel_mkdir(HsAddr pathName, HsInt mode)
{
#if defined(mingw32_TARGET_OS)
  return mkdir(pathName);
#else
  return mkdir(pathName,mode);
#endif
}

HsInt
prel_lstat(HsAddr fname, HsAddr st)
{
#ifdef HAVE_LSTAT
  return lstat((const char*)fname, (struct stat*)st);
#else
  return stat((const char*)fname, (struct stat*)st);
#endif
}

HsInt prel_s_ISDIR(mode_t m) {return S_ISDIR(m);}
HsInt prel_s_ISREG(mode_t m) {return S_ISREG(m);}

HsInt prel_path_max() { return PATH_MAX; }
mode_t prel_R_OK() { return R_OK; }
mode_t prel_W_OK() { return W_OK; }
mode_t prel_X_OK() { return X_OK; }

mode_t prel_S_IRUSR() { return S_IRUSR; }
mode_t prel_S_IWUSR() { return S_IWUSR; }
mode_t prel_S_IXUSR() { return S_IXUSR; }

HsAddr prel_d_name(struct dirent* d)
{ 
#ifndef mingw32_TARGET_OS
  return (HsAddr)(&d->d_name);
#else
  return (HsAddr)(d->d_name);
#endif
}

HsInt prel_end_of_dir()
{
#ifndef mingw32_TARGET_OS
  return 0;
#else
  return ENOENT;
#endif  
}

/*
 * read an entry from the directory stream; opt for the
 * re-entrant friendly way of doing this, if available.
 */
HsInt
prel_readdir(HsAddr dirPtr, HsAddr pDirEnt)
{
  struct dirent **pDirE = (struct dirent**)pDirEnt;
#if HAVE_READDIR_R
  struct dirent* p;
  struct dirent* r;
  int res;
  static unsigned int nm_max = -1;
  
  if (pDirE == NULL) {
    return -1;
  }
  if (nm_max == -1) {
#ifdef NAME_MAX
    nm_max = NAME_MAX;
#else
    char* res;
    nm_max = pathconf(res, _PC_NAME_MAX);
    if (nm_max == -1) { nm_max = 256; }
#endif
  }
  p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);
  res = readdir_r((DIR*)dirPtr, p, pDirE);
  if (res != 0) {
    *pDirE = NULL;
    free(p);
  }
  return res;
#else

  if (pDirE == NULL) {
    return -1;
  }

  *pDirE = readdir((DIR*)dirPtr);
  if (*pDirE == NULL) {
    return -1;
  } else {
    return 0;
{'fraction_non_alphanumeric': 0.1381016644174539, 'fraction_numerical': 0.013945119208277103, 'mean_word_length': 4.123271889400922, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '4304882', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1899, 'n_words': 457}