!apps: replace sclock_t with clock_t and drop redundant time_t/off_t casts

Align with the upstream nuttx change that drops the sclock_t alias now
that clock_t is itself a signed 64-bit type (int64_t).  Beyond the pure
sclock_t -> clock_t rename, this commit also removes the
now-unnecessary (time_t)-1 / (time_t)0 / (off_t)-1 casts that were
papering over the previously-unsigned time_t.

Files touched:

  - examples/alarm/alarm_main.c:        sclock_t -> clock_t
  - netutils/dhcpd/dhcpd.c:             sclock_t -> clock_t
  - netutils/ftpd/ftpd.c:               sclock_t -> clock_t
  - netutils/thttpd/libhttpd.c,
    netutils/thttpd/tdate_parse.c:      drop (time_t)-1 / (time_t)0 /
                                        (off_t)-1 sentinel casts
  - system/resmonitor/filldisk.c,
    system/zmodem/zm_receive.c:         sclock_t -> clock_t
  - testing/ostest/wdog.c:              sclock_t -> clock_t (the bulk
                                        of the rename, 30 sites)
  - testing/testsuites/kernel/syscall/cases/{clock_nanosleep_test,
    fsync_test,time_test}.c:            drop (time_t)-1 casts in the
                                        new signed-time_t world

No behavioural change.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2026-05-03 17:17:05 +08:00 committed by Xiang Xiao
parent 72837c8d26
commit a6477ec8dc
11 changed files with 33 additions and 33 deletions

View file

@ -393,7 +393,7 @@ int main(int argc, FAR char *argv[])
setrel.id = alarmid; setrel.id = alarmid;
setrel.pid = g_alarm_daemon_pid; setrel.pid = g_alarm_daemon_pid;
setrel.reltime = (time_t)seconds; setrel.reltime = seconds;
setrel.event.sigev_notify = SIGEV_SIGNAL; setrel.event.sigev_notify = SIGEV_SIGNAL;
setrel.event.sigev_signo = CONFIG_EXAMPLES_ALARM_SIGNO; setrel.event.sigev_signo = CONFIG_EXAMPLES_ALARM_SIGNO;

View file

@ -661,7 +661,7 @@ static inline bool dhcpd_parseoptions(void)
if (optlen >= 6 && optlen < remaining) if (optlen >= 6 && optlen < remaining)
{ {
memcpy(&tmp, &ptr[DHCPD_OPTION_DATA], 4); memcpy(&tmp, &ptr[DHCPD_OPTION_DATA], 4);
g_state.ds_optleasetime = (time_t)ntohl(tmp); g_state.ds_optleasetime = ntohl(tmp);
} }
break; break;

View file

@ -2305,11 +2305,11 @@ static int ftpd_listbuffer(FAR struct ftpd_session_s *session,
/* time */ /* time */
memcpy(&tm, localtime((FAR const time_t *)&st->st_mtime), sizeof(tm)); memcpy(&tm, localtime(&st->st_mtime), sizeof(tm));
offset += snprintf(&buffer[offset], buflen - offset, " %s %2u", offset += snprintf(&buffer[offset], buflen - offset, " %s %2u",
g_monthtab[tm.tm_mon], tm.tm_mday); g_monthtab[tm.tm_mon], tm.tm_mday);
now = time(0); now = time(0);
if ((now - st->st_mtime) > (time_t)(60 * 60 * 24 * 180)) if (now - st->st_mtime > 60 * 60 * 24 * 180)
{ {
offset += snprintf(&buffer[offset], buflen - offset, " %5u", offset += snprintf(&buffer[offset], buflen - offset, " %5u",
tm.tm_year + 1900); tm.tm_year + 1900);

View file

@ -327,7 +327,7 @@ static void send_mime(httpd_conn *hc, int status, const char *title,
(hc->range_end >= hc->range_start) && (hc->range_end >= hc->range_start) &&
((hc->range_end != length - 1) || ((hc->range_end != length - 1) ||
(hc->range_start != 0)) && (hc->range_start != 0)) &&
(hc->range_if == (time_t) - 1 || hc->range_if == hc->sb.st_mtime)) (hc->range_if == -1 || hc->range_if == hc->sb.st_mtime))
{ {
partial_content = 1; partial_content = 1;
status = 206; status = 206;
@ -340,7 +340,7 @@ static void send_mime(httpd_conn *hc, int status, const char *title,
} }
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (mod == (time_t)0) if (mod == 0)
{ {
mod = now.tv_sec; mod = now.tv_sec;
} }
@ -510,7 +510,7 @@ static int send_err_file(httpd_conn *hc, int status, char *title,
} }
send_mime(hc, status, title, "", extraheads, "text/html; charset=%s", send_mime(hc, status, title, "", extraheads, "text/html; charset=%s",
(off_t)-1, (time_t)0); -1, 0);
for (; ; ) for (; ; )
{ {
nread = fread(buf, 1, sizeof(buf) - 1, fp); nread = fread(buf, 1, sizeof(buf) - 1, fp);
@ -2421,8 +2421,8 @@ int httpd_get_conn(httpd_server *hs, int listen_fd, httpd_conn *hc)
hc->altdir[0] = '\0'; hc->altdir[0] = '\0';
#endif #endif
hc->buflen = 0; hc->buflen = 0;
hc->if_modified_since = (time_t) - 1; hc->if_modified_since = -1;
hc->range_if = (time_t)-1; hc->range_if = -1;
hc->contentlength = -1; hc->contentlength = -1;
hc->type = ""; hc->type = "";
#ifdef CONFIG_THTTPD_VHOST #ifdef CONFIG_THTTPD_VHOST
@ -2926,7 +2926,7 @@ int httpd_parse_request(httpd_conn *hc)
{ {
cp = &buf[18]; cp = &buf[18];
hc->if_modified_since = tdate_parse(cp); hc->if_modified_since = tdate_parse(cp);
if (hc->if_modified_since == (time_t) - 1) if (hc->if_modified_since == -1)
{ {
nerr("ERROR: unparsable time: %s\n", cp); nerr("ERROR: unparsable time: %s\n", cp);
} }
@ -2973,7 +2973,7 @@ int httpd_parse_request(httpd_conn *hc)
{ {
cp = &buf[9]; cp = &buf[9];
hc->range_if = tdate_parse(cp); hc->range_if = tdate_parse(cp);
if (hc->range_if == (time_t) - 1) if (hc->range_if == -1)
{ {
nerr("ERROR: unparsable time: %s\n", cp); nerr("ERROR: unparsable time: %s\n", cp);
} }
@ -3521,7 +3521,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowp)
send_mime(hc, 200, ok200title, hc->encodings, "", hc->type, send_mime(hc, 200, ok200title, hc->encodings, "", hc->type,
hc->sb.st_size, hc->sb.st_mtime); hc->sb.st_size, hc->sb.st_mtime);
} }
else if (hc->if_modified_since != (time_t) - 1 && else if (hc->if_modified_since != -1 &&
hc->if_modified_since >= hc->sb.st_mtime) hc->if_modified_since >= hc->sb.st_mtime)
{ {
send_mime(hc, 304, err304title, hc->encodings, "", send_mime(hc, 304, err304title, hc->encodings, "",

View file

@ -348,7 +348,7 @@ time_t tdate_parse(char *str)
#endif /* Day of week not yet supported by NuttX */ #endif /* Day of week not yet supported by NuttX */
else else
{ {
return (time_t) - 1; return -1;
} }
if (tm.tm_year > 1900) if (tm.tm_year > 1900)

View file

@ -304,7 +304,7 @@ int main(int argc, FAR char *argv[])
mode = 1; mode = 1;
break; break;
case 'i': case 'i':
interval = (time_t)bytes(optarg); interval = bytes(optarg);
break; break;
case 'b': case 'b':
bufsize = bytes(optarg); bufsize = bytes(optarg);

View file

@ -675,7 +675,7 @@ static int zmr_filename(FAR struct zm_state_s *pzm)
pzmr->filesize = (off_t)filesize; pzmr->filesize = (off_t)filesize;
#ifdef CONFIG_SYSTEM_ZMODEM_TIMESTAMPS #ifdef CONFIG_SYSTEM_ZMODEM_TIMESTAMPS
pzmr->timestamp = (time_t)timestamp; pzmr->timestamp = timestamp;
#endif #endif
/* Check if we need to send the CRC */ /* Check if we need to send the CRC */

View file

@ -56,7 +56,7 @@
typedef struct wdtest_param_s typedef struct wdtest_param_s
{ {
FAR struct wdog_s *wdog; FAR struct wdog_s *wdog;
sclock_t interval; clock_t interval;
uint64_t callback_cnt; uint64_t callback_cnt;
clock_t triggered_tick; clock_t triggered_tick;
} wdtest_param_t; } wdtest_param_t;
@ -79,7 +79,7 @@ static void wdtest_callback(wdparm_t param)
wdtest_param->callback_cnt += 1; wdtest_param->callback_cnt += 1;
} }
static void wdtest_checkdelay(sclock_t diff, sclock_t delay_tick) static void wdtest_checkdelay(clock_t diff, clock_t delay_tick)
{ {
/* Ensure the watchdog trigger time is not earlier than expected. */ /* Ensure the watchdog trigger time is not earlier than expected. */
@ -97,13 +97,13 @@ static void wdtest_checkdelay(sclock_t diff, sclock_t delay_tick)
} }
static void wdtest_once(FAR struct wdog_s *wdog, FAR wdtest_param_t *param, static void wdtest_once(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
sclock_t delay_ns) clock_t delay_ns)
{ {
uint64_t cnt; uint64_t cnt;
sclock_t diff; clock_t diff;
clock_t wdset_tick; clock_t wdset_tick;
irqstate_t flags; irqstate_t flags;
sclock_t delay_tick = (sclock_t)NSEC2TICK((clock_t)delay_ns); clock_t delay_tick = NSEC2TICK(delay_ns);
wdtest_printf("wdtest_once %lld ns\n", (long long)delay_ns); wdtest_printf("wdtest_once %lld ns\n", (long long)delay_ns);
@ -133,20 +133,20 @@ static void wdtest_once(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
/* Check if the delay is within the acceptable tolerance. */ /* Check if the delay is within the acceptable tolerance. */
diff = (sclock_t)(param->triggered_tick - wdset_tick); diff = param->triggered_tick - wdset_tick;
wdtest_checkdelay(diff, delay_tick); wdtest_checkdelay(diff, delay_tick);
} }
static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param, static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
sclock_t rand_ns) clock_t rand_ns)
{ {
uint64_t cnt; uint64_t cnt;
int idx; int idx;
sclock_t delay_ns; clock_t delay_ns;
clock_t wdset_tick; clock_t wdset_tick;
sclock_t delay_tick; clock_t delay_tick;
sclock_t diff; clock_t diff;
irqstate_t flags = 0; irqstate_t flags = 0;
/* Perform multiple iterations with random delays. */ /* Perform multiple iterations with random delays. */
@ -190,7 +190,7 @@ static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
if (cnt % 2) if (cnt % 2)
{ {
diff = (sclock_t)(param->triggered_tick - wdset_tick); diff = param->triggered_tick - wdset_tick;
wdtest_checkdelay(diff, delay_tick); wdtest_checkdelay(diff, delay_tick);
} }
} }
@ -204,7 +204,7 @@ static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
static void wdtest_callback_recursive(wdparm_t param) static void wdtest_callback_recursive(wdparm_t param)
{ {
FAR wdtest_param_t *wdtest_param = (FAR wdtest_param_t *)param; FAR wdtest_param_t *wdtest_param = (FAR wdtest_param_t *)param;
sclock_t interval = wdtest_param->interval; clock_t interval = wdtest_param->interval;
wdtest_param->callback_cnt += 1; wdtest_param->callback_cnt += 1;
wdtest_param->triggered_tick = clock_systime_ticks(); wdtest_param->triggered_tick = clock_systime_ticks();
@ -215,7 +215,7 @@ static void wdtest_callback_recursive(wdparm_t param)
static void wdtest_recursive(FAR struct wdog_s *wdog, static void wdtest_recursive(FAR struct wdog_s *wdog,
FAR wdtest_param_t *param, FAR wdtest_param_t *param,
sclock_t delay_ns, clock_t delay_ns,
unsigned int times) unsigned int times)
{ {
uint64_t cnt; uint64_t cnt;
@ -227,7 +227,7 @@ static void wdtest_recursive(FAR struct wdog_s *wdog,
cnt = param->callback_cnt; cnt = param->callback_cnt;
param->wdog = wdog; param->wdog = wdog;
param->interval = (sclock_t)NSEC2TICK((clock_t)delay_ns); param->interval = NSEC2TICK(delay_ns);
wdtest_assert(param->interval >= 0); wdtest_assert(param->interval >= 0);
@ -253,7 +253,7 @@ static void wdtest_recursive(FAR struct wdog_s *wdog,
static void wdog_test_run(FAR wdtest_param_t *param) static void wdog_test_run(FAR wdtest_param_t *param)
{ {
uint64_t cnt; uint64_t cnt;
sclock_t rest; clock_t rest;
clock_t delay; clock_t delay;
struct wdog_s test_wdog = struct wdog_s test_wdog =
{ {

View file

@ -55,7 +55,7 @@ void test_nuttx_syscall_clocknanosleep01(FAR void **state)
ret = clock_nanosleep(type, 0, &t, NULL); ret = clock_nanosleep(type, 0, &t, NULL);
assert_int_equal(ret, 0); assert_int_equal(ret, 0);
end_time = clock(); end_time = clock();
assert_int_equal((time_t)(end_time - start_time) / CLOCKS_PER_SEC, assert_int_equal((end_time - start_time) / CLOCKS_PER_SEC,
t.tv_sec); t.tv_sec);
} }

View file

@ -238,7 +238,7 @@ void test_nuttx_syscall_fsync03(FAR void **state)
ret = fsync(fd); ret = fsync(fd);
time_end = time(0); time_end = time(0);
assert_true(time_end != (time_t)-1); assert_true(time_end != -1);
assert_int_not_equal(ret, -1); assert_int_not_equal(ret, -1);
assert_int_equal(ret, 0); assert_int_equal(ret, 0);
assert_false(time_end < time_start); assert_false(time_end < time_start);

View file

@ -57,7 +57,7 @@ void test_nuttx_syscall_time01(FAR void **state)
/* check return code */ /* check return code */
assert_int_not_equal(ret, (time_t)-1); assert_int_not_equal(ret, -1);
} }
} }