<commit_before>
#include <errno.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
/*
 * These functions find the absolute path to the current working directory.
 *
 * They don't use malloc or large amounts of stack space.
 */

static char *recurser();		/* Routine to go up tree */
static char *search_dir();		/* Routine to find the step back down */
static char *path_buf;
static int path_size;

static dev_t root_dev;
static ino_t root_ino;

static struct stat st;

char *getcwd(buf, size)
char *buf;
int size;
{
	path_buf = buf;
	path_size = size;

	if (size < 3) {
		errno = ERANGE;
		return 0;
	}
	strcpy(path_buf, ".");

	if (stat("/", &st) < 0)
		return 0;

	root_dev = st.st_dev;
	root_ino = st.st_ino;

	return recurser();
}

static char *recurser()
{
	dev_t this_dev;
	ino_t this_ino;

	if (stat(path_buf, &st) < 0)
		return 0;
	this_dev = st.st_dev;
	this_ino = st.st_ino;
	if (this_dev == root_dev && this_ino == root_ino) {
		strcpy(path_buf, "/");
		return path_buf;<commit_msg>getcwd did not include the alloc-space-as-needed-on-NULL-buffer feature which busybox needed.  So I added it.<commit_after>#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>

/* These functions find the absolute path to the current working directory.  */

static char *recurser();		/* Routine to go up tree */
static char *search_dir();		/* Routine to find the step back down */
static char *path_buf;
static int path_size;

static dev_t root_dev;
static ino_t root_ino;

static struct stat st;

char *getcwd( char *buf, int size)
{
	path_size = size;

	if (size < 3) {
		errno = ERANGE;
		return NULL;
	}

	if (buf != NULL)
	    path_buf = buf;
	else
	{
	    path_buf = malloc (size);
	    if (path_buf == NULL)
		return NULL;
	}

	strcpy(path_buf, ".");

	if (stat("/", &st) < 0)
		return NULL;

	root_dev = st.st_dev;
	root_ino = st.st_ino;

	return recurser();
}

static char *recurser()
{
	dev_t this_dev;
	ino_t this_ino;

	if (stat(path_buf, &st) < 0)
		return 0;
	this_dev = st.st_dev;
	this_ino = st.st_ino;
	if (this_dev == root_dev && this_ino == root_ino) {
		strcpy(path_buf, "/");
		return path_buf;
{'fraction_non_alphanumeric': 0.1355463347164592, 'fraction_numerical': 0.004610419548178884, 'mean_word_length': 3.6072186836518045, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 12, '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': '6571696', 'n_tokens_mistral': 890, 'n_tokens_neox': 845, 'n_words': 254}