mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Fix warnings. Harden compilation.
This commit is contained in:
parent
8fbd97a1ea
commit
aebe6c1898
|
@ -13,5 +13,5 @@ matrix:
|
||||||
- os: osx
|
- os: osx
|
||||||
compiler: clang
|
compiler: clang
|
||||||
script:
|
script:
|
||||||
- make CFLAGS='-Werror'
|
- make clean
|
||||||
- make CFLAGS='-Wall -Wextra -Werror'
|
- make
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ VERSION = 0.6
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
MANPREFIX = $(PREFIX)/man
|
MANPREFIX = $(PREFIX)/man
|
||||||
|
|
||||||
CFLAGS += -O3 -march=native
|
CFLAGS += -O3 -march=native -Wall -Wextra -Werror
|
||||||
LDLIBS = -lcurses
|
LDLIBS = -lcurses
|
||||||
|
|
||||||
DISTFILES = nnn.c config.def.h nnn.1 Makefile README.md LICENSE
|
DISTFILES = nnn.c config.def.h nnn.1 Makefile README.md LICENSE
|
||||||
|
|
43
nnn.c
43
nnn.c
|
@ -21,6 +21,21 @@
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
static int
|
||||||
|
xprintf(int fd, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buf[BUFSIZ];
|
||||||
|
int r;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
r = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
|
if (r > 0)
|
||||||
|
r = write(fd, buf, r);
|
||||||
|
va_end(ap);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
#define DEBUG_FD 8
|
#define DEBUG_FD 8
|
||||||
#define DPRINTF_D(x) xprintf(DEBUG_FD, #x "=%d\n", x)
|
#define DPRINTF_D(x) xprintf(DEBUG_FD, #x "=%d\n", x)
|
||||||
#define DPRINTF_U(x) xprintf(DEBUG_FD, #x "=%u\n", x)
|
#define DPRINTF_U(x) xprintf(DEBUG_FD, #x "=%u\n", x)
|
||||||
|
@ -90,6 +105,8 @@ typedef struct entry {
|
||||||
off_t size;
|
off_t size;
|
||||||
} *pEntry;
|
} *pEntry;
|
||||||
|
|
||||||
|
typedef unsigned long ulong;
|
||||||
|
|
||||||
/* Global context */
|
/* Global context */
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
static int ndents, cur;
|
static int ndents, cur;
|
||||||
|
@ -120,21 +137,6 @@ static void printmsg(char *);
|
||||||
static void printwarn(void);
|
static void printwarn(void);
|
||||||
static void printerr(int, char *);
|
static void printerr(int, char *);
|
||||||
|
|
||||||
static int
|
|
||||||
xprintf(int fd, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
char buf[BUFSIZ];
|
|
||||||
int r;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
r = vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
||||||
if (r > 0)
|
|
||||||
r = write(fd, buf, r);
|
|
||||||
va_end(ap);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
xrealloc(void *p, size_t size)
|
xrealloc(void *p, size_t size)
|
||||||
{
|
{
|
||||||
|
@ -729,7 +731,6 @@ show_stats(char* fpath, char* fname, struct stat *sb)
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX + 48];
|
char buf[PATH_MAX + 48];
|
||||||
char *perms = get_lsperms(sb->st_mode, buf);
|
char *perms = get_lsperms(sb->st_mode, buf);
|
||||||
FILE *pf;
|
|
||||||
char *p, *begin = buf;
|
char *p, *begin = buf;
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
@ -750,7 +751,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
|
||||||
sb->st_size, sb->st_blocks, sb->st_blksize, buf);
|
sb->st_size, sb->st_blocks, sb->st_blksize, buf);
|
||||||
|
|
||||||
/* Show containing device, inode, hardlink count */
|
/* Show containing device, inode, hardlink count */
|
||||||
sprintf(buf, "%lxh/%lud", sb->st_dev, sb->st_dev);
|
sprintf(buf, "%lxh/%lud", (ulong)sb->st_dev, (ulong)sb->st_dev);
|
||||||
printw("\n Device: %-15s Inode: %-11lu Links: %-9lu",
|
printw("\n Device: %-15s Inode: %-11lu Links: %-9lu",
|
||||||
buf, sb->st_ino, sb->st_nlink);
|
buf, sb->st_ino, sb->st_nlink);
|
||||||
|
|
||||||
|
@ -826,7 +827,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
|
||||||
/* Show exit keys */
|
/* Show exit keys */
|
||||||
printw("\n\n << (q/Esc)");
|
printw("\n\n << (q/Esc)");
|
||||||
|
|
||||||
while (*buf = getch())
|
for (*buf = getch(); *buf != 'q' && *buf != 27; *buf = getch())
|
||||||
if (*buf == 'q' || *buf == 27)
|
if (*buf == 'q' || *buf == 27)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -868,7 +869,7 @@ show_help(void)
|
||||||
/* Show exit keys */
|
/* Show exit keys */
|
||||||
printw("\n\n << (q/Esc)");
|
printw("\n\n << (q/Esc)");
|
||||||
|
|
||||||
while (c = getch())
|
for (c = getch(); c != 'q' && c != 27; c = getch())
|
||||||
if (c == 'q' || c == 27)
|
if (c == 'q' || c == 27)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -927,6 +928,7 @@ dentfind(struct entry *dents, int n, char *path)
|
||||||
if (!path)
|
if (!path)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
int i;
|
||||||
char *p = xmemrchr(path, '/', strlen(path));
|
char *p = xmemrchr(path, '/', strlen(path));
|
||||||
if (!p)
|
if (!p)
|
||||||
p = path;
|
p = path;
|
||||||
|
@ -937,7 +939,7 @@ dentfind(struct entry *dents, int n, char *path)
|
||||||
|
|
||||||
DPRINTF_S(p);
|
DPRINTF_S(p);
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
if (strcmp(p, dents[i].name) == 0)
|
if (strcmp(p, dents[i].name) == 0)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
|
@ -1175,6 +1177,7 @@ nochange:
|
||||||
status = system(cmd);
|
status = system(cmd);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
status++; /* Dummy operation */
|
||||||
printmsg("No association");
|
printmsg("No association");
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue