diff --git a/Makefile b/Makefile index dab2df8..993372a 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,16 @@ # .PHONY: all -all: bin endpoint +all: bin libremail endpoint .PHONY: bin bin: mkdir -p $@ +.PHONY: libremail +libremail: + cd libremail/; make + .PHONY: endpoint endpoint: cd endpoint/; make diff --git a/endpoint/Makefile b/endpoint/Makefile index 3803d4a..a759f7a 100644 --- a/endpoint/Makefile +++ b/endpoint/Makefile @@ -5,6 +5,7 @@ CFILES = $(shell find . -name "*.c") OFILES = $(CFILES:.c=.o) +OFILES += $(shell find ../libremail/ -name "*.o") DFILES = $(CFILES:.c=.d) CC = gcc diff --git a/libremail/Makefile b/libremail/Makefile new file mode 100644 index 0000000..ffffd2d --- /dev/null +++ b/libremail/Makefile @@ -0,0 +1,25 @@ +# Copyright (c) 2026, Chloe Moffett +# Provided under the BSD-3 clause +# + +CFILES = $(shell find . -name "*.c") +OFILES = $(CFILES:.c=.o) +DFILES = $(CFILES:.c=.d) +CC = gcc + +CFLAGS = \ + -Wall \ + -pedantic \ + -MMD \ + -Iinc + +.PHONY: all +all: $(OFILES) + +-include $(DFILES) +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ + +.PHONY: clean +clean: + rm -f $(OFILES) $(DFILES) diff --git a/libremail/common/.keep b/libremail/common/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/libremail/common/file_mkdir.c b/libremail/common/file_mkdir.c new file mode 100644 index 0000000..8bc4e0e --- /dev/null +++ b/libremail/common/file_mkdir.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2026, Chloe Moffett + * Provided under the BSD-3 clause + */ + +#include +#include +#include +#include "libremail/file.h" + +int +try_mkdir(const char *path, mode_t mode) +{ + if (path == NULL) { + errno = EINVAL; + return -1; + } + + if (access(path, F_OK) != 0) { + return mkdir(path, mode); + } + + return 0; +} diff --git a/libremail/inc/libremail/.keep b/libremail/inc/libremail/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/libremail/inc/libremail/file.h b/libremail/inc/libremail/file.h new file mode 100644 index 0000000..5e1c341 --- /dev/null +++ b/libremail/inc/libremail/file.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2026, Chloe Moffett + * Provided under the BSD-3 clause + */ + +#ifndef LIBREMAIL_FILE_H +#define LIBREMAIL_FILE_H 1 + +#include + +/* + * Attempt to create a directory if it doesn't exist + * + * @path: Path to directory to create + * @mode: Desired mode to assign + * + * Returns zeo on success + */ +int try_mkdir(const char *path, mode_t mode); + +#endif /* !LIBREMAIL_FILE_H */