static void read_sonames() { char *line=NULL; size_t sz=0; FILE *ldc = popen("/sbin/ldconfig -p", "r"); while (!feof(ldc)) { ssize_t n = getline(&line, &sz, ldc); if (n == -1) break; if (n > 2 && isspace(line[0])) { int i=0; while (isspace(line[++i])) ; char *name = &line[i]; char *dot = strstr(name, ".so"); char *nxt = strchr(name, ' '); if (dot != NULL && nxt != NULL) { std::string pfx(name, dot - name); std::string soname(name, nxt - name); sonameMap[pfx] = soname; } } } free(line); pclose(ldc); }
extern "C" DLLEXPORT void jl_read_sonames(void) { char *line=NULL; size_t sz=0; FILE *ldc = popen("/sbin/ldconfig -p", "r"); while (!feof(ldc)) { ssize_t n = getline(&line, &sz, ldc); if (n == -1) break; if (n > 2 && isspace(line[0])) { int i=0; while (isspace(line[++i])) ; char *name = &line[i]; char *dot = strstr(name, ".so"); i=0; if (NULL == dot) continue; // Detect if this entry is for the current architecture while (!isspace(dot[++i])) ; while (isspace(dot[++i])) ; int j = i; while (!isspace(dot[++j])) ; char *arch = strstr(dot+i,"x86-64"); if (arch != NULL && arch < dot + j) { #ifdef _P32 continue; #endif } else { #ifdef _P64 continue; #endif } char *abslibpath = strrchr(line, ' '); if (dot != NULL && abslibpath != NULL) { std::string pfx(name, dot - name); // Do not include ' ' in front and '\n' at the end std::string soname(abslibpath+1, line+n-(abslibpath+1)-1); sonameMap[pfx] = soname; } } } free(line); pclose(ldc); }