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