Migration Time APIs from Linux to Visual Studio 2008

I have an application that I port to Microsoft Visual Studio 2008 that works fine and works on Linux.

I'm having problems with time programs, my Linux code is as follows:

#include <sys/types.h> #include <sys/time.h> typedef long long Usec; inline Usec timevalToUsec(const timeval &tv) { return (((Usec) tv.tv_sec) * 1000000) + ((Usec) tv.tv_usec); } 

But the compiler does not work in the sys/time.h header file:

 fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory 

If I change the include to just time.h , I get another error with an undefined timeval:

 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 

This is because timeval is undefined.

Includes time.h instead of sys/time.h correctly, and if so, where can I get the definition of struct timeval in Microsoft Visual Studio 2008?

+4
source share
2 answers

Filling out the winsock2.h header will result in a struct timeval since it is used in calls of type select .

+5
source

It exists, but not in "sys / time.h". Interestingly, Timeval, Winsock2.h.

+3
source

Source: https://habr.com/ru/post/1383502/


All Articles