diff --git a/include/sys/types.h b/include/sys/types.h index d548ad62b2b..321be8d9d96 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -231,9 +231,13 @@ typedef int16_t blksize_t; typedef unsigned int socklen_t; typedef uint16_t sa_family_t; -/* Used for system times in clock ticks */ +/* Used for system times in clock ticks (equivalent to systime_t) */ +#ifdef CONFIG_SYSTEM_TIME64 +typedef uint64_t clock_t; +#else typedef uint32_t clock_t; +#endif /* The type useconds_t shall be an unsigned integer type capable of storing * values at least in the range [0, 1000000]. The type suseconds_t shall be diff --git a/libc/time/Make.defs b/libc/time/Make.defs index f72fd4f99f1..417a5b3b1bb 100644 --- a/libc/time/Make.defs +++ b/libc/time/Make.defs @@ -1,7 +1,8 @@ ############################################################################ # libc/time/Make.defs # -# Copyright (C) 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2014-2015, 2018 Gregory Nutt. All rights +# reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,7 +38,7 @@ CSRCS += lib_strftime.c lib_calendar2utc.c lib_daysbeforemonth.c CSRCS += lib_gettimeofday.c lib_isleapyear.c lib_settimeofday.c lib_time.c -CSRCS += lib_difftime.c +CSRCS += lib_difftime.c lib_clock.c ifndef CONFIG_DISABLE_SIGNALS CSRCS += lib_nanosleep.c diff --git a/libc/time/lib_asctime.c b/libc/time/lib_asctime.c index 3ddf1074f8d..f2fef9850d2 100644 --- a/libc/time/lib_asctime.c +++ b/libc/time/lib_asctime.c @@ -55,7 +55,7 @@ * string representation. asctime is not re-entrant; asctime_r is re- * entrant * - * Parameters: + * Input Parameters: * tp - Pointer to the time to be converted. * * Returned Value: diff --git a/libc/time/lib_asctimer.c b/libc/time/lib_asctimer.c index bebbd21a122..e72230ba7b9 100644 --- a/libc/time/lib_asctimer.c +++ b/libc/time/lib_asctimer.c @@ -74,7 +74,7 @@ static const char * const g_mon_name[12] = * string representation. asctime is not re-entrant; asctime_r is re- * entrant. * - * Parameters: + * Input Parameters: * tp - Pointer to the time to be converted. * buf - A user provided buffer to receive the 26 character time string. * diff --git a/libc/time/lib_clock.c b/libc/time/lib_clock.c new file mode 100644 index 00000000000..c2e1b412c41 --- /dev/null +++ b/libc/time/lib_clock.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * libc/time/lib_clock.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: clock + * + * Description: + * The clock() function returns the implementation's best approximation to + * the processor time used by the process since the beginning of a + * implementation-defined era related only to the process invocation. + * + * To determine the time in seconds, the value returned by clock() should + * be divided by the value of the macro CLOCKS_PER_SEC as defined in . + * + * Input Parameters: + * None + * + * Returned Value: + * The system time in units of clock ticks is returend. If the processor + * time used is not available or its value cannot be represented, the + * function will return the value (clock_t)-1. + * + ****************************************************************************/ + +clock_t clock(void) +{ + return (clock_t)clock_systimer(); +} diff --git a/libc/time/lib_ctime.c b/libc/time/lib_ctime.c index 1151382816a..459383175ef 100644 --- a/libc/time/lib_ctime.c +++ b/libc/time/lib_ctime.c @@ -55,7 +55,7 @@ * epoch to a string representation. ctime is not re-entrant; ctime_r is * re-entrant. * - * Parameters: + * Input Parameters: * timep - The current time represented as seconds since the epoch. * * Returned Value: diff --git a/libc/time/lib_ctimer.c b/libc/time/lib_ctimer.c index 1286976c6d9..f8d8222a29a 100644 --- a/libc/time/lib_ctimer.c +++ b/libc/time/lib_ctimer.c @@ -59,7 +59,7 @@ * epoch to a string representation. ctime is not re-entrant; ctime_r is * re-entrant. * - * Parameters: + * Input Parameters: * timep - The current time represented as seconds since the epoch. * buf - A user provided buffer to receive the 26 character time string. * diff --git a/libc/time/lib_nanosleep.c b/libc/time/lib_nanosleep.c index ad728de5b8c..e2b9ed1a91a 100644 --- a/libc/time/lib_nanosleep.c +++ b/libc/time/lib_nanosleep.c @@ -63,7 +63,7 @@ * The use of the nanosleep() function has no effect on the action or * blockage of any signal. * - * Parameters: + * Input Parameters: * rqtp - The amount of time to be suspended from execution. * rmtp - If the rmtp argument is non-NULL, the timespec structure * referenced by it is updated to contain the amount of time diff --git a/libc/time/lib_time.c b/libc/time/lib_time.c index 683d8a71b9b..eb8d4ef9939 100644 --- a/libc/time/lib_time.c +++ b/libc/time/lib_time.c @@ -57,7 +57,7 @@ * and is provided for compatibility. clock_gettime() is the preferred way * to obtain system time. * - * Parameters: + * Input Parameters: * Pointer to an object of type time_t, where the time value is stored. * Alternatively, this parameter can be a null pointer, in which case the * parameter is not used, but a time_t object is still returned by the diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index 49c7fdfcff2..f6d17a1c9b4 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -136,15 +136,15 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, * is outside of the scope of getsockopt. */ - case SO_DEBUG: /* Enables recording of debugging information */ case SO_BROADCAST: /* Permits sending of broadcast messages */ - case SO_REUSEADDR: /* Allow reuse of local addresses */ + case SO_DEBUG: /* Enables recording of debugging information */ + case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */ #ifndef CONFIG_NET_TCPPROTO_OPTIONS case SO_KEEPALIVE: /* Verifies TCP connections active by enabling the * periodic transmission of probes */ #endif case SO_OOBINLINE: /* Leaves received out-of-band data inline */ - case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */ + case SO_REUSEADDR: /* Allow reuse of local addresses */ { sockopt_t optionset; @@ -254,14 +254,14 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, } break; - /* The following are not yet implemented */ + /* The following are not yet implemented (return values other than {0,1) */ case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */ - case SO_LINGER: - case SO_SNDBUF: /* Sets send buffer size */ - case SO_RCVBUF: /* Sets receive buffer size */ case SO_ERROR: /* Reports and clears error status. */ + case SO_LINGER: /* Lingers on a close() if data is present */ + case SO_RCVBUF: /* Sets receive buffer size */ case SO_RCVLOWAT: /* Sets the minimum number of bytes to input */ + case SO_SNDBUF: /* Sets send buffer size */ case SO_SNDLOWAT: /* Sets the minimum number of bytes to output */ default: diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index e59c242ad49..063939832c1 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -129,15 +129,15 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, * is outside of the scope of setsockopt. */ - case SO_DEBUG: /* Enables recording of debugging information */ case SO_BROADCAST: /* Permits sending of broadcast messages */ - case SO_REUSEADDR: /* Allow reuse of local addresses */ + case SO_DEBUG: /* Enables recording of debugging information */ + case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */ #ifndef CONFIG_NET_TCPPROTO_OPTIONS case SO_KEEPALIVE: /* Verifies TCP connections active by enabling the * periodic transmission of probes */ #endif case SO_OOBINLINE: /* Leaves received out-of-band data inline */ - case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */ + case SO_REUSEADDR: /* Allow reuse of local addresses */ { int setting; @@ -236,7 +236,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, break; #ifdef CONFIG_NET_SOLINGER - case SO_LINGER: + case SO_LINGER: /* Lingers on a close() if data is present */ { FAR struct linger *setting; @@ -276,9 +276,9 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, #endif /* The following are not yet implemented */ - case SO_SNDBUF: /* Sets send buffer size */ case SO_RCVBUF: /* Sets receive buffer size */ case SO_RCVLOWAT: /* Sets the minimum number of bytes to input */ + case SO_SNDBUF: /* Sets send buffer size */ case SO_SNDLOWAT: /* Sets the minimum number of bytes to output */ /* There options are only valid when used with getopt */