Skip to content

Commit 0af5eef

Browse files
!sys/types.h: change time_t and clock_t to int64_t to align with other OSes
POSIX leaves the signedness of time_t and clock_t unspecified, but mainstream implementations (Linux glibc/musl, the BSDs, macOS, RTEMS, Zephyr's POSIX layer, Windows _time64) expose time_t as signed 64-bit. NuttX has historically used uint64_t only because it was tied to the CONFIG_SYSTEM_TIME64 knob; with that gone, switch: time_t : uint64_t -> int64_t clock_t : uint64_t -> int64_t CLOCK_MAX: UINT64_MAX -> INT64_MAX This lets (time_t)-1 sentinels, negative tick deltas, and host-side headers behave as on every other POSIX system without source churn. Headers updated: - include/sys/types.h, include/limits.h, include/nuttx/clock.h - include/nuttx/fs/hostfs.h (nuttx_time_t alias) - include/nuttx/{mqueue.h,wdog.h,wqueue.h,timers/clkcnt.h} Because clock_t is now signed 64-bit, the NuttX-internal sclock_t alias becomes redundant: every sclock_t/SCLOCK_MAX use is folded back to clock_t/CLOCK_MAX (notably in sched/wdog, sched/mqueue, sched/sched, sched/clock, sched/timer, libs/libc/time, fs/vfs and the drivers/arch consumers below). Tick/period constants (NSEC_PER_SEC, USEC_PER_SEC, MSEC_PER_SEC, SEC_PER_MIN, ...) in include/nuttx/clock.h are retyped from "long" literals to INT64_C(...) so that 64-bit arithmetic no longer depends on the host's long width. Strip now-redundant (time_t)/(clock_t)/(unsigned long) casts and unsigned-only branches across the tree: - arch RTC / oneshot / tickless lowerhalfs: arm: cxd56xx, efm32, imxrt, lc823450, max326xx, sam34, sama5, samd5e5, samv7, stm32, stm32f7, stm32h7, stm32l4, stm32wb, xmc4 mips: pic32mz sparc: bm3803 x86_64: intel64 risc-v/xtensa: espressif (esp_i2c[_slave], esp_rtc, esp32c3{_i2c,_rtc,_wifi_adapter}, esp32{,s2,s3}_*), mpfs_perf - drivers: audio/tone, input/aw86225, power/pm/{activity, stability}_governor, rpmsg/rpmsg_ping, timers/{ds3231,mcp794xx,pcf85263,rx8010}, wireless/ieee80211/bcm43xxx, wireless/spirit/spirit_spi - core: fs/vfs/{fs_poll,fs_timerfd}, mm/iob/iob_alloc, libs/libc/{netdb/lib_dnscache,time/{lib_calendar2utc, lib_time}}, net/icmp/icmp_pmtu, net/icmpv6/icmpv6_pmtu, net/ipfrag, net/tcp/{tcp.h,tcp_timer}, net/utils/net_snoop, net/mld/mld_query (drop the now-dead mld_mrc2mrd helper since signed math handles it directly), sched/clock/{clock,clock_initialize}, sched/sched/{sched_profil,sched_setparam,sched_setscheduler}, sched/pthread/pthread_create, sched/wdog/{wd_gettime,wd_start,wdog.h}, sched/timer/timer_gettime, sched/mqueue/* Flip the few in-tree printf format strings that assumed an unsigned 64-bit tv_sec: * drivers/rpmsg/rpmsg_ping.c PRIu64 -> PRId64 * arch/xtensa/src/esp32{,s2,s3}/esp32*_oneshot_lowerhalf.c PRIu32 (already wrong) -> PRId64 Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent a8f50f5 commit 0af5eef

93 files changed

Lines changed: 227 additions & 282 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/arm/src/cxd56xx/cxd56_rtc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ time_t up_rtc_time(void)
394394
count += g_rtc_save->offset;
395395
count >>= 15; /* convert to 1sec resolution */
396396

397-
return (time_t)count / CONFIG_RTC_FREQUENCY;
397+
return count / CONFIG_RTC_FREQUENCY;
398398
}
399399
#endif
400400

arch/arm/src/efm32/efm32_rtc_burtc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int up_rtc_initialize(void)
398398
#ifndef CONFIG_RTC_HIRES
399399
time_t up_rtc_time(void)
400400
{
401-
return (time_t)efm32_get_burtc_tick() / CONFIG_RTC_FREQUENCY;
401+
return efm32_get_burtc_tick() / CONFIG_RTC_FREQUENCY;
402402
}
403403
#endif
404404

arch/arm/src/imxrt/imxrt_rtc_lowerhalf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int imxrt_rdalarm(struct rtc_lowerhalf_s *lower,
463463

464464
/* Get the current alarm setting in seconds */
465465

466-
alarm = (time_t)imxrt_hprtc_getalarm();
466+
alarm = imxrt_hprtc_getalarm();
467467

468468
/* Convert the one second epoch time to a struct tm */
469469

arch/arm/src/lc823450/lc823450_rtc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static void tm_divider(struct tm *tm, int divn, int divm)
173173
{
174174
time_t tt;
175175
tt = timegm(tm);
176-
tt = (time_t) ((uint64_t)tt * divn / divm);
176+
tt = tt * divn / divm;
177177
gmtime_r(&tt, tm);
178178
}
179179
#endif /* CONFIG_RTC_DIV */

arch/arm/src/lc823450/lc823450_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ int up_rtc_gettime(struct timespec *tp)
724724

725725
/* And return the result to the caller. */
726726

727-
tp->tv_sec = (time_t)secs;
728-
tp->tv_nsec = (long)nsecs;
727+
tp->tv_sec = secs;
728+
tp->tv_nsec = nsecs;
729729

730730
tmrinfo("Returning tp=(%d,%d)\n", (int)tp->tv_sec, (int)tp->tv_nsec);
731731
return OK;

arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int max326_rdalarm(struct rtc_lowerhalf_s *lower,
581581
{
582582
/* Extract integer seconds from the b32_t value */
583583

584-
time_t sec = (time_t)(b32toi(ftime));
584+
time_t sec = b32toi(ftime);
585585

586586
/* Convert to struct rtc_time (aka struct tm) */
587587

arch/arm/src/sam34/sam4cm_oneshot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ int sam_oneshot_cancel(struct sam_oneshot_s *oneshot,
496496
sec = usec / USEC_PER_SEC;
497497
nsec = ((usec) - (sec * USEC_PER_SEC)) * NSEC_PER_USEC;
498498

499-
ts->tv_sec = (time_t)sec;
500-
ts->tv_nsec = (unsigned long)nsec;
499+
ts->tv_sec = sec;
500+
ts->tv_nsec = nsec;
501501
}
502502

503503
tmrinfo("remaining (%lu, %lu)\n",

arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ static int sam_max_delay(struct oneshot_lowerhalf_s *lower,
152152
uint64_t sec = usecs / 1000000;
153153
usecs -= 1000000 * sec;
154154

155-
ts->tv_sec = (time_t)sec;
156-
ts->tv_nsec = (long)(usecs * 1000);
155+
ts->tv_sec = sec;
156+
ts->tv_nsec = usecs * 1000;
157157
}
158158

159159
return ret;

arch/arm/src/sama5/sam_oneshot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ int sam_oneshot_cancel(struct sam_oneshot_s *oneshot,
507507
sec = usec / USEC_PER_SEC;
508508
nsec = ((usec) - (sec * USEC_PER_SEC)) * NSEC_PER_USEC;
509509

510-
ts->tv_sec = (time_t)sec;
511-
ts->tv_nsec = (unsigned long)nsec;
510+
ts->tv_sec = sec;
511+
ts->tv_nsec = nsec;
512512
}
513513

514514
tmrinfo("remaining (%lu, %lu)\n",

arch/arm/src/sama5/sam_oneshot_lowerhalf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ static int sam_max_delay(struct oneshot_lowerhalf_s *lower,
154154
uint64_t sec = usecs / 1000000;
155155
usecs -= 1000000 * sec;
156156

157-
ts->tv_sec = (time_t)sec;
158-
ts->tv_nsec = (long)(usecs * 1000);
157+
ts->tv_sec = sec;
158+
ts->tv_nsec = usecs * 1000;
159159
}
160160

161161
return ret;

0 commit comments

Comments
 (0)