char *abspath(const char * const fnam, const int warn) { char *h; assert(fnam); if((h = dfnfullpath(fnam)) != 0) return h; if(warn) display_errno_fnam_error(fnam); return 0; }
int dir_print_body(char *arg, unsigned long *dircount) { int rv; unsigned long filecount, bytecount; char *pattern, *cachedPattern; char *p; /* Modified to pre-allocate path to 270 bytes so that we don't have to realloc() it later. That was causing "DIR /S" not to work properly. The path variable cannot be reallocated once dir_list() is called, because dir_list() is recursive. This will also help to reduce memory fragmentation. */ if((p = dfnfullpath(arg)) == NULL) { error_out_of_memory(); return E_NoMem; } if((path = realloc(p, 270*sizeof(char))) == NULL) { free(p); error_out_of_memory(); return E_NoMem; } filecount = bytecount = 0; /* print the header */ if((rv = dir_print_header(toupper(path[0]) - 'A')) == 0) { /* There are some directory specs that are not detected by dfnstat() as they are no part of the filesystem in DOS */ pattern = dfnfilename(path); assert(p); if(!*pattern || (dfnstat(path) & DFN_DIRECTORY) != 0) { pattern = strchr(pattern, '\0'); if(pattern[-1] != '\\') ++pattern; rv = dir_list(pattern - path, "*.*", dircount, &filecount , &bytecount ); } else { if((cachedPattern = strdup(pattern)) == NULL) { error_out_of_memory(); rv = E_NoMem; } else { rv = dir_list(pattern - path, cachedPattern, dircount , &filecount, &bytecount ); free(cachedPattern); } } } free(path); return rv || (optS? print_total(filecount, bytecount): 0); }
char *find_which(const char * const fname) { char *p; static char *buf = 0; if(0 == (p = dfnsearch(fname, 0, 0))) return 0; free(buf); buf = dfnfullpath(p); free(p); return buf; }