From d15bd48aba800576884e88bac76f077c73953639 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Thu, 19 Nov 2020 08:45:31 -0300 Subject: [PATCH] Fix relative path name bug --- main.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index a597324..1078600 100644 --- a/main.c +++ b/main.c @@ -5,11 +5,21 @@ #include #include #include +#include #include "parser.h" #include "translator.h" #include "bootstrap.h" #include "util.h" +#include +#ifndef PATH_MAX +#ifdef __linux__ +#include +#else +#define PATH_MAX 512 +#endif +#endif + typedef struct { char** files; char** fnames; @@ -91,7 +101,16 @@ bool isdir(char* f, int len) { char* getoutname(char* input, int len, bool isdir) { char* outname; if(isdir) { - char* name = getname(input, len); + char olddir[PATH_MAX]; + getcwd(olddir, PATH_MAX); + + chdir(input); + char buf[PATH_MAX]; + getcwd(buf, PATH_MAX); + + chdir(olddir); + + char* name = getname(buf, strlen(buf)); int sz = sizeof(char) * (strlen(name)+len+6); outname = (char*)malloc(sz); snprintf(outname, sz, "%s/%s.asm", input, name);