<commit_before>//  Copyright 2010 <NAME>
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

// this file contains cross-platform APIs
// in the ideal world, we would use an existing library, like APR or Boost. In
// the early days of this project, it was decided to keep the code as free
// from external dependencies as possible. As this namespace becomes larger
// and larger, we have to start questioning that decision.

#ifndef ZIPPYLOG_PLATFORM_HPP_
#define ZIPPYLOG_PLATFORM_HPP_

#include <zippylog/zippylog.h>

#ifdef WINDOWS
#include <winsock2.h>
#include <Windows.h>

#elif LINUX
// TODO should be pulled from build tools
#define HAVE_OPENDIR 1

#include <signal.h>
#include <time.h>
#endif

#include <map>
#include <string>
#include <vector>

namespace zippylog {

// TODO move these last remaining APIs to platform namespace
typedef void * (* thread_start_func)(void *);

void windows_error(char *buffer, size_t buffer_size);

// new namespace where all APIs should be
namespace platform {
    using ::std::map;
    using ::std::string;
    using ::std::vector;

    // records the last known system error
    void set_system_error();

    // attempts to retrieve the current system error
    // if the current system error is not defined, returns false
    // else, returns true and puts the error message in the string variable
    // will reset the current system error on call
    bool get_system_error(string &string);

    // sleeps the current thread for specified amount of milliseconds
    void sleep(uint32 milliseconds);

    typedef struct DirectoryEntry {
        string name;
        uint64 size;
        enum FileType type;
    } DirectoryEntry;

    bool DirectoryEntries(const string &dir, vector<DirectoryEntry> &v);
    bool FilesInDirectory(const string &dir, vector<DirectoryEntry> &v);
    bool FilesInDirectory(const string &dir, vector<string> &v);
    bool DirectoriesInDirectory(const string &dir, vector<DirectoryEntry> &v);
    bool DirectoriesInDirectory(const string &dir, vector<string> &v);

    enum FileType {
        REGULAR = 1,
        DIRECTORY = 2,
        PIPE = 3,
        CHARACTER = 4,
        UNKNOWN = 5,
    };

    typedef struct FileStat {
        FileType type;
        int64 size;
    } FileStat;

    ZIPPYLOG_EXPORT bool stat(const string path, FileStat &st);

    typedef struct Time {
        int32 year;
        int32 mon;
        int32 mday;
        int32 hour;
        int32 min;<commit_msg>declare FileType enum before it is used elsewhere in file scope<commit_after>//  Copyright 2010 <NAME>
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

// this file contains cross-platform APIs
// in the ideal world, we would use an existing library, like APR or Boost. In
// the early days of this project, it was decided to keep the code as free
// from external dependencies as possible. As this namespace becomes larger
// and larger, we have to start questioning that decision.

#ifndef ZIPPYLOG_PLATFORM_HPP_
#define ZIPPYLOG_PLATFORM_HPP_

#include <zippylog/zippylog.h>

#ifdef WINDOWS
#include <winsock2.h>
#include <Windows.h>

#elif LINUX
// TODO should be pulled from build tools
#define HAVE_OPENDIR 1

#include <signal.h>
#include <time.h>
#endif

#include <map>
#include <string>
#include <vector>

namespace zippylog {

// TODO move these last remaining APIs to platform namespace
typedef void * (* thread_start_func)(void *);

void windows_error(char *buffer, size_t buffer_size);

// new namespace where all APIs should be
namespace platform {
    using ::std::map;
    using ::std::string;
    using ::std::vector;

    // records the last known system error
    void set_system_error();

    // attempts to retrieve the current system error
    // if the current system error is not defined, returns false
    // else, returns true and puts the error message in the string variable
    // will reset the current system error on call
    bool get_system_error(string &string);

    // sleeps the current thread for specified amount of milliseconds
    void sleep(uint32 milliseconds);

    enum FileType {
        REGULAR = 1,
        DIRECTORY = 2,
        PIPE = 3,
        CHARACTER = 4,
        UNKNOWN = 5,
    };

    typedef struct DirectoryEntry {
        string name;
        uint64 size;
        enum FileType type;
    } DirectoryEntry;

    bool DirectoryEntries(const string &dir, vector<DirectoryEntry> &v);
    bool FilesInDirectory(const string &dir, vector<DirectoryEntry> &v);
    bool FilesInDirectory(const string &dir, vector<string> &v);
    bool DirectoriesInDirectory(const string &dir, vector<DirectoryEntry> &v);
    bool DirectoriesInDirectory(const string &dir, vector<string> &v);

    typedef struct FileStat {
        FileType type;
        int64 size;
    } FileStat;

    ZIPPYLOG_EXPORT bool stat(const string path, FileStat &st);

    typedef struct Time {
        int32 year;
        int32 mon;
        int32 mday;
        int32 hour;
        int32 min;
{'fraction_non_alphanumeric': 0.08127914723517655, 'fraction_numerical': 0.010326449033977348, 'mean_word_length': 3.149965445749827, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3918514', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1640, 'n_words': 701}