aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make/utils.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2019-04-23 22:41:31 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2019-04-25 20:26:24 +0200
commitf09e36acfe2db50e0452ba1e19b13f4395a8d704 (patch)
tree98128638131359eee2b91308284b965719388748 /src/blogc-make/utils.c
parent4120e6adf557b01b8e43f8b5abe52c85602def64 (diff)
downloadblogc-f09e36acfe2db50e0452ba1e19b13f4395a8d704.tar.gz
blogc-f09e36acfe2db50e0452ba1e19b13f4395a8d704.tar.bz2
blogc-f09e36acfe2db50e0452ba1e19b13f4395a8d704.zip
make: do not follow symlinks when resolving blogcfile path
Diffstat (limited to 'src/blogc-make/utils.c')
-rw-r--r--src/blogc-make/utils.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/blogc-make/utils.c b/src/blogc-make/utils.c
index 0c984f6..91b7b53 100644
--- a/src/blogc-make/utils.c
+++ b/src/blogc-make/utils.c
@@ -6,10 +6,18 @@
* See the file LICENSE.
*/
+#include <errno.h>
+#include <limits.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include "../common/error.h"
#include "../common/utils.h"
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
char*
bm_generate_filename(const char *dir, const char *prefix, const char *fname,
@@ -59,3 +67,30 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname,
return bc_string_free(rv, false);
}
+
+
+char*
+bm_abspath(const char *path, bc_error_t **err)
+{
+ if (err == NULL || *err != NULL)
+ return NULL;
+
+ if (path[0] == '/') {
+ return bc_strdup(path);
+ }
+
+ char cwd[PATH_MAX];
+ if (NULL == getcwd(cwd, sizeof(cwd))) {
+ *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS,
+ "Failed to detect absolute path (%s): %s", path, strerror(errno));
+ return NULL;
+ }
+
+ if (cwd[0] != '/') {
+ *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS,
+ "Failed to get current working directory: %s", cwd);
+ return NULL;
+ }
+
+ return bc_strdup_printf("%s/%s", cwd, path);
+}