21this code is no being maintained anymore
49 (0==stat(n,&stbuf)&&(stbuf.st_mode&S_IFMT)==S_IFREG&&0==access(n,X_OK))
51 (0==stat(n,&stbuf)&&(stbuf.st_mode&S_IFMT)==S_IFDIR&&0==access(n,W_OK))
58Yap_FindExecutable(
void)
60 register char *cp, *cp2;
64 cp = (
char *)getenv(
"PATH");
66 cp =
".:/usr/ucb:/bin:/usr/bin:/usr/local/bin";
67 if (*GLOBAL_argv[0] ==
'/') {
68 if (oktox(GLOBAL_argv[0])) {
69 strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
70 Yap_AbsoluteFileInBuffer(LOCAL_FileNameBuf,
true);
71 strncpy( GLOBAL_Executable, LOCAL_FileNameBuf, PATH_MAX);
83 for (cp2 = LOCAL_FileNameBuf; (*cp) != 0 && (*cp) !=
':';)
86 strcpy(cp2, GLOBAL_argv[0]);
89 if (!oktox(LOCAL_FileNameBuf))
91 Yap_AbsoluteFileInBuffer(Yap_AbsoluteFileInBuffer(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
95 strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
96 Yap_AbsoluteFileInBuffer(Yap_AbsoluteFileInBuffer(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
97 if (oktox(GLOBAL_Executable))
98 return GLOBAL_Executable;
100 Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
101 "cannot find file being executed");
105Yap_LoadForeignFile(
char *file,
int flags)
112Yap_CallForeignFile(
void *handle,
char *f)
118Yap_CloseForeignFile(
void *handle)
132 YapInitProc *init_proc)
134 char command[2*PATH_MAX];
139 char tmp_buff[32] =
"/tmp/YAP_TMP_XXXXXX";
144 unsigned long loadImageSize, firstloadImSz;
158 strcat(o_files,AtomName(tmp->name));
169 strcat(l_files,AtomName(tmp->name));
174 tfile = mktemp(tmp_buff);
177 if (strlen(o_files) + strlen(l_files) + strlen(proc_name) +
178 strlen(GLOBAL_Executable) > 2*PATH_MAX) {
179 strcpy(LOCAL_ErrorSay,
" too many parameters in load_foreign/3 ");
182 sprintf(command,
"/usr/bin/ld -N -A %s -o %s -u _%s %s %s -lc",
184 tfile, proc_name, o_files, l_files);
186 if (system(command) != 0) {
188 strcpy(LOCAL_ErrorSay,
" ld returned error status in load_foreign_files ");
192 if ((fildes = open(tfile, O_RDONLY)) < 0) {
193 strcpy(LOCAL_ErrorSay,
" unable to open temp file in load_foreign_files ");
198 read(fildes, (
char *) &header,
sizeof(header));
201 loadImageSize = header.a_text + header.a_data + header.a_bss;
205 firstloadImSz = loadImageSize;
207 if (!(FCodeBase = Yap_AllocCodeSpace((
int) loadImageSize))) {
208 strcpy(LOCAL_ErrorSay,
" unable to allocate space for external code ");
212 sprintf(command,
"/usr/bin/ld -N -A %s -T %lx -o %s -u _%s %s %s -lc",
214 (
unsigned long) FCodeBase,
215 tfile, proc_name, o_files, l_files);
217 if (system(command) != 0) {
219 strcpy(LOCAL_ErrorSay,
" ld returned error status in load_foreign_files ");
222 if ((fildes = open(tfile, O_RDONLY)) < 0) {
223 strcpy(LOCAL_ErrorSay,
" unable to open temp file in load_foreign_files ");
226 read(fildes, (
char *) &header,
sizeof(header));
227 loadImageSize = header.a_text + header.a_data + header.a_bss;
228 if (firstloadImSz < loadImageSize) {
229 strcpy(LOCAL_ErrorSay,
" miscalculation in load_foreign/3 ");
235 struct nlist func_info[2];
236 sprintf(entry_fun,
"_%s", proc_name);
237 func_info[0].n_un.n_name = entry_fun;
238 func_info[1].n_un.n_name = NULL;
239 if (nlist(tfile, func_info) == -1) {
240 strcpy(LOCAL_ErrorSay,
" in nlist(3) ");
243 if (func_info[0].n_type == 0) {
244 strcpy(LOCAL_ErrorSay,
" in nlist(3) ");
247 *init_proc = (YapInitProc)(func_info[0].n_value);
251 lseek(fildes, (
long)(N_TXTOFF(header)), 0);
253 unsigned int u1 = header.a_text + header.a_data;
254 read(fildes, (
char *) FCodeBase, u1);
256 while (u1 < loadImageSize)
261 return LOAD_SUCCEEDED;
266 char *proc_name, YapInitProc *init_proc)
268 return LoadForeign(ofiles, libs, proc_name, init_proc);
272Yap_ShutdownLoadForeign(
void)
278 char *proc_name, YapInitProc *init_proc)
280 return(LoadForeign(ofiles,libs, proc_name, init_proc));
load_foreign_files/3 has works for the following configurations: