version 1.60, 2005/11/11 18:51:49 |
version 1.61, 2005/11/13 07:49:02 |
|
|
{ |
{ |
static char file[NFILEN]; |
static char file[NFILEN]; |
char *home; |
char *home; |
|
int ret; |
|
|
if ((home = getenv("HOME")) == NULL || *home == '\0') |
if ((home = getenv("HOME")) == NULL || *home == '\0') |
goto nohome; |
goto nohome; |
|
|
if (suffix == NULL) { |
if (suffix == NULL) { |
if (snprintf(file, sizeof(file), "%s/.mg", home) |
ret = snprintf(file, sizeof(file), "%s/.mg", home); |
>= sizeof(file)) |
if (ret < 0 || ret >= sizeof(file)) |
return (NULL); |
return (NULL); |
} else { |
} else { |
if (snprintf(file, sizeof(file), "%s/.mg-%s", home, suffix) |
ret = snprintf(file, sizeof(file), "%s/.mg-%s", home, suffix); |
>= sizeof(file)) |
if (ret < 0 || ret >= sizeof(file)) |
return (NULL); |
return (NULL); |
} |
} |
|
|
|
|
nohome: |
nohome: |
#ifdef STARTUPFILE |
#ifdef STARTUPFILE |
if (suffix == NULL) { |
if (suffix == NULL) { |
if (snprintf(file, sizeof(file), "%s", STARTUPFILE) |
ret = snprintf(file, sizeof(file), "%s", STARTUPFILE); |
>= sizeof(file)) |
if (ret < 0 || ret >= sizeof(file)) |
return (NULL); |
return (NULL); |
} else { |
} else { |
if (snprintf(file, sizeof(file), "%s%s", STARTUPFILE, suffix) |
ret = snprintf(file, sizeof(file), "%s%s", STARTUPFILE, |
>= sizeof(file)) |
suffix); |
|
if (ret < 0 || ret >= sizeof(file)) |
return (NULL); |
return (NULL); |
} |
} |
|
|
if (access(file, R_OK) == 0) |
if (access(file, R_OK) == 0) |
return (file); |
return (file); |
#endif |
#endif /* STARTUPFILE */ |
return (NULL); |
return (NULL); |
} |
} |
#endif |
#endif /* !NO_STARTUP */ |
|
|
#ifndef NO_DIRED |
#ifndef NO_DIRED |
|
|
|
|
make_file_list(char *buf) |
make_file_list(char *buf) |
{ |
{ |
char *dir, *file, *cp; |
char *dir, *file, *cp; |
int len, preflen; |
int len, preflen, ret; |
DIR *dirp; |
DIR *dirp; |
struct dirent *dent; |
struct dirent *dent; |
LIST *last; |
LIST *last; |
|
|
char statname[NFILEN + 2]; |
char statname[NFILEN + 2]; |
|
|
statbuf.st_mode = 0; |
statbuf.st_mode = 0; |
if (snprintf(statname, sizeof(statname), "%s/%s", |
ret = snprintf(statname, sizeof(statname), "%s/%s", |
dir, dent->d_name) > sizeof(statname) - 1) { |
dir, dent->d_name); |
|
if (ret < 0 || ret > sizeof(statname) - 1) |
continue; |
continue; |
} |
|
if (stat(statname, &statbuf) < 0) |
if (stat(statname, &statbuf) < 0) |
continue; |
continue; |
if (statbuf.st_mode & S_IFDIR) |
if (statbuf.st_mode & S_IFDIR) |
|
|
if (current == NULL) |
if (current == NULL) |
break; |
break; |
|
|
if (snprintf(current->fl_name, sizeof(current->fl_name), |
ret = snprintf(current->fl_name, sizeof(current->fl_name), |
"%s%s%s", prefixx, dent->d_name, isdir ? "/" : "") |
"%s%s%s", prefixx, dent->d_name, isdir ? "/" : ""); |
>= sizeof(current->fl_name)) { |
if (ret < 0 || ret >= sizeof(current->fl_name)) { |
free(current); |
free(current); |
continue; |
continue; |
} |
} |