<commit_before># depends on: array.rb

class Dir
  class DirEntry < FFI::Struct            
    # struct dirent {
    #   ino_t d_ino;      /* file number of entry */
    #   __uint16_t d_reclen;    /* length of this record */
    #   __uint8_t  d_type;    /* file type, see below */
    #   __uint8_t  d_namlen;    /* length of string in d_name */
    #   char d_name[__DARWIN_MAXNAMLEN + 1];  /* name must be no longer than this */
    # };
    
    layout  :d_ino,    :uint,
            :d_reclen, :ushort,
            :d_type,   :uchar,
            :d_namlen, :uchar,
            :d_name,   :char_array
  end

  include Enumerable
  
  def self.glob(pattern, flags)
    Ruby.primitive :dir_glob
  end
  
  def self.[](pattern)
    glob(pattern, 0)
  end
  
  def self.chdir(path = ENV['HOME'])
    if block_given?
      original_path = self.getwd
      Platform::POSIX.chdir path
      value = yield path
      Platform::POSIX.chdir original_path
      return value
    else
      error = Platform::POSIX.chdir path
      if error != 0
        Errno.handle path
      end
      error
    end
  end
  
  def self.mkdir(path, mode = 0777)
    error = Platform::POSIX.mkdir(path, mode)
    if error != 0<commit_msg>Dir::glob's flags are optional<commit_after># depends on: array.rb

class Dir
  class DirEntry < FFI::Struct            
    # struct dirent {
    #   ino_t d_ino;      /* file number of entry */
    #   __uint16_t d_reclen;    /* length of this record */
    #   __uint8_t  d_type;    /* file type, see below */
    #   __uint8_t  d_namlen;    /* length of string in d_name */
    #   char d_name[__DARWIN_MAXNAMLEN + 1];  /* name must be no longer than this */
    # };
    
    layout  :d_ino,    :uint,
            :d_reclen, :ushort,
            :d_type,   :uchar,
            :d_namlen, :uchar,
            :d_name,   :char_array
  end

  include Enumerable
  
  def self.glob(pattern, flags = 0)
    prim_glob pattern, flags
  end

  def self.prim_glob(pattern, flags)
    Ruby.primitive :dir_glob
  end
  
  def self.[](pattern)
    glob(pattern, 0)
  end
  
  def self.chdir(path = ENV['HOME'])
    if block_given?
      original_path = self.getwd
      Platform::POSIX.chdir path
      value = yield path
      Platform::POSIX.chdir original_path
      return value
    else
      error = Platform::POSIX.chdir path
      if error != 0
        Errno.handle path
      end
      error
    end
  end
  
  def self.mkdir(path, mode = 0777)
    error = Platform::POSIX.mkdir(path, mode)
    if error != 0
{'fraction_non_alphanumeric': 0.09857482185273159, 'fraction_numerical': 0.009897070467141725, 'mean_word_length': 1.9555555555555555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4509077', 'n_tokens_mistral': 912, 'n_tokens_neox': 868, 'n_words': 230}