8d11602f3e6db8bb0706c8b18fda238e89b5cefb
[fw/openocd] / src / helper / time_support_common.c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /***************************************************************************
4  *   Copyright (C) 2006 by Dominic Rath                                    *
5  *   Dominic.Rath@gmx.de                                                   *
6  *                                                                         *
7  *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                 *
8  *   oyvind.harboe@zylin.com                                               *
9  *                                                                         *
10  *   Copyright (C) 2008 by Spencer Oliver                                  *
11  *   spen@spen-soft.co.uk                                                  *
12  ***************************************************************************/
13
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17
18 #include "time_support.h"
19
20 /* simple and low overhead fetching of ms counter. Use only
21  * the difference between ms counters returned from this fn.
22  */
23 int64_t timeval_ms(void)
24 {
25         struct timeval now;
26         int retval = gettimeofday(&now, NULL);
27         if (retval < 0)
28                 return retval;
29         return (int64_t)now.tv_sec * 1000 + now.tv_usec / 1000;
30 }