mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
Introduce virTimeMs for getting current time in ms
This commit is contained in:
parent
af2abe3f19
commit
ef6e99dc24
@ -1025,6 +1025,7 @@ virStrToLong_ul;
|
||||
virStrToLong_ull;
|
||||
virStrcpy;
|
||||
virStrncpy;
|
||||
virTimeMs;
|
||||
virTimestamp;
|
||||
virVasprintf;
|
||||
|
||||
|
@ -2471,6 +2471,30 @@ virTimestamp(void)
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
#define timeval_to_ms(tv) (((tv).tv_sec * 1000ull) + ((tv).tv_usec / 1000))
|
||||
|
||||
/**
|
||||
* virTimeMs:
|
||||
*
|
||||
* Get current time in milliseconds.
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
virTimeMs(unsigned long long *ms)
|
||||
{
|
||||
struct timeval now;
|
||||
|
||||
if (gettimeofday(&now, NULL) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
_("cannot get time of day"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
*ms = timeval_to_ms(now);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if HAVE_LIBDEVMAPPER_H
|
||||
bool
|
||||
virIsDevMapperDevice(const char *devname)
|
||||
|
@ -254,6 +254,8 @@ int virBuildPathInternal(char **path, ...) ATTRIBUTE_SENTINEL;
|
||||
|
||||
char *virTimestamp(void);
|
||||
|
||||
int virTimeMs(unsigned long long *ms) ATTRIBUTE_NONNULL(1);
|
||||
|
||||
bool virIsDevMapperDevice(const char *devname) ATTRIBUTE_NONNULL(1);
|
||||
|
||||
int virEmitXMLWarning(int fd,
|
||||
|
Loading…
Reference in New Issue
Block a user