/* winlnk: debug.o display.o function.o -lpdcurses -lregex */
#include <curses.h>
+#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
current = list[panel]->tab + windir[panel]->index;
if ((current->type == type_dir_e) || (current->type == type_ldir_e)) {
char *_dirname = newfilename (dirname[panel], current->name);
- free (dirname[panel]);
- dirname[panel] = _dirname;
- index_x[panel] = 0;
- index_y[panel] = 0;
- freelist (list[panel]);
- list[panel] = NULL;
- page[panel] = 0;
+ DIR *dir = opendir (_dirname);
+ if (dir == NULL) {
+ char *msg = strdupcat ("Can't open directory '", _dirname, "'", NULL);
+ errorwindow (msg, winscreen);
+ free (msg);
+ free (_dirname);
+ } else {
+ closedir (dir);
+ free (dirname[panel]);
+ dirname[panel] = _dirname;
+ index_x[panel] = 0;
+ index_y[panel] = 0;
+ freelist (list[panel]);
+ list[panel] = NULL;
+ page[panel] = 0;
+ }
}
break;
case '\t':
list_t *_addelement (list_t *list, char *dirname, char *filename, type_t type)
{
char *name = newfilename (dirname, filename);
- struct stat sb;
- if (STAT (name, &sb) == -1) {
- VERBOSE (ERROR, fprintf (stderr, "can't stat file '%s'\n", name));
- exit (1);
- }
+ struct stat sb = {0};
+ int error = (STAT (name, &sb) == -1);
size_t size = 0;
if (type == type_reg_e) {
{
char *name = newfilename (dirname, elem->name);
- struct stat sb;
- if (STAT (name, &sb) == -1) {
- VERBOSE (ERROR, fprintf (stderr, "can't stat file '%s%s%s'\n", dirname, SEPARATOR, elem->name));
- exit (1);
- }
+ struct stat sb = {0};
+ int error = (STAT (name, &sb) == -1);
free (name);
#ifdef WIN32
elem->uid = strdup ("");
#else /* Linux*/
- struct passwd *pwd = getpwuid (sb.st_uid);
- if (pwd) {
- elem->uid = strdup (pwd->pw_name);
+ if (!error) {
+ struct passwd *pwd = getpwuid (sb.st_uid);
+ if (pwd) {
+ elem->uid = strdup (pwd->pw_name);
+ } else {
+ elem->uid = (char *) calloc (_log10 (sb.st_uid) + 1, 1);
+ sprintf (elem->uid, "%d", sb.st_uid);
+ }
} else {
- elem->uid = (char *) calloc (_log10 (sb.st_uid) + 1, 1);
- sprintf (elem->uid, "%d", sb.st_uid);
+ elem->uid = strdup ("");
}
#endif
#ifdef WIN32
elem->gid = strdup ("");
#else /* Linux*/
- struct group *grp = getgrgid (sb.st_gid);
- if (grp) {
- elem->gid = strdup (grp->gr_name);
+ if (!error) {
+ struct group *grp = getgrgid (sb.st_gid);
+ if (grp) {
+ elem->gid = strdup (grp->gr_name);
+ } else {
+ elem->gid = (char *) calloc (_log10 (sb.st_gid) + 1, 1);
+ sprintf (elem->gid, "%d", sb.st_gid);
+ }
} else {
- elem->gid = (char *) calloc (_log10 (sb.st_gid) + 1, 1);
- sprintf (elem->gid, "%d", sb.st_gid);
+ elem->gid = strdup ("");
}
#endif