save
This commit is contained in:
9
core/e.h
Normal file
9
core/e.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef ERROR_H
|
||||
#define ERROR_H
|
||||
|
||||
typedef struct {
|
||||
int stat;
|
||||
const char *src;
|
||||
} error_t;
|
||||
|
||||
#endif
|
||||
22
core/file.c
Normal file
22
core/file.c
Normal 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
core/file.h
Normal file
9
core/file.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef FILE_H
|
||||
#define FILE_H
|
||||
|
||||
#include "e.h"
|
||||
|
||||
error_t write(char *, char *, ...);
|
||||
void printfn(char *, ...);
|
||||
|
||||
#endif
|
||||
14
core/print.c
Normal file
14
core/print.c
Normal 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);
|
||||
fprintf(stderr, "yait: ");
|
||||
len = vfprintf(stderr, format, args);
|
||||
putchar('\n');
|
||||
va_end(args);
|
||||
return len;
|
||||
}
|
||||
9
core/print.h
Normal file
9
core/print.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef PRINT_H
|
||||
#define PRINT_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int printfn(char *, ...);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user