<commit_before>/*
 * Define a minimal POSIX-compatible API to allow the OCaml runtime to compile.
 *
 * Most functions either always return an error or panic. A few
 * actually do something:
 *
 * - atoi and calloc are implemented
 * - write(1 or 2, ...) uses printk to display the output
 * - exit calls do_exit
 *
 * Based on Mini-OS sys.c by <NAME> <<EMAIL>>,
 * October 2007.
 */

#include <mini-os/os.h>
#include <mini-os/lib.h>
#include <mini-os/xmalloc.h>
#include <mini-os/time.h>
#include <time.h>
#include <errno.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/times.h>
#include "fmt_fp.h"
#define HUGE_VAL	(__builtin_huge_val())

#define     ENOSYS          38      /* Function not implemented */

#define print_unsupported(fmt, ...) \
    printk("Unsupported function "fmt" called in Mini-OS kernel\n", ## __VA_ARGS__);

/* Crash on function call */
#define unsupported_function_crash(function) \
    int __unsup_##function(void) asm(#function); \
    int __unsup_##function(void) \
    { \
	print_unsupported(#function); \
	do_exit(); \
    }

/* Log and err out on function call */
#define unsupported_function_log(type, function, ret) \
    type __unsup_##function(void) asm(#function); \
    type __unsup_##function(void) \
    { \
	print_unsupported(#function); \
	errno = ENOSYS; \
	return ret; \
    }

/* Err out on function call */
#define unsupported_function(type, function, ret) \
    type __unsup_##function(void) asm(#function); \
    type __unsup_##function(void) \
    { \
	errno = ENOSYS; \
	return ret; \
    }

void *stderr = NULL;
void *stdout = NULL;
void * __stack_chk_guard = NULL;

char *getenv(const char *name)
{
  printk("getenv(%s) -> null\n", name);
  return NULL;
}

void* calloc(size_t nmemb, size_t _size)
{
  register size_t size=_size*nmemb;
  void* x=malloc(size);
  memset(x,0,size);
  return x;
}

ssize_t write(int fd, const void *buf, size_t count)
{
  if (fd == 1 || fd == 2)
  {
    console_print(NULL, (char *) buf, count);
  }
  else
  {
    printk("Error: write to FD %d: '%*s'\n", fd, (int) count, (char *) buf);
  }
  return count;
}

void exit(int status)
{
  printk("Mirage exiting with status %d\n", status);
  do_exit();
}

int atoi(const char *nptr)
{
  return simple_strtoul(nptr, NULL, 10);
}

int open64(const char *pathname, int flags, ...)
{
  printk("Attempt to open(%s)!\n", pathname);
  return -1;
}

struct _buffer {
    char *buf;
    char *end;
};

void out(buffer_t *f, const char *s, size_t l)
{
    while (l > 0) {
        if (f->buf <= f->end)
            *(f->buf++) = *(s++);
        --l;
    }
}

int fprintf(void *stream, const char *fmt, ...)
{
  va_list  args;
  va_start(args, fmt);
  print(0, fmt, args);
  va_end(args);
  return 1;
}

int printf(const char *fmt, ...)
{
  va_list args;
  va_start(args, fmt);
  print(0, fmt, args);
  va_end(args);
  return 1;
}

int fflush (void * stream)
{
  return 0;
}

void abort(void)
{
  printk("Abort called!\n");
  do_exit();
}

#define ZEROPAD 1               /* pad with zero */
#define SIGN    2               /* unsigned/signed long */
#define PLUS    4               /* show plus */
#define SPACE   8               /* space if plus */
#define LEFT    16              /* left justified */
#define SPECIAL 32              /* 0x */
#define LARGE   64              /* use 'ABCDEF' instead of 'abcdef' */

char *minios_printf_render_float(char *buf, char *end, long double y, char fmt, char qualifier, int size, int precision, int type)
{
    buffer_t buffer = {
        .buf = buf,
        .end = end
    };
    int fl = 0;<commit_msg>fix unused parameter warnings in mini_libc<commit_after>/*
 * Define a minimal POSIX-compatible API to allow the OCaml runtime to compile.
 *
 * Most functions either always return an error or panic. A few
 * actually do something:
 *
 * - atoi and calloc are implemented
 * - write(1 or 2, ...) uses printk to display the output
 * - exit calls do_exit
 *
 * Based on Mini-OS sys.c by <NAME> <<EMAIL>>,
 * October 2007.
 */

#include <mini-os/os.h>
#include <mini-os/lib.h>
#include <mini-os/xmalloc.h>
#include <mini-os/time.h>
#include <time.h>
#include <errno.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/times.h>
#include "fmt_fp.h"
#define HUGE_VAL	(__builtin_huge_val())

#define     ENOSYS          38      /* Function not implemented */

#define print_unsupported(fmt, ...) \
    printk("Unsupported function "fmt" called in Mini-OS kernel\n", ## __VA_ARGS__);

/* Crash on function call */
#define unsupported_function_crash(function) \
    int __unsup_##function(void) asm(#function); \
    int __unsup_##function(void) \
    { \
	print_unsupported(#function); \
	do_exit(); \
    }

/* Log and err out on function call */
#define unsupported_function_log(type, function, ret) \
    type __unsup_##function(void) asm(#function); \
    type __unsup_##function(void) \
    { \
	print_unsupported(#function); \
	errno = ENOSYS; \
	return ret; \
    }

/* Err out on function call */
#define unsupported_function(type, function, ret) \
    type __unsup_##function(void) asm(#function); \
    type __unsup_##function(void) \
    { \
	errno = ENOSYS; \
	return ret; \
    }

#define UNUSED __attribute__((__unused__))

void *stderr = NULL;
void *stdout = NULL;
void * __stack_chk_guard = NULL;

char *getenv(const char *name)
{
  printk("getenv(%s) -> null\n", name);
  return NULL;
}

void* calloc(size_t nmemb, size_t _size)
{
  register size_t size=_size*nmemb;
  void* x=malloc(size);
  memset(x,0,size);
  return x;
}

ssize_t write(int fd, const void *buf, size_t count)
{
  if (fd == 1 || fd == 2)
  {
    console_print(NULL, (char *) buf, count);
  }
  else
  {
    printk("Error: write to FD %d: '%*s'\n", fd, (int) count, (char *) buf);
  }
  return count;
}

void exit(int status)
{
  printk("Mirage exiting with status %d\n", status);
  do_exit();
}

int atoi(const char *nptr)
{
  return simple_strtoul(nptr, NULL, 10);
}

int open64(const char *pathname, int flags UNUSED, ...)
{
  printk("Attempt to open(%s)!\n", pathname);
  return -1;
}

struct _buffer {
    char *buf;
    char *end;
};

void out(buffer_t *f, const char *s, size_t l)
{
    while (l > 0) {
        if (f->buf <= f->end)
            *(f->buf++) = *(s++);
        --l;
    }
}

int fprintf(void *stream UNUSED, const char *fmt, ...)
{
  va_list  args;
  va_start(args, fmt);
  print(0, fmt, args);
  va_end(args);
  return 1;
}

int printf(const char *fmt, ...)
{
  va_list args;
  va_start(args, fmt);
  print(0, fmt, args);
  va_end(args);
  return 1;
}

int fflush (void * stream UNUSED)
{
  return 0;
}

void abort(void)
{
  printk("Abort called!\n");
  do_exit();
}

#define ZEROPAD 1               /* pad with zero */
#define SIGN    2               /* unsigned/signed long */
#define PLUS    4               /* show plus */
#define SPACE   8               /* space if plus */
#define LEFT    16              /* left justified */
#define SPECIAL 32              /* 0x */
#define LARGE   64              /* use 'ABCDEF' instead of 'abcdef' */

char *minios_printf_render_float(char *buf, char *end, long double y, char fmt, char qualifier UNUSED, int size, int precision, int type)
{
    buffer_t buffer = {
        .buf = buf,
        .end = end
    };
    int fl = 0;
{'fraction_non_alphanumeric': 0.15120606478290835, 'fraction_numerical': 0.009372846312887664, 'mean_word_length': 2.779166666666667, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 37, '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': '1521250', 'n_tokens_mistral': 2726, 'n_tokens_neox': 2617, 'n_words': 743}