mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
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:
parent
d018dc0be6
commit
8be1145497
3 changed files with 19 additions and 16 deletions
|
|
@ -6,10 +6,14 @@ AM_INIT_AUTOMAKE([foreign std-options subdir-objects])
|
||||||
|
|
||||||
# Check for programs.
|
# Check for programs.
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
AC_PROG_CC_C99
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
AC_PROG_RANLIB
|
AC_PROG_RANLIB
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
|
|
||||||
|
# Enable POSIX
|
||||||
|
AC_DEFINE([_POSIX_C_SOURCE], [200809L], [Use POSIX 2008 features])
|
||||||
|
|
||||||
# Check for header files.
|
# Check for header files.
|
||||||
AC_CHECK_HEADERS(
|
AC_CHECK_HEADERS(
|
||||||
[limits.h sys/time.h sys/types.h sys/stat.h dirent.h unistd.h fnmatch.h ncurses.h],[],
|
[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.
|
# Check for library functions.
|
||||||
AC_CHECK_FUNCS(
|
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_MSG_ERROR([required function missing]))
|
||||||
|
|
||||||
AC_CHECK_FUNCS(statfs)
|
AC_CHECK_FUNCS(statfs)
|
||||||
|
|
|
||||||
14
src/main.c
14
src/main.c
|
|
@ -31,7 +31,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <yopt.h>
|
#include <yopt.h>
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ int confirm_quit = 0;
|
||||||
static int min_rows = 17, min_cols = 60;
|
static int min_rows = 17, min_cols = 60;
|
||||||
static int ncurses_init = 0;
|
static int ncurses_init = 0;
|
||||||
static int ncurses_tty = 0; /* Explicitely open /dev/tty instead of using stdio */
|
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) {
|
static void screen_draw(void) {
|
||||||
|
|
@ -70,16 +70,16 @@ static void screen_draw(void) {
|
||||||
*/
|
*/
|
||||||
int input_handle(int wait) {
|
int input_handle(int wait) {
|
||||||
int ch;
|
int ch;
|
||||||
struct timeval tv;
|
struct timespec ts;
|
||||||
|
|
||||||
if(wait != 1)
|
if(wait != 1)
|
||||||
screen_draw();
|
screen_draw();
|
||||||
else {
|
else {
|
||||||
gettimeofday(&tv, NULL);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / update_delay;
|
ts.tv_nsec = (1000000*(ts.tv_sec % 1000) + (ts.tv_nsec / 1000)) / update_delay;
|
||||||
if(lastupdate != tv.tv_usec) {
|
if(lastupdate != ts.tv_nsec) {
|
||||||
screen_draw();
|
screen_draw();
|
||||||
lastupdate = tv.tv_usec;
|
lastupdate = ts.tv_nsec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
src/util.c
15
src/util.c
|
|
@ -124,14 +124,13 @@ char *fullsize(int64_t from) {
|
||||||
|
|
||||||
char *fmtmode(unsigned short mode) {
|
char *fmtmode(unsigned short mode) {
|
||||||
static char buf[11];
|
static char buf[11];
|
||||||
unsigned short ft = mode & S_IFMT;
|
buf[0] = S_ISDIR(mode) ? 'd'
|
||||||
buf[0] = ft == S_IFDIR ? 'd'
|
: S_ISREG(mode) ? '-'
|
||||||
: ft == S_IFREG ? '-'
|
: S_ISLNK(mode) ? 'l'
|
||||||
: ft == S_IFLNK ? 'l'
|
: S_ISFIFO(mode) ? 'p'
|
||||||
: ft == S_IFIFO ? 'p'
|
: S_ISSOCK(mode) ? 's'
|
||||||
: ft == S_IFSOCK ? 's'
|
: S_ISCHR(mode) ? 'c'
|
||||||
: ft == S_IFCHR ? 'c'
|
: S_ISBLK(mode) ? 'b' : '?';
|
||||||
: ft == S_IFBLK ? 'b' : '?';
|
|
||||||
buf[1] = mode & 0400 ? 'r' : '-';
|
buf[1] = mode & 0400 ? 'r' : '-';
|
||||||
buf[2] = mode & 0200 ? 'w' : '-';
|
buf[2] = mode & 0200 ? 'w' : '-';
|
||||||
buf[3] = mode & 0100 ? 'x' : '-';
|
buf[3] = mode & 0100 ? 'x' : '-';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue