1*472cd20dSToomas Soome //
2*472cd20dSToomas Soome //  posix_utilities.c
3*472cd20dSToomas Soome //  mDNSResponder
4*472cd20dSToomas Soome //
5*472cd20dSToomas Soome //  Copyright (c) 2019 Apple Inc. All rights reserved.
6*472cd20dSToomas Soome //
7*472cd20dSToomas Soome 
8*472cd20dSToomas Soome #include "posix_utilities.h"
9*472cd20dSToomas Soome #include "mDNSEmbeddedAPI.h"
10*472cd20dSToomas Soome #include <stdlib.h>                 // for NULL
11*472cd20dSToomas Soome #include <stdio.h>                  // for snprintf
12*472cd20dSToomas Soome #include <time.h>
13*472cd20dSToomas Soome #include <sys/time.h>               // for gettimeofday
14*472cd20dSToomas Soome 
getLocalTimestamp(char * const buffer,mDNSu32 buffer_len)15*472cd20dSToomas Soome mDNSexport void getLocalTimestamp(char * const buffer, mDNSu32 buffer_len)
16*472cd20dSToomas Soome {
17*472cd20dSToomas Soome     struct timeval      now;
18*472cd20dSToomas Soome     struct tm           local_time;
19*472cd20dSToomas Soome     char                date_time_str[32];
20*472cd20dSToomas Soome     char                time_zone_str[32];
21*472cd20dSToomas Soome 
22*472cd20dSToomas Soome     gettimeofday(&now, NULL);
23*472cd20dSToomas Soome     localtime_r(&now.tv_sec, &local_time);
24*472cd20dSToomas Soome 
25*472cd20dSToomas Soome     strftime(date_time_str, sizeof(date_time_str), "%F %T", &local_time);
26*472cd20dSToomas Soome     strftime(time_zone_str, sizeof(time_zone_str), "%z", &local_time);
27*472cd20dSToomas Soome     snprintf(buffer, buffer_len, "%s.%06lu%s", date_time_str, (unsigned long)now.tv_usec, time_zone_str);
28*472cd20dSToomas Soome }
29