mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
lib: Create time_basic.[ch]
Make the two functions that debug.c needs a subsystem of their own. The goal is to put debug.c on a diet. Anybody who wants to use it should not be forced to pull in half of Samba :-) Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
parent
8799120abd
commit
0753c1bec1
@ -22,7 +22,7 @@
|
||||
#include "includes.h"
|
||||
#include "system/filesys.h"
|
||||
#include "system/syslog.h"
|
||||
#include "lib/util/time.h"
|
||||
#include "lib/util/time_basic.h"
|
||||
|
||||
/* define what facility to use for syslog */
|
||||
#ifndef SYSLOG_FACILITY
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "includes.h"
|
||||
#include "system/time.h"
|
||||
#include "lib/util/time_basic.h"
|
||||
|
||||
/**
|
||||
* @file
|
||||
@ -45,18 +46,6 @@ _PUBLIC_ time_t get_time_t_max(void)
|
||||
return TIME_T_MAX;
|
||||
}
|
||||
|
||||
/**
|
||||
a gettimeofday wrapper
|
||||
**/
|
||||
_PUBLIC_ void GetTimeOfDay(struct timeval *tval)
|
||||
{
|
||||
#ifdef HAVE_GETTIMEOFDAY_TZ
|
||||
gettimeofday(tval,NULL);
|
||||
#else
|
||||
gettimeofday(tval);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
a wrapper to preferably get the monotonic time
|
||||
**/
|
||||
@ -341,46 +330,6 @@ _PUBLIC_ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset)
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
char *timeval_str_buf(const struct timeval *tp, bool hires,
|
||||
struct timeval_buf *dst)
|
||||
{
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
size_t len;
|
||||
|
||||
t = (time_t)tp->tv_sec;
|
||||
tm = localtime(&t);
|
||||
|
||||
if (tm == NULL) {
|
||||
if (hires) {
|
||||
snprintf(dst->buf, sizeof(dst->buf),
|
||||
"%ld.%06ld seconds since the Epoch",
|
||||
(long)tp->tv_sec, (long)tp->tv_usec);
|
||||
} else {
|
||||
snprintf(dst->buf, sizeof(dst->buf),
|
||||
"%ld seconds since the Epoch", (long)t);
|
||||
}
|
||||
return dst->buf;
|
||||
}
|
||||
|
||||
#ifdef HAVE_STRFTIME
|
||||
len = strftime(dst->buf, sizeof(dst->buf), "%Y/%m/%d %H:%M:%S", tm);
|
||||
#else
|
||||
{
|
||||
const char *asct = asctime(tm);
|
||||
len = strlcpy(dst->buf, sizeof(dst->buf),
|
||||
asct ? asct : "unknown");
|
||||
}
|
||||
#endif
|
||||
if (hires && (len < sizeof(dst->buf))) {
|
||||
snprintf(dst->buf + len, sizeof(dst->buf) - len,
|
||||
".%06ld", (long)tp->tv_usec);
|
||||
}
|
||||
|
||||
return dst->buf;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Return the date and time as a string
|
||||
****************************************************************************/
|
||||
|
@ -119,18 +119,6 @@ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset);
|
||||
**/
|
||||
time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset);
|
||||
|
||||
struct timeval_buf { char buf[128]; };
|
||||
|
||||
/**
|
||||
Put a date and time into dst->buf, return it dst->buf
|
||||
(optionally with microseconds)
|
||||
|
||||
format is %Y/%m/%d %H:%M:%S if strftime is available
|
||||
**/
|
||||
|
||||
char *timeval_str_buf(const struct timeval *tp, bool hires,
|
||||
struct timeval_buf *dst);
|
||||
|
||||
/**
|
||||
Return a date and time as a string (optionally with microseconds)
|
||||
|
||||
|
80
lib/util/time_basic.c
Normal file
80
lib/util/time_basic.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Unix SMB/CIFS implementation.
|
||||
* time handling functions
|
||||
*
|
||||
* Copyright (C) Andrew Tridgell 1992-2004
|
||||
* Copyright (C) Stefan (metze) Metzmacher 2002
|
||||
* Copyright (C) Jeremy Allison 2007
|
||||
* Copyright (C) Andrew Bartlett 2011
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
#include "lib/util/time_basic.h"
|
||||
|
||||
/**
|
||||
a gettimeofday wrapper
|
||||
**/
|
||||
_PUBLIC_ void GetTimeOfDay(struct timeval *tval)
|
||||
{
|
||||
#ifdef HAVE_GETTIMEOFDAY_TZ
|
||||
gettimeofday(tval,NULL);
|
||||
#else
|
||||
gettimeofday(tval);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Return the date and time as a string
|
||||
****************************************************************************/
|
||||
|
||||
char *timeval_str_buf(const struct timeval *tp, bool hires,
|
||||
struct timeval_buf *dst)
|
||||
{
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
size_t len;
|
||||
|
||||
t = (time_t)tp->tv_sec;
|
||||
tm = localtime(&t);
|
||||
|
||||
if (tm == NULL) {
|
||||
if (hires) {
|
||||
snprintf(dst->buf, sizeof(dst->buf),
|
||||
"%ld.%06ld seconds since the Epoch",
|
||||
(long)tp->tv_sec, (long)tp->tv_usec);
|
||||
} else {
|
||||
snprintf(dst->buf, sizeof(dst->buf),
|
||||
"%ld seconds since the Epoch", (long)t);
|
||||
}
|
||||
return dst->buf;
|
||||
}
|
||||
|
||||
#ifdef HAVE_STRFTIME
|
||||
len = strftime(dst->buf, sizeof(dst->buf), "%Y/%m/%d %H:%M:%S", tm);
|
||||
#else
|
||||
{
|
||||
const char *asct = asctime(tm);
|
||||
len = strlcpy(dst->buf, sizeof(dst->buf),
|
||||
asct ? asct : "unknown");
|
||||
}
|
||||
#endif
|
||||
if (hires && (len < sizeof(dst->buf))) {
|
||||
snprintf(dst->buf + len, sizeof(dst->buf) - len,
|
||||
".%06ld", (long)tp->tv_usec);
|
||||
}
|
||||
|
||||
return dst->buf;
|
||||
}
|
42
lib/util/time_basic.h
Normal file
42
lib/util/time_basic.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Unix SMB/CIFS implementation.
|
||||
* time handling functions
|
||||
*
|
||||
* Copyright (C) Andrew Tridgell 1992-2004
|
||||
* Copyright (C) Stefan (metze) Metzmacher 2002
|
||||
* Copyright (C) Jeremy Allison 2007
|
||||
* Copyright (C) Andrew Bartlett 2011
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
#include "system/time.h"
|
||||
|
||||
/**
|
||||
a gettimeofday wrapper
|
||||
**/
|
||||
_PUBLIC_ void GetTimeOfDay(struct timeval *tval);
|
||||
|
||||
struct timeval_buf { char buf[128]; };
|
||||
|
||||
/**
|
||||
Put a date and time into dst->buf, return it dst->buf
|
||||
(optionally with microseconds)
|
||||
|
||||
format is %Y/%m/%d %H:%M:%S if strftime is available
|
||||
**/
|
||||
|
||||
char *timeval_str_buf(const struct timeval *tp, bool hires,
|
||||
struct timeval_buf *dst);
|
@ -1,5 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
bld.SAMBA_SUBSYSTEM('time-basic',
|
||||
source='time_basic.c',
|
||||
deps='replace',
|
||||
local_include=False)
|
||||
|
||||
bld.SAMBA_LIBRARY('samba-util',
|
||||
source='''talloc_stack.c smb_threads.c xfile.c data_blob.c
|
||||
util_file.c time.c rbtree.c rfc1738.c select.c getpass.c
|
||||
@ -9,7 +14,7 @@ bld.SAMBA_LIBRARY('samba-util',
|
||||
util_str.c util_str_common.c substitute.c ms_fnmatch.c
|
||||
server_id.c dprintf.c parmlist.c bitmap.c pidfile.c
|
||||
tevent_debug.c util_process.c memcache.c''',
|
||||
deps='DYNCONFIG',
|
||||
deps='DYNCONFIG time-basic',
|
||||
public_deps='talloc tevent execinfo pthread LIBCRYPTO charset util_setid systemd-daemon',
|
||||
public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h samba_util.h string_wrappers.h',
|
||||
header_path= [ ('dlinklist.h samba_util.h', '.'), ('*', 'util') ],
|
||||
|
Loading…
Reference in New Issue
Block a user