mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Some more compatibility improvements for C89 environments
This compiles now fine with gcc 2.95 on Haiku.
This commit is contained in:
parent
15ebd21195
commit
e29a42a02a
7 changed files with 16 additions and 9 deletions
|
|
@ -71,10 +71,10 @@ static void browse_draw_info(struct dir *dr) {
|
||||||
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory" : dr->flags & FF_FILE ? "File" : "Other");
|
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory" : dr->flags & FF_FILE ? "File" : "Other");
|
||||||
|
|
||||||
if(e) {
|
if(e) {
|
||||||
|
time_t t = (time_t)e->mtime;
|
||||||
ncaddstr(4, 9, fmtmode(e->mode));
|
ncaddstr(4, 9, fmtmode(e->mode));
|
||||||
ncprint(4, 26, "%d", e->uid);
|
ncprint(4, 26, "%d", e->uid);
|
||||||
ncprint(4, 38, "%d", e->gid);
|
ncprint(4, 38, "%d", e->gid);
|
||||||
time_t t = (time_t)e->mtime;
|
|
||||||
strftime(mbuf, sizeof(mbuf), "%Y-%m-%d %H:%M:%S %z", localtime(&t));
|
strftime(mbuf, sizeof(mbuf), "%Y-%m-%d %H:%M:%S %z", localtime(&t));
|
||||||
ncaddstr(5, 18, mbuf);
|
ncaddstr(5, 18, mbuf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,13 +77,14 @@ void dir_curpath_leave() {
|
||||||
|
|
||||||
|
|
||||||
void dir_setlasterr(const char *path) {
|
void dir_setlasterr(const char *path) {
|
||||||
|
int req;
|
||||||
if(!path) {
|
if(!path) {
|
||||||
free(lasterr);
|
free(lasterr);
|
||||||
lasterr = NULL;
|
lasterr = NULL;
|
||||||
lasterrl = 0;
|
lasterrl = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int req = strlen(path)+1;
|
req = strlen(path)+1;
|
||||||
if(lasterrl < req) {
|
if(lasterrl < req) {
|
||||||
lasterrl = req;
|
lasterrl = req;
|
||||||
lasterr = xrealloc(lasterr, lasterrl);
|
lasterr = xrealloc(lasterr, lasterrl);
|
||||||
|
|
@ -93,12 +94,12 @@ void dir_setlasterr(const char *path) {
|
||||||
|
|
||||||
|
|
||||||
void dir_seterr(const char *fmt, ...) {
|
void dir_seterr(const char *fmt, ...) {
|
||||||
|
va_list va;
|
||||||
free(dir_fatalerr);
|
free(dir_fatalerr);
|
||||||
dir_fatalerr = NULL;
|
dir_fatalerr = NULL;
|
||||||
if(!fmt)
|
if(!fmt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
va_list va;
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
dir_fatalerr = xmalloc(1024); /* Should be enough for everything... */
|
dir_fatalerr = xmalloc(1024); /* Should be enough for everything... */
|
||||||
vsnprintf(dir_fatalerr, 1023, fmt, va);
|
vsnprintf(dir_fatalerr, 1023, fmt, va);
|
||||||
|
|
|
||||||
|
|
@ -45,13 +45,13 @@ static hl_t *links = NULL;
|
||||||
/* recursively checks a dir structure for hard links and fills the lookup array */
|
/* recursively checks a dir structure for hard links and fills the lookup array */
|
||||||
static void hlink_init(struct dir *d) {
|
static void hlink_init(struct dir *d) {
|
||||||
struct dir *t;
|
struct dir *t;
|
||||||
|
int r;
|
||||||
|
|
||||||
for(t=d->sub; t!=NULL; t=t->next)
|
for(t=d->sub; t!=NULL; t=t->next)
|
||||||
hlink_init(t);
|
hlink_init(t);
|
||||||
|
|
||||||
if(!(d->flags & FF_HLNKC))
|
if(!(d->flags & FF_HLNKC))
|
||||||
return;
|
return;
|
||||||
int r;
|
|
||||||
hl_put(links, d, &r);
|
hl_put(links, d, &r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,7 @@ static char *dir_read(int *err) {
|
||||||
buf = xmalloc(buflen);
|
buf = xmalloc(buflen);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
size_t len, req;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if ((item = readdir(dir)) == NULL) {
|
if ((item = readdir(dir)) == NULL) {
|
||||||
if(errno)
|
if(errno)
|
||||||
|
|
@ -172,7 +173,8 @@ static char *dir_read(int *err) {
|
||||||
}
|
}
|
||||||
if(item->d_name[0] == '.' && (item->d_name[1] == 0 || (item->d_name[1] == '.' && item->d_name[2] == 0)))
|
if(item->d_name[0] == '.' && (item->d_name[1] == 0 || (item->d_name[1] == '.' && item->d_name[2] == 0)))
|
||||||
continue;
|
continue;
|
||||||
size_t len = strlen(item->d_name), req = off+3+len;
|
len = strlen(item->d_name);
|
||||||
|
req = off+3+len;
|
||||||
if(req > buflen) {
|
if(req > buflen) {
|
||||||
buflen = req < buflen*2 ? buflen*2 : req;
|
buflen = req < buflen*2 ? buflen*2 : req;
|
||||||
buf = xrealloc(buf, buflen);
|
buf = xrealloc(buf, buflen);
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,6 @@ static void argv_parse(int argc, char **argv) {
|
||||||
char *import = NULL;
|
char *import = NULL;
|
||||||
char *dir = NULL;
|
char *dir = NULL;
|
||||||
|
|
||||||
uic_theme = getenv("NO_COLOR") ? 0 : 2;
|
|
||||||
|
|
||||||
static yopt_opt_t opts[] = {
|
static yopt_opt_t opts[] = {
|
||||||
{ 'h', 0, "-h,-?,--help" },
|
{ 'h', 0, "-h,-?,--help" },
|
||||||
{ 'q', 0, "-q" },
|
{ 'q', 0, "-q" },
|
||||||
|
|
@ -149,6 +147,8 @@ static void argv_parse(int argc, char **argv) {
|
||||||
{0,0,NULL}
|
{0,0,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uic_theme = getenv("NO_COLOR") ? 0 : 2;
|
||||||
|
|
||||||
dir_ui = -1;
|
dir_ui = -1;
|
||||||
si = 0;
|
si = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,11 @@
|
||||||
|
|
||||||
static void set_level(void) {
|
static void set_level(void) {
|
||||||
static int done = 0;
|
static int done = 0;
|
||||||
|
const char *lvl;
|
||||||
char nlvl[2];
|
char nlvl[2];
|
||||||
if(done)
|
if(done)
|
||||||
return;
|
return;
|
||||||
const char *lvl = getenv("NCDU_LEVEL");
|
lvl = getenv("NCDU_LEVEL");
|
||||||
/* too lazy to count beyond 9 */
|
/* too lazy to count beyond 9 */
|
||||||
if(lvl && *lvl >= '1' && *lvl < '9' && lvl[1] == 0) {
|
if(lvl && *lvl >= '1' && *lvl < '9' && lvl[1] == 0) {
|
||||||
nlvl[0] = 1 + *lvl;
|
nlvl[0] = 1 + *lvl;
|
||||||
|
|
|
||||||
|
|
@ -147,10 +147,13 @@ char *fmtmode(unsigned short mode) {
|
||||||
|
|
||||||
|
|
||||||
void read_locale() {
|
void read_locale() {
|
||||||
|
#ifdef HAVE_LOCALE_H
|
||||||
|
char *locale_thou_sep;
|
||||||
|
#endif
|
||||||
thou_sep = '.';
|
thou_sep = '.';
|
||||||
#ifdef HAVE_LOCALE_H
|
#ifdef HAVE_LOCALE_H
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
char *locale_thou_sep = localeconv()->thousands_sep;
|
locale_thou_sep = localeconv()->thousands_sep;
|
||||||
if(locale_thou_sep && 1 == strlen(locale_thou_sep))
|
if(locale_thou_sep && 1 == strlen(locale_thou_sep))
|
||||||
thou_sep = locale_thou_sep[0];
|
thou_sep = locale_thou_sep[0];
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue