maintain compatibility with olde linuxen.

This commit is contained in:
Vitor Santos Costa
2018-09-29 14:43:27 -05:00
parent 87c6971bb6
commit f57377a23a
14 changed files with 57 additions and 54 deletions

26
os/streams.c Normal file → Executable file
View File

@@ -315,35 +315,35 @@ bool Yap_SetCurInpPos(
return true;
}
char *Yap_guessFileName(FILE *file, int sno, size_t max) {
size_t maxs = Yap_Max(1023, max-1);
int i = push_text_stack();
char *nameb = Malloc(maxs + 1);
char *Yap_guessFileName(FILE *file, int sno) {
size_t maxs = YAP_FILENAME_MAX-1;
char *nameb = malloc(maxs + 1);
if (!file) {
strncpy(nameb, "memory buffer", maxs);
return pop_output_text_stack(i,nameb);
return nameb;
}
int f = fileno(file);
if (f < 0) {
strcpy(nameb, "???");
return pop_output_text_stack(i,nameb);
return nameb;
}
#if __linux__
char *path = Malloc(1024);
char *path = malloc(1024);
if (snprintf(path, 1023, "/proc/self/fd/%d", f) &&
readlink(path, nameb, maxs)) {
return pop_output_text_stack(i,nameb);
free(path);
return nameb;
}
#elif __APPLE__
if (fcntl(f, F_GETPATH, nameb) != -1) {
return pop_output_text_stack(i,nameb);
return nameb;
}
#else
TCHAR *path = Malloc(MAX_PATH + 1);
TCHAR *path = malloc(MAX_PATH + 1);
if (!GetFullPathName(path, MAX_PATH, path, NULL)) {
pop_text_stack(i);
return NULL;
} else {
int i;
@@ -351,14 +351,12 @@ char *Yap_guessFileName(FILE *file, int sno, size_t max) {
for (i = 0; i < strlen(path); i++)
ptr += put_utf8(ptr, path[i]);
*ptr = '\0';
return pop_output_text_stack(i,nameb);
return nameb;
}
#endif
if (!StreamName(sno)) {
pop_text_stack(i);
return NULL;
}
pop_text_stack(i);
return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE;
}