diff --git a/configure.ac b/configure.ac index 9cec626..78f8c24 100644 --- a/configure.ac +++ b/configure.ac @@ -6,10 +6,14 @@ AM_INIT_AUTOMAKE([foreign std-options subdir-objects]) # Check for programs. AC_PROG_CC +AC_PROG_CC_C99 AC_PROG_INSTALL AC_PROG_RANLIB PKG_PROG_PKG_CONFIG +# Enable POSIX +AC_DEFINE([_POSIX_C_SOURCE], [200809L], [Use POSIX 2008 features]) + # Check for header files. AC_CHECK_HEADERS( [limits.h sys/time.h sys/types.h sys/stat.h dirent.h unistd.h fnmatch.h ncurses.h],[], @@ -25,7 +29,7 @@ AC_STRUCT_ST_BLOCKS # Check for library functions. AC_CHECK_FUNCS( - [getcwd gettimeofday fnmatch chdir rmdir unlink lstat system getenv],[], + [getcwd clock_gettime fnmatch chdir rmdir unlink lstat system getenv],[], AC_MSG_ERROR([required function missing])) AC_CHECK_FUNCS(statfs) diff --git a/src/main.c b/src/main.c index 13b6de8..4dfe4be 100644 --- a/src/main.c +++ b/src/main.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include @@ -48,7 +48,7 @@ int confirm_quit = 0; static int min_rows = 17, min_cols = 60; static int ncurses_init = 0; static int ncurses_tty = 0; /* Explicitely open /dev/tty instead of using stdio */ -static long lastupdate = 999; +static long lastupdate = 999999; static void screen_draw(void) { @@ -70,16 +70,16 @@ static void screen_draw(void) { */ int input_handle(int wait) { int ch; - struct timeval tv; + struct timespec ts; if(wait != 1) screen_draw(); else { - gettimeofday(&tv, NULL); - tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / update_delay; - if(lastupdate != tv.tv_usec) { + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_nsec = (1000000*(ts.tv_sec % 1000) + (ts.tv_nsec / 1000)) / update_delay; + if(lastupdate != ts.tv_nsec) { screen_draw(); - lastupdate = tv.tv_usec; + lastupdate = ts.tv_nsec; } } diff --git a/src/util.c b/src/util.c index 8448956..48df7bb 100644 --- a/src/util.c +++ b/src/util.c @@ -124,14 +124,13 @@ char *fullsize(int64_t from) { char *fmtmode(unsigned short mode) { static char buf[11]; - unsigned short ft = mode & S_IFMT; - buf[0] = ft == S_IFDIR ? 'd' - : ft == S_IFREG ? '-' - : ft == S_IFLNK ? 'l' - : ft == S_IFIFO ? 'p' - : ft == S_IFSOCK ? 's' - : ft == S_IFCHR ? 'c' - : ft == S_IFBLK ? 'b' : '?'; + buf[0] = S_ISDIR(mode) ? 'd' + : S_ISREG(mode) ? '-' + : S_ISLNK(mode) ? 'l' + : S_ISFIFO(mode) ? 'p' + : S_ISSOCK(mode) ? 's' + : S_ISCHR(mode) ? 'c' + : S_ISBLK(mode) ? 'b' : '?'; buf[1] = mode & 0400 ? 'r' : '-'; buf[2] = mode & 0200 ? 'w' : '-'; buf[3] = mode & 0100 ? 'x' : '-';