14 #define dln_warning rb_warning 15 #define dln_warning_arg 17 #define dln_warning fprintf 18 #define dln_warning_arg stderr, 30 #if defined(HAVE_ALLOCA_H) 44 #include <sys/types.h> 48 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 55 #if !defined(_WIN32) && !HAVE_DECL_GETENV 59 static char *dln_find_1(
const char *fname,
const char *path,
char *
buf,
size_t size,
int exe_flag
70 if (path) path = envpath =
strdup(path);
82 if (envpath)
free(envpath);
90 if (!path) path =
".";
95 dln_find_1(
const char *fname,
const char *path,
char *fbuf,
size_t size,
99 register const char *
dp;
100 register const char *ep;
103 size_t i, fnlen, fspace;
105 static const char extension[][5] = {
109 int is_abs = 0, has_path = 0;
112 const char *p = fname;
114 static const char pathname_too_long[] =
"openpath: pathname too long (ignored)\n\ 115 \tDirectory \"%.*s\"%s\n\tFile \"%.*s\"%s\n";
116 #define PATHNAME_TOO_LONG() dln_warning(dln_warning_arg pathname_too_long, \ 117 ((bp - fbuf) > 100 ? 100 : (int)(bp - fbuf)), fbuf, \ 118 ((bp - fbuf) > 100 ? "..." : ""), \ 119 (fnlen > 100 ? 100 : (int)fnlen), fname, \ 120 (fnlen > 100 ? "..." : "")) 122 #define RETURN_IF(expr) if (expr) return (char *)fname; 128 "openpath: pathname too long (ignored)\n\tFile \"%.*s\"%s\n",
129 (fnlen > 100 ? 100 : (
int)fnlen), fname,
130 (fnlen > 100 ?
"..." :
""));
135 # define CharNext(p) ((p)+1) 137 # ifdef DOSISH_DRIVE_LETTER 138 if (((p[0] | 0x20) -
'a') < 26 && p[1] ==
':') {
165 for (j = 0;
STRCASECMP(ext, extension[j]); ) {
166 if (++j ==
sizeof(extension) /
sizeof(extension[0])) {
179 if (i + 1 >
size)
goto toolong;
180 fspace =
size - i - 1;
183 memcpy(fbuf, fname, i + 1);
184 goto needs_extension;
189 if (*p ==
'.' && *++p ==
'.') ++p;
195 for (dp = path;; dp = ++ep) {
216 if (*dp ==
'~' && (l == 1 ||
256 memcpy(bp, fname, i + 1);
259 if (exe_flag && !ext) {
261 for (j = 0; j <
sizeof(extension) /
sizeof(extension[0]); j++) {
262 if (fspace <
strlen(extension[j])) {
266 strlcpy(bp + i, extension[j], fspace);
267 if (
stat(fbuf, &st) == 0)
275 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 278 if (exe_flag == 0)
return fbuf;
#define PATHNAME_TOO_LONG()
size_t strlen(const char *)
int eaccess(const char *path, int mode)
char * dln_find_exe_r(const char *fname, const char *path, char *buf, size_t size DLN_FIND_EXTRA_ARG_DECL)
#define DLN_FIND_EXTRA_ARG
char * dln_find_file_r(const char *fname, const char *path, char *buf, size_t size DLN_FIND_EXTRA_ARG_DECL)
#define DLN_FIND_EXTRA_ARG_DECL
unsigned char buf[MIME_BUF_SIZE]
char * strchr(char *, char)
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
#define STRCASECMP(s1, s2)