This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] y2038: Helper macro to convert struct __timespec64 to struct timespec


On 10/18/19 7:57 AM, Lukasz Majewski wrote:

+/* Check if a value lies with the valid nanoseconds range.  */
+#define IS_VALID_NANOSECONDS(ns) ((ns) >= 0 && (ns) <= 999999999)

This should be a static or inline function; there's no need for the excessive power of a macro here.

+#define timespec64_to_timespec(ts64)                                           \
+  ({                                                                           \
+    if (! IS_VALID_NANOSECONDS (ts64.tv_nsec))                                 \
+      {                                                                        \
+        __set_errno (EINVAL);                                                  \
+        return -1;                                                             \
+      }                                                                        \
+    if (! in_time_t_range (ts64.tv_sec))                                       \
+      {                                                                        \
+        __set_errno (EOVERFLOW);                                               \
+        return -1;                                                             \
+      }                                                                        \
+    valid_timespec64_to_timespec (ts64); })

This macro is too confusing. Instead, if there's a need for this sort of thing, I suggest a static or inline function that returns true or false (setting errno); the caller can decide what to do if it returns false.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]