}
/* if no argument, choose all files */
- if (fptr == NULL || fptr[0] == 0) fptr = "*";
+ if (fptr == NULL || fptr[0] == 0) {
+ fptr = "*";
+ } else {
+ /* we need to check if the last part is a directory (no -d switch) */
+ struct stat buf;
+ if (stat(fptr, &buf) == 0 && S_ISDIR(buf.st_mode)) {
+ TRAP_ERROR(chdir(fptr) == -1, 550, return -1);
+ fptr = "*";
+ }
+ }
*ptr = fptr;
#if WANT_NONROOT