Check Access Permissions (continued.) /* scan all directories in the path and check each of them. */ p_slash = file_path; while ( (p_slash = strchr(p_slash, '/')) != NULL) { /* copy directory path (including trailing slash) */ /* into dir_path. */ strncpy(dir_path, file_path, p_slash-file_path+1); dir_path[p_slash-file_path+1] = '\0'; /* check existance and X permission for this directory. */ if (access(dir_path, F_OK) == -1) { sprintf(err_msg, "Directory '%s' in the path does not exist.", dir_path); return 0; } if (access(dir_path, X_OK) == -1) { sprintf(err_msg, "Directory '%s' in the path - no 'X' permission.", dir_path); return 0; } /* skip the current slash, so the next strchr() call will */ /* find the next slash in the file path. */ p_slash++; }