make C usage POSIX

Add AC_PROC_CC_C99 to configure.ac.
Define _POSIX_C_SOURCE to 200809L.
Replace gettimeofday, and timeval struct used with it, with POSIX
clock_gettime and timespec struct.
Replace XSI mode & S_IFMT, and S_IF* macros, with POSIX S_IS* macros.
This commit is contained in:
Ethan Sommer 2020-05-21 19:40:04 -04:00
parent d018dc0be6
commit 8be1145497
3 changed files with 19 additions and 16 deletions

View file

@ -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)

View file

@ -31,7 +31,7 @@
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <yopt.h>
@ -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;
}
}

View file

@ -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' : '-';