* Switched to -std=c99 compile mode, using explicit feature macros where necessary.
authorUrban Wallasch <urban.wallasch@freenet.de>
Mon, 22 Jul 2019 13:22:59 +0000 (15:22 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Mon, 22 Jul 2019 13:22:59 +0000 (15:22 +0200)
* Removed ntime dependency from fserv.c.

Makefile
fserv.c
net.c
ntime.c [deleted file]
ntime.h [deleted file]
shmget.c
telehttpd.c

index e00c59f1cd83173577e48b73db9beef61e34278a..e49e4c63531c84c767104069f2f0bd07997f4abd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ SDK_INCLUDES=\
   -Isdk/include/amtrucks/ \
   -Isdk/include/eurotrucks2
 
-CFLAGS=-Wall -Wextra -std=gnu99 -DDEBUG -I.
+CFLAGS=-Wall -Wextra -std=c99 -DDEBUG -I.
 
 UNAME:= $(shell uname -s)
 
@@ -30,7 +30,7 @@ all: telehttpd telelogger telemetry.so
 telemetry.so: telemetry.cpp $(SDK_HEADERS)
        g++ -o $@ -fPIC -Wall --shared -Wl,$(LIB_NAME_OPTION),$@ $(SDK_INCLUDES) telemetry.cpp
 
-telehttpd: telehttpd.o shmget.o net.o fserv.o ntime.o
+telehttpd: telehttpd.o shmget.o net.o fserv.o
        $(CC) $(LDFLAGS) -o $@ -pthread $^
 
 telelogger: telelogger.o shmget.o
diff --git a/fserv.c b/fserv.c
index 18a2cf5bd8891440d87b5690d2131b4251c96480..c668dbf24df91760b31f215a83352ba295c4175e 100644 (file)
--- a/fserv.c
+++ b/fserv.c
@@ -10,7 +10,6 @@
 
 #include "fserv.h"
 #include "log.h"
-#include "ntime.h"
 
 
 #define BUFSIZE 65536
@@ -41,32 +40,12 @@ int fserv_open_server( const char *fn, struct file_info_t *fi )
        return 0;
 }
 
-#ifdef DEBUG
-// returns NOW which can be fed as start in subsequent calls
-static unsigned long fserv_report_speed( size_t sent, unsigned long start )
-{
-       unsigned long now = ntime_to_ms( nclock_get() );
-       unsigned long tsdiff = now - start;
-       if ( tsdiff >= 3 )
-       {
-               DPRINT( "%lu bytes in %lu ms @ %5.2f kB/s\n",
-                               sent, tsdiff, (double)sent * 1000 / tsdiff / 1024 );
-       }
-       return now;
-}
-#endif
-
 int fserv_sendfile( int outfd, struct file_info_t *fi )
 {
        off_t sent = 0;
        int err = -1;
        char buf[BUFSIZE];
        size_t bread, bwr;
-#ifdef DEBUG
-       size_t str = 0;
-       unsigned long start, chkt;
-       start = chkt = ntime_to_ms( nclock_get() );
-#endif
 
        DPRINT( "send file contents\n" );
        if ( fi->coff != lseek( fi->fd, fi->coff, SEEK_SET ) )
@@ -99,24 +78,12 @@ int fserv_sendfile( int outfd, struct file_info_t *fi )
                        goto DONE;
                }
                sent += bwr;
-#ifdef DEBUG
-               str += bwr;
-               if ( ntime_to_ms( nclock_get() ) - chkt >= 10000 )
-               {
-                       chkt = fserv_report_speed( str, chkt );
-                       str = 0;
-               }
-#endif
        }
        err = 0;
 DONE:
        fi->remn -= sent;
        DPRINT( "Sent %lu, remaining %lu, resume at %lu\n",
                        sent, fi->remn, fi->coff );
-#ifdef DEBUG
-       if ( sent > 0 )
-               fserv_report_speed( sent, start );
-#endif
        return err;
 }
 
diff --git a/net.c b/net.c
index 776551f4b35f04cc92eb9791df58cb1fbf622bd7..5b54db667b372e1ffd24870c6c7436b8e656a6a9 100644 (file)
--- a/net.c
+++ b/net.c
@@ -7,6 +7,9 @@
  *             2013-05-31      support bind address, statics no more [uw]
  */
 
+// Needed for inet_aton() and herror():
+#define _DEFAULT_SOURCE
+
 #include <stdio.h>
 #include <string.h>
 
diff --git a/ntime.c b/ntime.c
deleted file mode 100644 (file)
index 56b5fa6..0000000
--- a/ntime.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
-
- ntime.c
-
- Get and convert absolute and relative times expressed in nanoseconds
- represented as simple integral objects. Accuracy depends on the
- underlying implementation and hardware.
-
- The getter functions are basically convenience wrappers for the
- POSIX clock_gettime() and clock_getres() interface, which must be
-available on the target system. (Link with librt, if required.)
-
-
- Copyright (c) 2013 Urban Wallasch
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
-*/
-
-
-#include <ntime.h>
-
-
-#if defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
-#include <unistd.h>
-#endif
-
-#if !defined(_POSIX_TIMERS) || !(_POSIX_TIMERS > 0) || !defined(CLOCK_REALTIME)
-#error "POSIX timers required but not available!"
-#endif
-
-/*
- Select the monotonic clock source best suited for relative timing
- measurements.
-
- Note 1:
- CLOCK_MONOTONIC_RAW provided by modern Linux based systems seems a
- better choice over CLOCK_MONOTONIC, since it is guaranteed to not
- be influenced by NTP slew, thus running at a constant speed. The
- drawback is it might run slightly slower or faster than the adjusted
- monotonic clock.
-
- Note 2:
- Untested on AIX, BSD, Solaris.
-*/
-#if defined(CLOCK_MONOTONIC_PRECISE)   /* BSD */
-#define NT_MONOCLOCK   CLOCK_MONOTONIC_PRECISE
-#elif defined(CLOCK_MONOTONIC_RAW)             /* Linux */
-#define NT_MONOCLOCK   CLOCK_MONOTONIC_RAW
-#elif defined(CLOCK_HIGHRES)                   /* Solaris */
-#define NT_MONOCLOCK   CLOCK_HIGHRES
-#elif defined(CLOCK_MONOTONIC)                 /* AIX, BSD, Linux, Solaris, generally POSIX compliant*/
-#define NT_MONOCLOCK   CLOCK_MONOTONIC
-#else
-#error "No monotonic clock available!"
-#endif
-
-#define NT_REALCLOCK   CLOCK_REALTIME
-
-
-struct timeval *ntime_to_timeval( ntime_t t, struct timeval *tv )
-{
-       tv->tv_sec = t / NT_NS_PER_S;
-       tv->tv_usec = t % NT_NS_PER_S / NT_NS_PER_US;
-       return tv;
-}
-
-ntime_t ntime_from_timeval( struct timeval *tv )
-{
-       return (ntime_t)tv->tv_sec * NT_NS_PER_S + tv->tv_usec * NT_NS_PER_US;
-}
-
-
-struct timespec *ntime_to_timespec( ntime_t t, struct timespec *ts )
-{
-       ts->tv_sec = t / NT_NS_PER_S;
-       ts->tv_nsec = t % NT_NS_PER_S;
-       return ts;
-}
-
-ntime_t ntime_from_timespec( struct timespec *ts )
-{
-       return (ntime_t)ts->tv_sec * NT_NS_PER_S + ts->tv_nsec;
-}
-
-
-ntime_t ntime_get( void )
-{
-       struct timespec ts;
-       if ( 0 != clock_gettime( NT_REALCLOCK, &ts ) )
-               return -1;
-       return ntime_from_timespec( &ts );
-}\r
-
-ntime_t ntime_res( void )
-{
-       struct timespec ts;
-       if ( 0 != clock_getres( NT_REALCLOCK, &ts ) )
-               return -1;
-       return ntime_from_timespec( &ts );
-}\r
-
-
-ntime_t nclock_get( void )
-{
-       struct timespec ts;
-       if ( 0 != clock_gettime( NT_MONOCLOCK, &ts ) )
-               return -1;
-       return ntime_from_timespec( &ts );
-}\r
-
-ntime_t nclock_res( void )
-{
-       struct timespec ts;
-       if ( 0 != clock_getres( NT_MONOCLOCK, &ts ) )
-               return -1;
-       return ntime_from_timespec( &ts );
-}\r
-
-/* EOF */
diff --git a/ntime.h b/ntime.h
deleted file mode 100644 (file)
index cf37c16..0000000
--- a/ntime.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
-
- ntime.h
-
- Get and convert absolute and relative times expressed in nanoseconds
- represented as simple integral objects. Accuracy depends on the
- underlying implementation and hardware.
-
- The getter functions are basically convenience wrappers for the
- POSIX clock_gettime() and clock_getres() interface, which must be
- available on the target system. (Link with librt, if required.)
-
-
- Copyright (c) 2013 Urban Wallasch
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
-*/
-
-#ifndef NTIME_H_INCLUDED
-#define NTIME_H_INCLUDED
-
-#ifdef _cplusplus
-extern "C" {
-#endif
-
-#include <inttypes.h>
-#include <time.h>
-#include <sys/time.h>
-
-
-/*
- Conversion specifier string macros suitable for use in fprintf/fscanf
- format strings.
-*/
-#define PRI_ntime              PRIdLEAST64
-#define SCA_ntime              SCAdLEAST64
-
-/*
- Guess what. Got tired of typing zeroes.
-*/
-#define NT_NS_PER_S            (1000*1000*1000)
-#define NT_NS_PER_MS   (1000*1000)
-#define NT_NS_PER_US   (1000)
-
-#define NT_US_PER_S            (1000*1000)
-#define NT_US_PER_MS   (1000)
-
-#define NT_MS_PER_S            (1000)
-
-/*
- Type to hold ntime values. Capable of holding absolute time
- values in nanosecond resolution at least up until the year 2262.
-*/
-typedef int_least64_t ntime_t;
-
-
-/*
- Convert between ntime_t and other common time representations.
- No rounding applied so that results should agree with those
- returned by time() and gettimeofday(). Conversions to and from
- structural types are implemented as functions to steer clear 
- of macros evaluating their arguments more than once.
-  
- The (in principle good) idea to use inline functions here was 
- dropped due to the incomprehensible mess of 'inline' semantics 
- across various C standards and compilers. Instead, use a high 
- optimization setting and let the comopiler figure out the best 
- way to deal with it. Sigh. [uw 2014-03-21]
-*/
-
-#define ntime_to_time_t(t)             ( (time_t)( (t) / NT_NS_PER_S ) )
-#define ntime_from_time_t(t)   ( (ntime_t)(t) * NT_NS_PER_S )
-
-#define ntime_to_ms(t)                 ( (t) / NT_NS_PER_MS )
-#define ntime_from_ms(m)               ( (ntime_t)(m) * NT_NS_PER_MS )
-
-extern struct timeval *ntime_to_timeval( ntime_t t, struct timeval *tv );
-extern ntime_t ntime_from_timeval( struct timeval *tv );
-
-extern struct timespec *ntime_to_timespec( ntime_t t, struct timespec *ts );
-extern ntime_t ntime_from_timespec( struct timespec *ts );
-
-
-/*
- Get real ("wall-clock") time in nanoseconds since UNIX epoch.
- This may experience discontinuous jumps due to time adjustments.
- Use this in (absolute) calendar time calculations.
- Returns -1 on error.
-*/
-extern ntime_t ntime_get( void );
-
-/*
- Get real ("wall-")clock resolution in nanoseconds.
- Returns -1 on error.
-*/
-extern ntime_t ntime_res( void );
-
-/*
- Get monotonic clock time in nanoseconds since arbitrary epoch,
- usually boot time on Linux systems; guaranteed to not "jump"
- due to time adjustments, but might be subject to NTP slew,
- depending on the target system. Best suited for (relative) timing
- purposes.
- Returns -1 on error.
-*/
-extern ntime_t nclock_get( void );
-
-/*
- Get monotonic clock resolution in nanoseconds.
- Returns -1 on error.
-*/
-extern ntime_t nclock_res( void );
-
-
-#ifdef _cplusplus
-} //extern "C" {
-#endif
-
-#endif //ndef NTIME_H_INCLUDED
-
-/* EOF */
index dbf5660ededb8c70c89443412c1a36cd0c555e69..c604be16eb34023e0d2893c830c94c24b301cfac 100644 (file)
--- a/shmget.c
+++ b/shmget.c
@@ -1,3 +1,6 @@
+// Needed for ipc.h:
+#define _XOPEN_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
index 4bf7e1091404148c483bf56d3dfd70f45d6a3c74..73b3f89fb4ae932cebdd5a41446b440be14a8cd8 100644 (file)
@@ -1,3 +1,6 @@
+// Needed for getopt():
+#define _XOPEN_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>