Fix relative path name bug

This commit is contained in:
Augusto Gunsch 2020-11-19 08:45:31 -03:00
parent 4e532a5cb9
commit d15bd48aba
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
1 changed files with 20 additions and 1 deletions

21
main.c
View File

@ -5,11 +5,21 @@
#include <sys/types.h>
#include <dirent.h>
#include <stdbool.h>
#include <unistd.h>
#include "parser.h"
#include "translator.h"
#include "bootstrap.h"
#include "util.h"
#include <limits.h>
#ifndef PATH_MAX
#ifdef __linux__
#include <linux/limits.h>
#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);