#include <errno.h>
#include <fcntl.h>
#include <grp.h>
+#include <libgen.h>
#include <limits.h>
#ifdef __gnu_hurd__
#define PATH_MAX 4096
static void printmsg(char *);
static void printwarn(void);
static void printerr(int, char *);
-static int dentfind(struct entry *dents, int n, char *path);
static void redraw(char *path);
static rlim_t
p = (unsigned char *)s + n - 1;
- while(n--)
+ while (n--)
if ((*p--) == ch)
return ++p;
c1++;
if (*c1 == '-' || *c1 == '+')
c1++;
- while(*c1 >= '0' && *c1 <= '9')
+ while (*c1 >= '0' && *c1 <= '9')
c1++;
c2 = s2;
*env = bindings[i].env;
return bindings[i].act;
}
+
return 0;
}
static const char *size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
static char size_buf[12]; /* Buffer to hold human readable size */
static int i;
- static off_t fsize, tmp;
+ static off_t tmp;
static long double rem;
i = 0;
- fsize = size;
rem = 0;
- while (fsize > 1024) {
- tmp = fsize;
- //fsize *= div_2_pow_10;
- fsize >>= 10;
- rem = tmp - (fsize << 10);
+ while (size > 1024) {
+ tmp = size;
+ size >>= 10;
+ rem = tmp - (size << 10);
i++;
}
- snprintf(size_buf, 12, "%.*Lf%s", i, fsize + rem * div_2_pow_10, size_units[i]);
+ snprintf(size_buf, 12, "%.*Lf%s", i, size + rem * div_2_pow_10, size_units[i]);
return size_buf;
}
static int
sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
- if(typeflag == FTW_F || typeflag == FTW_D)
+ if (typeflag == FTW_F || typeflag == FTW_D)
blk_size += sb->st_blocks;
return 0;
static DIR *dirp;
static struct dirent *dp;
static struct stat sb;
- static struct statvfs svb;
- static int r, n;
- r = n = 0;
+ static int n;
+ n = 0;
dirp = opendir(path);
if (dirp == NULL)
xstrlcpy((*dents)[n].name, dp->d_name, NAME_MAX);
/* Get mode flags */
mkpath(path, dp->d_name, newpath, PATH_MAX);
- r = lstat(newpath, &sb);
- if (r == -1) {
+ if (lstat(newpath, &sb) == -1) {
if (*dents)
free(*dents);
printerr(1, "lstat");
}
if (bsizeorder) {
- r = statvfs(path, &svb);
- if (r == -1)
+ static struct statvfs svb;
+ if (statvfs(path, &svb) == -1)
fs_free = 0;
else
fs_free = svb.f_bavail << getorder(svb.f_bsize);
}
/* Should never be null */
- r = closedir(dirp);
- if (r == -1) {
+ if (closedir(dirp) == -1) {
if (*dents)
free(*dents);
printerr(1, "closedir");
}
+
return n;
}
static int i;
static char *p;
- p = xmemrchr(path, '/', strlen(path));
- if (!p)
- p = path;
- else
- /* We are assuming an entry with actual
- name ending in '/' will not appear */
- p++;
-
+ p = basename(path);
DPRINTF_S(p);
for (i = 0; i < n; i++)
populate(char *path, char *oldpath, char *fltr)
{
static regex_t re;
- static int r;
/* Can fail when permissions change while browsing */
if (canopendir(path) == 0)
return -1;
/* Search filter */
- r = setfilter(&re, fltr);
- if (r != 0)
+ if (setfilter(&re, fltr) != 0)
return -1;
ndents = dentfill(path, &dents, visible, &re);
redraw(char *path)
{
static char cwd[PATH_MAX];
- static int nlines, odd;
- static int i;
+ static int nlines, i;
static size_t ncols;
nlines = MIN(LINES - 4, ndents);
printw(CWD "%s\n\n", cwd);
/* Print listing */
- odd = ISODD(nlines);
if (cur < (nlines >> 1)) {
for (i = 0; i < nlines; i++)
printptr(&dents[i], i == cur);
for (i = ndents - nlines; i < ndents; i++)
printptr(&dents[i], i == cur);
} else {
+ static int odd;
+ odd = ISODD(nlines);
nlines >>= 1;
for (i = cur - nlines; i < cur + nlines + odd; i++)
printptr(&dents[i], i == cur);
fprintf(fp, "cd \"%s\"", path);
fclose(fp);
}
+
+ /* Fall through to exit */
}
case SEL_QUIT:
dentfree(dents);
return;
case SEL_BACK:
/* There is no going back */
- if (strcmp(path, "/") == 0 ||
- strchr(path, '/') == NULL) {
+ if (path[0] == '/' && path[1] == '\0') {
printmsg("You are at /");
goto nochange;
}
+
dir = xdirname(path);
if (canopendir(dir) == 0) {
printwarn();