ifix
This commit is contained in:
36
os/streams.c
36
os/streams.c
@@ -315,30 +315,34 @@ bool Yap_SetCurInpPos(
|
||||
return true;
|
||||
}
|
||||
|
||||
char *Yap_guessFileName(FILE *file, int sno, size_t max) {
|
||||
Atom 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);
|
||||
if (!file) {
|
||||
strncpy(nameb, "memory buffer", maxs);
|
||||
|
||||
return pop_output_text_stack(i,nameb);
|
||||
Atom at = Yap_LookupAtom("mem");
|
||||
return at;
|
||||
}
|
||||
int f = fileno(file);
|
||||
if (f < 0) {
|
||||
strcpy(nameb, "???");
|
||||
return pop_output_text_stack(i,nameb);
|
||||
Atom at = Yap_LookupAtom("fmem");
|
||||
return at;
|
||||
}
|
||||
|
||||
int i = push_text_stack();
|
||||
#if __linux__
|
||||
char *path = Malloc(1024);
|
||||
if (snprintf(path, 1023, "/proc/self/fd/%d", f) &&
|
||||
readlink(path, nameb, maxs)) {
|
||||
return pop_output_text_stack(i,nameb);
|
||||
char *path = Malloc(1024), *nameb = Malloc(maxs+1);
|
||||
size_t len;
|
||||
if ((len = snprintf(path, 1023, "/proc/self/fd/%d", f)) >= 0 &&
|
||||
(len = readlink(path, nameb, maxs)) > 0) {
|
||||
nameb[len] = '\0';
|
||||
Atom at = Yap_LookupAtom(nameb);
|
||||
pop_text_stack(i);
|
||||
return at;
|
||||
}
|
||||
#elif __APPLE__
|
||||
if (fcntl(f, F_GETPATH, nameb) != -1) {
|
||||
return pop_output_text_stack(i,nameb);
|
||||
Atom at = Yap_LookupAtom(nameb);
|
||||
pop_text_stack(i);
|
||||
return at;
|
||||
}
|
||||
#else
|
||||
TCHAR *path = Malloc(MAX_PATH + 1);
|
||||
@@ -351,7 +355,9 @@ 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);
|
||||
Atom at = Yap_LookupAtom(nameb);
|
||||
pop_text_stack(i);
|
||||
return at;
|
||||
}
|
||||
#endif
|
||||
if (!StreamName(sno)) {
|
||||
@@ -359,7 +365,7 @@ char *Yap_guessFileName(FILE *file, int sno, size_t max) {
|
||||
return NULL;
|
||||
}
|
||||
pop_text_stack(i);
|
||||
return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE;
|
||||
return AtomOfTerm(StreamName(sno));
|
||||
}
|
||||
|
||||
static Int representation_error(int sno, Term t2 USES_REGS) {
|
||||
|
Reference in New Issue
Block a user