Skip to content

Commit 0c7e13f

Browse files
newlib: Fix adjtime, returns the amount of time remaining from any previous adjustment
If the olddelta argument is not a null pointer, the adjtime function returns information about any previous time adjustment that has not yet completed. Closes: espressif/esp-idf#5194
1 parent d3a400c commit 0c7e13f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

components/newlib/time.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ static void adjtime_corr_stop (void)
193193
int adjtime(const struct timeval *delta, struct timeval *outdelta)
194194
{
195195
#if defined( WITH_FRC ) || defined( WITH_RTC )
196+
if(outdelta != NULL){
197+
_lock_acquire(&s_adjust_time_lock);
198+
adjust_boot_time();
199+
if (adjtime_start != 0) {
200+
outdelta->tv_sec = adjtime_total_correction / 1000000L;
201+
outdelta->tv_usec = adjtime_total_correction % 1000000L;
202+
} else {
203+
outdelta->tv_sec = 0;
204+
outdelta->tv_usec = 0;
205+
}
206+
_lock_release(&s_adjust_time_lock);
207+
}
196208
if(delta != NULL){
197209
int64_t sec = delta->tv_sec;
198210
int64_t usec = delta->tv_usec;
@@ -211,18 +223,6 @@ int adjtime(const struct timeval *delta, struct timeval *outdelta)
211223
adjtime_total_correction = sec * 1000000L + usec;
212224
_lock_release(&s_adjust_time_lock);
213225
}
214-
if(outdelta != NULL){
215-
_lock_acquire(&s_adjust_time_lock);
216-
adjust_boot_time();
217-
if (adjtime_start != 0) {
218-
outdelta->tv_sec = adjtime_total_correction / 1000000L;
219-
outdelta->tv_usec = adjtime_total_correction % 1000000L;
220-
} else {
221-
outdelta->tv_sec = 0;
222-
outdelta->tv_usec = 0;
223-
}
224-
_lock_release(&s_adjust_time_lock);
225-
}
226226
return 0;
227227
#else
228228
return -1;

0 commit comments

Comments
 (0)