#define SP_NORMAL 0x80 /* spawn child process in non-curses regular mode */
typedef unsigned long ulong;
+typedef unsigned int uint;
typedef unsigned char uchar;
/* Directory entry */
static char *editor;
static char *desktop_manager;
static off_t blk_size;
+static off_t dir_size;
static size_t fs_free;
-static unsigned int open_max;
+static uint open_max;
static bm bookmark[MAX_BM];
static const double div_2_pow_10 = 1.0 / 1024.0;
getmime(char *file)
{
regex_t regex;
- unsigned int i;
- static unsigned int len = LEN(assocs);
+ uint i;
+ static uint len = LEN(assocs);
for (i = 0; i < len; ++i) {
if (regcomp(®ex, assocs[i].regex,
static int
nextsel(char **run, char **env, int *presel)
{
- int c = *presel;
- unsigned int i;
- static unsigned int len = LEN(bindings);
+ static int c;
+ static uchar i;
+ static uint len = LEN(bindings);
+
+ c = *presel;
if (c == 0)
c = getch();
n = 0;
+ if (cfg.bsizeorder)
+ dir_size = 0;
+
dirp = opendir(path);
if (dirp == NULL)
return 0;
(dp->d_name[1] == '.' && dp->d_name[2] == '\0'))))
continue;
- if (filter(re, dp->d_name) == 0)
+ mkpath(path, dp->d_name, newpath, PATH_MAX);
+ if (lstat(newpath, &sb) == -1) {
+ continue;
+ /* if (*dents)
+ free(*dents);
+ printerr(1, "lstat"); */
+ }
+
+ if (filter(re, dp->d_name) == 0) {
+ if (!cfg.bsizeorder)
+ continue;
+
+ if (S_ISDIR(sb.st_mode)) {
+ blk_size = 0;
+ if (nftw(newpath, sum_bsizes, open_max,
+ FTW_MOUNT | FTW_PHYS) == -1) {
+ printmsg("nftw(3) failed");
+ dir_size += sb.st_blocks;
+ } else
+ dir_size += blk_size;
+ } else
+ dir_size += sb.st_blocks;
+
continue;
+ }
if (n == total_dents) {
total_dents += 64;
}
xstrlcpy((*dents)[n].name, dp->d_name, NAME_MAX);
- /* Get mode flags */
- mkpath(path, dp->d_name, newpath, PATH_MAX);
- if (lstat(newpath, &sb) == -1) {
- if (*dents)
- free(*dents);
- printerr(1, "lstat");
- }
+
(*dents)[n].mode = sb.st_mode;
(*dents)[n].t = sb.st_mtime;
(*dents)[n].size = sb.st_size;
(*dents)[n].bsize = blk_size;
} else
(*dents)[n].bsize = sb.st_blocks;
+
+ dir_size += (*dents)[n].bsize;
}
++n;
static void
redraw(char *path)
{
- static char cwd[PATH_MAX];
static int nlines, i;
static size_t ncols;
DPRINTF_S(path);
/* No text wrapping in cwd line */
- if (!realpath(path, cwd)) {
+ if (!realpath(path, g_buf)) {
printmsg("Cannot resolve path");
return;
}
ncols = COLS;
if (ncols > PATH_MAX)
ncols = PATH_MAX;
- cwd[ncols - strlen(CWD) - 1] = '\0';
- printw(CWD "%s\n\n", cwd);
+ g_buf[ncols - strlen(CWD) - 1] = '\0';
+ printw(CWD "%s\n\n", g_buf);
/* Print listing */
if (cur < (nlines >> 1)) {
ind[0] = '\0';
if (!cfg.bsizeorder)
- sprintf(cwd, "total %d %s[%s%s]", ndents, sort,
+ sprintf(g_buf, "total %d %s[%s%s]", ndents, sort,
replace_escape(dents[cur].name), ind);
- else
- sprintf(cwd,
- "total %d by disk usage, %s free [%s%s]",
- ndents, coolsize(fs_free),
+ else {
+ i = sprintf(g_buf, "du: %s in dir, ",
+ coolsize(dir_size << 9));
+ sprintf(g_buf + i, "%s free [%s%s]", coolsize(fs_free),
replace_escape(dents[cur].name), ind);
+ }
- printmsg(cwd);
+ printmsg(g_buf);
} else
printmsg("0 items");
}