<commit_before>/* KallistiOS ##version##

   newlib_stat.c
   Copyright (C)2004 <NAME>

*/

#include <unistd.h>
#include <sys/stat.h>

int _stat_r(void * reent, const char * fn, struct stat * pstat) {
	pstat->st_mode = S_IFCHR;
	return 0;
}<commit_msg>This is a little bit better version of stat(). At least this one will work for a few common use-cases of it...<commit_after>/* KallistiOS ##version##

   newlib_stat.c
   Copyright (C) 2004 <NAME>
   Copyright (C) 2011 <NAME>

*/

#include <unistd.h>
#include <sys/stat.h>
#include <sys/reent.h>
#include <kos/fs.h>
#include <errno.h>

int _stat_r(struct _reent * reent, const char * fn, struct stat * pstat) {
    file_t fp = fs_open(fn, O_RDONLY);
    mode_t md = S_IFREG;

    /* If we couldn't get it as a file, try as a directory */
    if(fp == FILEHND_INVALID) {
        fp = fs_open(fn, O_RDONLY | O_DIR);
        md = S_IFDIR;
    }

    /* If we still don't have it, then we're not going to get it. */
    if(fp == FILEHND_INVALID) {
        reent->_errno = ENOENT;
        return -1;
    }

    /* This really doesn't convey all that much information, but it should help
       with at least some uses of stat. */
    pstat->st_mode = md;
    pstat->st_size = (off_t)fs_total(fp);

    /* Clean up after ourselves. */
    fs_close(fp);

    return 0;
}
{'fraction_non_alphanumeric': 0.13155893536121674, 'fraction_numerical': 0.011406844106463879, 'mean_word_length': 2.76, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '3723708', 'n_tokens_mistral': 510, 'n_tokens_neox': 484, 'n_words': 153}