This commit is contained in:
2025-07-18 15:44:30 -04:00
parent cf26cdc4b9
commit 50e964d3a0
6 changed files with 71 additions and 65 deletions

View File

@@ -1,14 +0,0 @@
#include "e.h"
#include "print.h"
#include <stdlib.h>
error_t
unwrap (error_t err)
{
if (!err.null)
{
printfn ("error: %s", err.src);
exit (err.status);
}
return err;
}

View File

@@ -1,14 +0,0 @@
#ifndef ERROR_H
#define ERROR_H
#include <stdbool.h>
typedef struct {
bool null;
int status;
const char *src;
} error_t;
error_t unwrap(error_t);
#endif

View File

@@ -1,25 +1,17 @@
#include "file.h"
#include "e.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
error_t
int
touch (char *path, char *format, ...)
{
error_t err = { 0 };
err.null = true;
FILE *fp = fopen (path, "w");
if (!fp)
{
err.null = false;
err.status = errno;
err.src = strerror (errno);
return err;
return 0;
}
else
@@ -31,15 +23,12 @@ touch (char *path, char *format, ...)
}
fclose (fp);
return err;
return 0;
}
error_t
int
dir (char *format, ...)
{
error_t err = { 0 };
err.null = true; // success by default
va_list args;
va_start (args, format);
@@ -50,28 +39,23 @@ dir (char *format, ...)
if (mkdir (path, 0777) < 0)
{
err.null = false;
err.status = errno;
err.src = strerror (errno);
return errno;
}
return err;
return 0;
}
error_t
int
take (const char *dirname)
{
error_t err = dir ("%s", dirname);
if (!err.null)
int err = dir ("%s", dirname);
if (err)
{
return err;
}
if (chdir (dirname) != 0)
{
err.null = false;
err.status = errno;
err.src = strerror (errno);
return err;
return errno;
}
return err;
return 0;
}

View File

@@ -1,12 +1,11 @@
#ifndef FILE_H
#define FILE_H
#include "e.h"
#include <unistd.h>
error_t take(const char *dirname);
int take(const char *dirname);
error_t touch(char *, char *, ...);
error_t dir(char *, ...);
int touch(char *, char *, ...);
int dir(char *, ...);
#endif

View File

@@ -5,13 +5,13 @@
#include <string.h>
int
parse_standard_options (void (*usage) (), int argc, char **argv)
parse_standard_options (void (*usage) (int), int argc, char **argv)
{
for (int i = 1; i < argc; ++i)
{
if (strcmp (argv[i], "--help") == 0)
{
usage ();
usage (0);
exit (0);
}
else if (strcmp (argv[i], "--version") == 0)