NO

Author Topic: sys/time.h not found  (Read 6170 times)

sp1541

  • Guest
sys/time.h not found
« on: January 12, 2011, 05:41:02 PM »
Hi there!
I want to compile a simple program which was written for unix in windows.
In Pelles C 6.50.4 RC3 the instruction _gettimeofday() is implemented.
I need "#include <sys/time.h>" to use that and the structs timeval and timezone.
This file does not exist. I tried to use "timeb.h" or copy it from gcc.
In the end I only need a solution to get a precise time on windows.
Any ideas?

Sorry for my english...

CommonTater

  • Guest
Re: sys/time.h not found
« Reply #1 on: January 12, 2011, 06:17:43 PM »
Try it with just #include <time.h>  

In PellesC the time.h file is in the include directory on your search path.

If you installed on defaults, look in the c:\program files\pellesc\include folder.
« Last Edit: January 12, 2011, 06:19:16 PM by CommonTater »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: sys/time.h not found
« Reply #2 on: January 12, 2011, 08:42:35 PM »
For PellesC 6.5 only.
Code: [Select]
#include <stdio.h>
//#include <sys/time.h>

typedef struct timeval {
    long tv_sec;
    long tv_usec;
};

int gettimeofday(struct timeval *tv, struct timezone *tz);

int main(int argc, char **argv)
{
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
gettimeofday(&tv, NULL);
if (tv.tv_sec)
printf("%d\n", (long)tv.tv_sec);
return 0;
}

You can test sys/time.h like this
Code: [Select]
#ifndef _SYS_TIME_H
#define _SYS_TIME_H
typedef struct timeval {
    long tv_sec;
    long tv_usec;
};

int gettimeofday(struct timeval *tv, struct timezone *tz);
#endif /* _SYS_TIME_H */
This is not used.
Code: [Select]
typedef struct timezone {
    int tz_minuteswest;
    int tz_dsttime;
};
« Last Edit: January 13, 2011, 03:42:08 PM by timovjl »
May the source be with you

sp1541

  • Guest
Re: sys/time.h not found
« Reply #3 on: January 13, 2011, 03:14:07 PM »
thank you!

@CommonTater:
time.h was already included

@timovjl:
Your solution will work with my code, I think.
I got only an error because struct timezone isn't defined but I think I will find how to define it.