move sys/time.h support functionality out of generic header

The utils header is a large collection of functionality for several
system headers and API. This splits out the ones from sys/time.h into
a separate header reducing the need for many unconnected source files
to include the system header unecessarily.
This commit is contained in:
Vincent Sanders 2016-04-19 09:16:09 +01:00
parent 46e1061ef3
commit 836ea5679e
11 changed files with 61 additions and 36 deletions

View File

@ -19,9 +19,9 @@
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "utils/sys_time.h"
#include "utils/errors.h"
#include "atari/schedule.h"

View File

@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include "utils/sys_time.h"
#include "utils/log.h"
#include "framebuffer/schedule.h"

View File

@ -20,11 +20,11 @@
#include <stdlib.h>
#include <limits.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "utils/config.h"
#include "utils/sys_time.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/filepath.h"

View File

@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include "utils/sys_time.h"
#include "utils/log.h"
#include "monkey/schedule.h"

View File

@ -32,7 +32,6 @@
#include <assert.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <curl/curl.h>
#include <libwapcaplet/libwapcaplet.h>
@ -46,6 +45,7 @@
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
#include "utils/sys_time.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"

View File

@ -22,9 +22,9 @@
#include <stdarg.h>
#include <stdio.h>
#include <sys/time.h>
#include "utils/config.h"
#include "utils/sys_time.h"
#include "utils/utsname.h"
#include "desktop/version.h"

53
utils/sys_time.h Normal file
View File

@ -0,0 +1,53 @@
/*
* Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file
* \brief BSD style time functions
*/
#ifndef _NETSURF_UTILS_SYS_TIME_H_
#define _NETSURF_UTILS_SYS_TIME_H_
#include <sys/time.h>
#ifndef timeradd
#define timeradd(a, aa, result) \
do { \
(result)->tv_sec = (a)->tv_sec + (aa)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (aa)->tv_usec; \
if ((result)->tv_usec >= 1000000) { \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
} \
} while (0)
#endif
#ifndef timersub
#define timersub(a, aa, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (aa)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (aa)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
#endif
#endif

View File

@ -28,7 +28,6 @@
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <regex.h>
#include <time.h>
#include <errno.h>

View File

@ -31,7 +31,6 @@
#include <stddef.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <regex.h>
#include <assert.h>
#include <stdarg.h>
@ -119,32 +118,6 @@ struct dirent;
#define SLEN(x) (sizeof((x)) - 1)
#ifndef timeradd
#define timeradd(a, aa, result) \
do { \
(result)->tv_sec = (a)->tv_sec + (aa)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (aa)->tv_usec; \
if ((result)->tv_usec >= 1000000) { \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
} \
} while (0)
#endif
#ifndef timersub
#define timersub(a, aa, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (aa)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (aa)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
#endif
/**
* Replace consecutive whitespace with a single space.
*

View File

@ -17,13 +17,13 @@
*/
#include <limits.h>
#include <sys/time.h>
#include "utils/config.h"
#include <shlobj.h>
#include <windows.h>
#include "utils/sys_time.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/url.h"

View File

@ -16,9 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/time.h>
#include <time.h>
#include "utils/sys_time.h"
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/errors.h"