Skip to content

Commit 677d340

Browse files
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>
1 parent c8c21b9 commit 677d340

11 files changed

Lines changed: 33 additions & 33 deletions

File tree

examples/alarm/alarm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ int main(int argc, FAR char *argv[])
393393

394394
setrel.id = alarmid;
395395
setrel.pid = g_alarm_daemon_pid;
396-
setrel.reltime = (time_t)seconds;
396+
setrel.reltime = seconds;
397397

398398
setrel.event.sigev_notify = SIGEV_SIGNAL;
399399
setrel.event.sigev_signo = CONFIG_EXAMPLES_ALARM_SIGNO;

netutils/dhcpd/dhcpd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ static inline bool dhcpd_parseoptions(void)
661661
if (optlen >= 6 && optlen < remaining)
662662
{
663663
memcpy(&tmp, &ptr[DHCPD_OPTION_DATA], 4);
664-
g_state.ds_optleasetime = (time_t)ntohl(tmp);
664+
g_state.ds_optleasetime = ntohl(tmp);
665665
}
666666
break;
667667

netutils/ftpd/ftpd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,11 +2305,11 @@ static int ftpd_listbuffer(FAR struct ftpd_session_s *session,
23052305

23062306
/* time */
23072307

2308-
memcpy(&tm, localtime((FAR const time_t *)&st->st_mtime), sizeof(tm));
2308+
memcpy(&tm, localtime(&st->st_mtime), sizeof(tm));
23092309
offset += snprintf(&buffer[offset], buflen - offset, " %s %2u",
23102310
g_monthtab[tm.tm_mon], tm.tm_mday);
23112311
now = time(0);
2312-
if ((now - st->st_mtime) > (time_t)(60 * 60 * 24 * 180))
2312+
if (now - st->st_mtime > 60 * 60 * 24 * 180)
23132313
{
23142314
offset += snprintf(&buffer[offset], buflen - offset, " %5u",
23152315
tm.tm_year + 1900);

netutils/thttpd/libhttpd.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static void send_mime(httpd_conn *hc, int status, const char *title,
327327
(hc->range_end >= hc->range_start) &&
328328
((hc->range_end != length - 1) ||
329329
(hc->range_start != 0)) &&
330-
(hc->range_if == (time_t) - 1 || hc->range_if == hc->sb.st_mtime))
330+
(hc->range_if == -1 || hc->range_if == hc->sb.st_mtime))
331331
{
332332
partial_content = 1;
333333
status = 206;
@@ -340,7 +340,7 @@ static void send_mime(httpd_conn *hc, int status, const char *title,
340340
}
341341

342342
gettimeofday(&now, NULL);
343-
if (mod == (time_t)0)
343+
if (mod == 0)
344344
{
345345
mod = now.tv_sec;
346346
}
@@ -510,7 +510,7 @@ static int send_err_file(httpd_conn *hc, int status, char *title,
510510
}
511511

512512
send_mime(hc, status, title, "", extraheads, "text/html; charset=%s",
513-
(off_t)-1, (time_t)0);
513+
-1, 0);
514514
for (; ; )
515515
{
516516
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)
24212421
hc->altdir[0] = '\0';
24222422
#endif
24232423
hc->buflen = 0;
2424-
hc->if_modified_since = (time_t) - 1;
2425-
hc->range_if = (time_t)-1;
2424+
hc->if_modified_since = -1;
2425+
hc->range_if = -1;
24262426
hc->contentlength = -1;
24272427
hc->type = "";
24282428
#ifdef CONFIG_THTTPD_VHOST
@@ -2926,7 +2926,7 @@ int httpd_parse_request(httpd_conn *hc)
29262926
{
29272927
cp = &buf[18];
29282928
hc->if_modified_since = tdate_parse(cp);
2929-
if (hc->if_modified_since == (time_t) - 1)
2929+
if (hc->if_modified_since == -1)
29302930
{
29312931
nerr("ERROR: unparsable time: %s\n", cp);
29322932
}
@@ -2973,7 +2973,7 @@ int httpd_parse_request(httpd_conn *hc)
29732973
{
29742974
cp = &buf[9];
29752975
hc->range_if = tdate_parse(cp);
2976-
if (hc->range_if == (time_t) - 1)
2976+
if (hc->range_if == -1)
29772977
{
29782978
nerr("ERROR: unparsable time: %s\n", cp);
29792979
}
@@ -3521,7 +3521,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowp)
35213521
send_mime(hc, 200, ok200title, hc->encodings, "", hc->type,
35223522
hc->sb.st_size, hc->sb.st_mtime);
35233523
}
3524-
else if (hc->if_modified_since != (time_t) - 1 &&
3524+
else if (hc->if_modified_since != -1 &&
35253525
hc->if_modified_since >= hc->sb.st_mtime)
35263526
{
35273527
send_mime(hc, 304, err304title, hc->encodings, "",

netutils/thttpd/tdate_parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ time_t tdate_parse(char *str)
348348
#endif /* Day of week not yet supported by NuttX */
349349
else
350350
{
351-
return (time_t) - 1;
351+
return -1;
352352
}
353353

354354
if (tm.tm_year > 1900)

system/resmonitor/filldisk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ int main(int argc, FAR char *argv[])
304304
mode = 1;
305305
break;
306306
case 'i':
307-
interval = (time_t)bytes(optarg);
307+
interval = bytes(optarg);
308308
break;
309309
case 'b':
310310
bufsize = bytes(optarg);

system/zmodem/zm_receive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ static int zmr_filename(FAR struct zm_state_s *pzm)
675675

676676
pzmr->filesize = (off_t)filesize;
677677
#ifdef CONFIG_SYSTEM_ZMODEM_TIMESTAMPS
678-
pzmr->timestamp = (time_t)timestamp;
678+
pzmr->timestamp = timestamp;
679679
#endif
680680

681681
/* Check if we need to send the CRC */

testing/ostest/wdog.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
typedef struct wdtest_param_s
5757
{
5858
FAR struct wdog_s *wdog;
59-
sclock_t interval;
59+
clock_t interval;
6060
uint64_t callback_cnt;
6161
clock_t triggered_tick;
6262
} wdtest_param_t;
@@ -79,7 +79,7 @@ static void wdtest_callback(wdparm_t param)
7979
wdtest_param->callback_cnt += 1;
8080
}
8181

82-
static void wdtest_checkdelay(sclock_t diff, sclock_t delay_tick)
82+
static void wdtest_checkdelay(clock_t diff, clock_t delay_tick)
8383
{
8484
/* Ensure the watchdog trigger time is not earlier than expected. */
8585

@@ -97,13 +97,13 @@ static void wdtest_checkdelay(sclock_t diff, sclock_t delay_tick)
9797
}
9898

9999
static void wdtest_once(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
100-
sclock_t delay_ns)
100+
clock_t delay_ns)
101101
{
102102
uint64_t cnt;
103-
sclock_t diff;
103+
clock_t diff;
104104
clock_t wdset_tick;
105105
irqstate_t flags;
106-
sclock_t delay_tick = (sclock_t)NSEC2TICK((clock_t)delay_ns);
106+
clock_t delay_tick = NSEC2TICK(delay_ns);
107107

108108
wdtest_printf("wdtest_once %lld ns\n", (long long)delay_ns);
109109

@@ -133,20 +133,20 @@ static void wdtest_once(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
133133

134134
/* Check if the delay is within the acceptable tolerance. */
135135

136-
diff = (sclock_t)(param->triggered_tick - wdset_tick);
136+
diff = param->triggered_tick - wdset_tick;
137137

138138
wdtest_checkdelay(diff, delay_tick);
139139
}
140140

141141
static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
142-
sclock_t rand_ns)
142+
clock_t rand_ns)
143143
{
144144
uint64_t cnt;
145145
int idx;
146-
sclock_t delay_ns;
146+
clock_t delay_ns;
147147
clock_t wdset_tick;
148-
sclock_t delay_tick;
149-
sclock_t diff;
148+
clock_t delay_tick;
149+
clock_t diff;
150150
irqstate_t flags = 0;
151151

152152
/* Perform multiple iterations with random delays. */
@@ -190,7 +190,7 @@ static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
190190

191191
if (cnt % 2)
192192
{
193-
diff = (sclock_t)(param->triggered_tick - wdset_tick);
193+
diff = param->triggered_tick - wdset_tick;
194194
wdtest_checkdelay(diff, delay_tick);
195195
}
196196
}
@@ -204,7 +204,7 @@ static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
204204
static void wdtest_callback_recursive(wdparm_t param)
205205
{
206206
FAR wdtest_param_t *wdtest_param = (FAR wdtest_param_t *)param;
207-
sclock_t interval = wdtest_param->interval;
207+
clock_t interval = wdtest_param->interval;
208208

209209
wdtest_param->callback_cnt += 1;
210210
wdtest_param->triggered_tick = clock_systime_ticks();
@@ -215,7 +215,7 @@ static void wdtest_callback_recursive(wdparm_t param)
215215

216216
static void wdtest_recursive(FAR struct wdog_s *wdog,
217217
FAR wdtest_param_t *param,
218-
sclock_t delay_ns,
218+
clock_t delay_ns,
219219
unsigned int times)
220220
{
221221
uint64_t cnt;
@@ -227,7 +227,7 @@ static void wdtest_recursive(FAR struct wdog_s *wdog,
227227
cnt = param->callback_cnt;
228228

229229
param->wdog = wdog;
230-
param->interval = (sclock_t)NSEC2TICK((clock_t)delay_ns);
230+
param->interval = NSEC2TICK(delay_ns);
231231

232232
wdtest_assert(param->interval >= 0);
233233

@@ -253,7 +253,7 @@ static void wdtest_recursive(FAR struct wdog_s *wdog,
253253
static void wdog_test_run(FAR wdtest_param_t *param)
254254
{
255255
uint64_t cnt;
256-
sclock_t rest;
256+
clock_t rest;
257257
clock_t delay;
258258
struct wdog_s test_wdog =
259259
{

testing/testsuites/kernel/syscall/cases/clock_nanosleep_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void test_nuttx_syscall_clocknanosleep01(FAR void **state)
5555
ret = clock_nanosleep(type, 0, &t, NULL);
5656
assert_int_equal(ret, 0);
5757
end_time = clock();
58-
assert_int_equal((time_t)(end_time - start_time) / CLOCKS_PER_SEC,
58+
assert_int_equal((end_time - start_time) / CLOCKS_PER_SEC,
5959
t.tv_sec);
6060
}
6161

testing/testsuites/kernel/syscall/cases/fsync_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void test_nuttx_syscall_fsync03(FAR void **state)
238238
ret = fsync(fd);
239239

240240
time_end = time(0);
241-
assert_true(time_end != (time_t)-1);
241+
assert_true(time_end != -1);
242242
assert_int_not_equal(ret, -1);
243243
assert_int_equal(ret, 0);
244244
assert_false(time_end < time_start);

0 commit comments

Comments
 (0)