From 4ba7eda791e0eed0b56b508cac34be8e1f27600d Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sat, 20 Oct 2018 09:50:28 +1000 Subject: [PATCH] Add fopen_bbs_path function --- src/bbs.h | 1 + src/util.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/bbs.h b/src/bbs.h index 1e51fab..57a42e6 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -280,6 +280,7 @@ extern void ptr_vector_apply(struct ptr_vector *vec, void (*f)(void *arg)); extern void **ptr_vector_ptrs(struct ptr_vector *vec); extern void **consume_ptr_vector(struct ptr_vector *vec); extern void destroy_ptr_vector(struct ptr_vector *vec); +extern FILE *fopen_bbs_path(const char *filename, const char *mode); extern char *str_replace(const char *orig, const char *rep, const char *with); extern int copy_file(char *src, char *dest); diff --git a/src/util.c b/src/util.c index d2d348f..b93756a 100644 --- a/src/util.c +++ b/src/util.c @@ -7,9 +7,12 @@ #include #include #include +#include #include "bbs.h" +extern struct bbs_config conf; + void die(const char *msg) { dolog(msg); exit(-1); @@ -231,3 +234,12 @@ void destroy_ptr_vector(struct ptr_vector *vec) { vec->capacity = 0; vec->len = 0; } + +FILE *fopen_bbs_path(const char *filename, const char *mode) { + char buffer[PATH_MAX]; + + snprintf(buffer, PATH_MAX, "%s/%s", conf.bbs_path, filename); + + return fopen(buffer, mode); + +}