int filename_cmp_impl(VALUE source, char *file) { char *source_ptr, *file_ptr; long s_len, f_len, min_len; long s, f; int dirsep_flag = 0; s_len = RSTRING_LEN(source); f_len = strlen(file); min_len = s_len < f_len ? s_len : f_len; source_ptr = RSTRING_PTR(source); file_ptr = file; for (s = s_len - 1, f = f_len - 1; s >= s_len - min_len && f >= f_len - min_len; s--, f--) { if ((source_ptr[s] == '.' || file_ptr[f] == '.') && dirsep_flag) return 1; if (isdirsep(source_ptr[s]) && isdirsep(file_ptr[f])) dirsep_flag = 1; #ifdef DOSISH_DRIVE_LETTER else if (s == 0) return (toupper(source_ptr[s]) == toupper(file_ptr[f])); #endif else if (source_ptr[s] != file_ptr[f]) return 0; } return 1; }
static char * strrdirsep(const char *path) { char *last = NULL; while (*path) { if (isdirsep(*path)) { const char *tmp = path++; while (isdirsep(*path)) path++; if (!*path) break; last = (char *)tmp; } else { path = CharNext(path); } } return last; }
static void makelibpath(const char *path, const char *libpath, char *finalpath, int finalpath_length) { int l; int p_l = 0; for(l = 0; path[l]; l++) { if(isdirsep(path[l])) { p_l = l + 1; } } while(isdirsep(*libpath)) libpath++; if(!finalpath_length) return; *finalpath = 0; if(p_l > (finalpath_length - 1)) p_l = (finalpath_length - 1); if(p_l) { memcpy(finalpath, path, p_l); finalpath[p_l] = 0; finalpath += p_l; finalpath_length -= p_l; } if(!finalpath_length) return; strncpy(finalpath, libpath, finalpath_length); finalpath[finalpath_length - 1] = 0; }
int psf2fs_virtual_readfile(void *psf2fs, const char *path, int offset, char *buffer, int length) { struct PSF2FS *fs = (struct PSF2FS*)psf2fs; struct DIR_ENTRY *entry = fs->dir; if(!path) goto invalidarg; if(offset < 0) goto invalidarg; if(!buffer) goto invalidarg; if(length < 0) goto invalidarg; for(;;) { int l; int need_dir; if(!entry) goto pathnotfound; while(isdirsep(*path)) path++; for(l = 0;; l++) { if(!path[l]) { need_dir = 0; break; } if(isdirsep(path[l])) { need_dir = 1; break; } } entry = finddirentry(entry, path, l); if(!entry) goto pathnotfound; if(!need_dir) break; entry = entry->subdir; path += l; } // if we "found" a file but it's a directory, then we didn't find it if(entry->subdir) goto pathnotfound; // special case: if requested length is 0, return the total file length if(!length) return entry->length; // otherwise, read from source return virtual_read(fs, entry, offset, buffer, length); pathnotfound: goto error; invalidarg: goto error; error: return -1; }
/* If fname isn't absolute, add cwd to it. */ char * cdio_abspath(const char *cwd, const char *fname) { if (isdirsep(*fname)) return strdup(fname); size_t len = strlen(cwd) + strlen(fname) + 2; char* result = calloc(sizeof(char), len); snprintf(result, len, "%s%c%s", cwd, CDIO_FILE_SEPARATOR, fname); return result; }
static size_t init_funcname_len(const char **file) { const char *p = *file, *base, *dot = NULL; /* Load the file as an object one */ for (base = p; *p; p++) { /* Find position of last '/' */ if (*p == '.' && !dot) dot = p; if (isdirsep(*p)) base = p+1, dot = NULL; } *file = base; /* Delete suffix if it exists */ return (dot ? dot : p) - base; }
static void path_next(arc *c, value str, int *index) { while (!isdirsep(arc_strindex(c, str, *index))) (*index)++; }