[v2] newlib/libc/include/time.h: Removed clock_id casts

Message ID 20241119221650.34832-1-aaron.nyholm@unfoldedeffective.com
State New
Headers
Series [v2] newlib/libc/include/time.h: Removed clock_id casts |

Commit Message

aaron.nyholm@unfoldedeffective.com Nov. 19, 2024, 10:16 p.m. UTC
  From: Aaron Nyholm <aaron.nyholm@unfoldedeffective.com>

The POSIX specification defines these as constants. The cast is
unnecessary. This brings newlib inline with the equivalent FreeBSD
defines.
---
 newlib/libc/include/time.h | 20 +++++------
 test                       | 71 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 10 deletions(-)
 create mode 100644 test
  

Comments

Corinna Vinschen Nov. 20, 2024, 11:13 a.m. UTC | #1
Hi Aaron,

On Nov 20 09:16, aaron.nyholm@unfoldedeffective.com wrote:
> The POSIX specification defines these as constants. The cast is
> unnecessary. This brings newlib inline with the equivalent FreeBSD
> defines.
> ---
>  newlib/libc/include/time.h | 20 +++++------
>  test                       | 71 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 81 insertions(+), 10 deletions(-)
>  create mode 100644 test

Pushed.


Thanks,
Corinna
  
Corinna Vinschen Nov. 20, 2024, 11:18 a.m. UTC | #2
On Nov 20 12:13, Corinna Vinschen wrote:
> Hi Aaron,
> 
> On Nov 20 09:16, aaron.nyholm@unfoldedeffective.com wrote:
> > The POSIX specification defines these as constants. The cast is
> > unnecessary. This brings newlib inline with the equivalent FreeBSD
> > defines.
> > ---
> >  newlib/libc/include/time.h | 20 +++++------
> >  test                       | 71 ++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 81 insertions(+), 10 deletions(-)
> >  create mode 100644 test
> 
> Pushed.

Unfortunately I missed the stray "test" file in the top-level dir.
I removed it with a followup patch.


Corinna
  

Patch

diff --git a/newlib/libc/include/time.h b/newlib/libc/include/time.h
index ed6cc70fe..ab3491341 100644
--- a/newlib/libc/include/time.h
+++ b/newlib/libc/include/time.h
@@ -237,10 +237,10 @@  extern "C" {
 /* Manifest Constants, P1003.1b-1993, p. 262 */
 
 #if __GNU_VISIBLE
-#define CLOCK_REALTIME_COARSE	((clockid_t) 0)
+#define CLOCK_REALTIME_COARSE	(0)
 #endif
 
-#define CLOCK_REALTIME		((clockid_t) 1)
+#define CLOCK_REALTIME		(1)
 
 /* Manifest Constants, P1003.4b/D8, p. 55 */
 
@@ -250,7 +250,7 @@  extern "C" {
    the identifier of the CPU_time clock associated with the PROCESS
    making the function call.  */
 
-#define CLOCK_PROCESS_CPUTIME_ID ((clockid_t) 2)
+#define CLOCK_PROCESS_CPUTIME_ID (2)
 
 #endif
 
@@ -260,7 +260,7 @@  extern "C" {
     the identifier of the CPU_time clock associated with the THREAD
     making the function call.  */
 
-#define CLOCK_THREAD_CPUTIME_ID	((clockid_t) 3)
+#define CLOCK_THREAD_CPUTIME_ID	(3)
 
 #endif
 
@@ -270,21 +270,21 @@  extern "C" {
  *  as a clock whose value cannot be set via clock_settime() and which
  *  cannot have backward clock jumps. */
 
-#define CLOCK_MONOTONIC		((clockid_t) 4)
+#define CLOCK_MONOTONIC		(4)
 
 #endif
 
 #if __GNU_VISIBLE
 
-#define CLOCK_MONOTONIC_RAW	((clockid_t) 5)
+#define CLOCK_MONOTONIC_RAW	(5)
 
-#define CLOCK_MONOTONIC_COARSE	((clockid_t) 6)
+#define CLOCK_MONOTONIC_COARSE	(6)
 
-#define CLOCK_BOOTTIME		((clockid_t) 7)
+#define CLOCK_BOOTTIME		(7)
 
-#define CLOCK_REALTIME_ALARM	((clockid_t) 8)
+#define CLOCK_REALTIME_ALARM	(8)
 
-#define CLOCK_BOOTTIME_ALARM	((clockid_t) 9)
+#define CLOCK_BOOTTIME_ALARM	(9)
 
 #endif
 
diff --git a/test b/test
new file mode 100644
index 000000000..63b216d0b
--- /dev/null
+++ b/test
@@ -0,0 +1,71 @@ 
+From: Aaron Nyholm <aaron.nyholm@unfoldedeffective.com>
+
+---
+ newlib/libc/include/time.h | 20 ++++++++++----------
+ 1 file changed, 10 insertions(+), 10 deletions(-)
+
+diff --git a/newlib/libc/include/time.h b/newlib/libc/include/time.h
+index ed6cc70fe..ab3491341 100644
+--- a/newlib/libc/include/time.h
++++ b/newlib/libc/include/time.h
+@@ -237,10 +237,10 @@ extern "C" {
+ /* Manifest Constants, P1003.1b-1993, p. 262 */
+
+ #if __GNU_VISIBLE
+-#define CLOCK_REALTIME_COARSE	((clockid_t) 0)
++#define CLOCK_REALTIME_COARSE	(0)
+ #endif
+
+-#define CLOCK_REALTIME		((clockid_t) 1)
++#define CLOCK_REALTIME		(1)
+
+ /* Manifest Constants, P1003.4b/D8, p. 55 */
+
+@@ -250,7 +250,7 @@ extern "C" {
+    the identifier of the CPU_time clock associated with the PROCESS
+    making the function call.  */
+
+-#define CLOCK_PROCESS_CPUTIME_ID ((clockid_t) 2)
++#define CLOCK_PROCESS_CPUTIME_ID (2)
+
+ #endif
+
+@@ -260,7 +260,7 @@ extern "C" {
+     the identifier of the CPU_time clock associated with the THREAD
+     making the function call.  */
+
+-#define CLOCK_THREAD_CPUTIME_ID	((clockid_t) 3)
++#define CLOCK_THREAD_CPUTIME_ID	(3)
+
+ #endif
+
+@@ -270,21 +270,21 @@ extern "C" {
+  *  as a clock whose value cannot be set via clock_settime() and which
+  *  cannot have backward clock jumps. */
+
+-#define CLOCK_MONOTONIC		((clockid_t) 4)
++#define CLOCK_MONOTONIC		(4)
+
+ #endif
+
+ #if __GNU_VISIBLE
+
+-#define CLOCK_MONOTONIC_RAW	((clockid_t) 5)
++#define CLOCK_MONOTONIC_RAW	(5)
+
+-#define CLOCK_MONOTONIC_COARSE	((clockid_t) 6)
++#define CLOCK_MONOTONIC_COARSE	(6)
+
+-#define CLOCK_BOOTTIME		((clockid_t) 7)
++#define CLOCK_BOOTTIME		(7)
+
+-#define CLOCK_REALTIME_ALARM	((clockid_t) 8)
++#define CLOCK_REALTIME_ALARM	(8)
+
+-#define CLOCK_BOOTTIME_ALARM	((clockid_t) 9)
++#define CLOCK_BOOTTIME_ALARM	(9)
+
+ #endif
+
+--
+2.46.2