Fix relative path name bug
This commit is contained in:
parent
4e532a5cb9
commit
d15bd48aba
21
main.c
21
main.c
|
@ -5,11 +5,21 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "translator.h"
|
#include "translator.h"
|
||||||
#include "bootstrap.h"
|
#include "bootstrap.h"
|
||||||
#include "util.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 {
|
typedef struct {
|
||||||
char** files;
|
char** files;
|
||||||
char** fnames;
|
char** fnames;
|
||||||
|
@ -91,7 +101,16 @@ bool isdir(char* f, int len) {
|
||||||
char* getoutname(char* input, int len, bool isdir) {
|
char* getoutname(char* input, int len, bool isdir) {
|
||||||
char* outname;
|
char* outname;
|
||||||
if(isdir) {
|
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);
|
int sz = sizeof(char) * (strlen(name)+len+6);
|
||||||
outname = (char*)malloc(sz);
|
outname = (char*)malloc(sz);
|
||||||
snprintf(outname, sz, "%s/%s.asm", input, name);
|
snprintf(outname, sz, "%s/%s.asm", input, name);
|
||||||
|
|
Loading…
Reference in New Issue