Introduce virTimeMs for getting current time in ms

This commit is contained in:
Jiri Denemark 2011-06-01 11:38:56 +02:00
parent af2abe3f19
commit ef6e99dc24
3 changed files with 27 additions and 0 deletions

View File

@ -1025,6 +1025,7 @@ virStrToLong_ul;
virStrToLong_ull;
virStrcpy;
virStrncpy;
virTimeMs;
virTimestamp;
virVasprintf;

View File

@ -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)

View File

@ -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,