some libs done

This commit is contained in:
2025-07-13 18:20:10 -04:00
parent 6245723dc0
commit 174e80f4f8
8 changed files with 65 additions and 16 deletions

9
lib/e.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef ERROR_H
#define ERROR_H
typedef struct {
int stat;
const char *src;
} error_t;
#endif

22
lib/file.c Normal file
View File

@@ -0,0 +1,22 @@
#include "file.h"
#include "e.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
error_t write(char *path, char *format, ...) {
error_t err;
va_list args;
va_start(args, format);
FILE *fp;
fp = fopen(path, "w");
if (!fp) {
err.stat = errno;
err.src = strerror(errno);
}
vfprintf(fp, format, args);
fclose(fp);
va_end(args);
return err;
}

9
lib/file.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef FILE_H
#define FILE_H
#include "e.h"
error_t write(char *, char *, ...);
void printfn(char *, ...);
#endif

14
lib/print.c Normal file
View File

@@ -0,0 +1,14 @@
#include "print.h"
#include <stdarg.h>
#include <stdio.h>
int printfn(char *format, ...) {
int len;
va_list args;
va_start(args, format);
printf("yait: ");
len = vfprintf(stderr, format, args);
putchar('\n');
va_end(args);
return len;
}

9
lib/print.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef PRINT_H
#define PRINT_H
#include <stdarg.h>
#include <stdio.h>
int printfn(char *, ...);
#endif