Time libraries and funtions for Windows C Compiling

This is a discussion on Time libraries and funtions for Windows C Compiling within the C Programming forums, part of the General Programming Boards category; Hi, I have a C program I wrote for Unix that uses some time libraries such as: #include <sys/time.h> #include ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    3

    Time libraries and funtions for Windows C Compiling

    Hi,

    I have a C program I wrote for Unix that uses some time libraries such as:

    #include <sys/time.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/sysinfo.h>

    and functions like:

    ascftime() and strptime() to manipulate date strings and formats.

    I am trying to compile this code under windows (using LLC compiler) but it looks that it does not contain the libraries/functions to support this coding. Does anyone know either where I can dowwnload such lubraries (for Windows) or what are the ANSI-C equivalent commands under Windows OS?

    Appreciated
    vmn_3k

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    32
    I assume you are referring to the lcc compiler (Please correct me otherwise - I have not heard of LLC). Checking lcc\include\sys reveals that there is no time.h nor sysinfo.h present.

    Also, I imagine that due to the different notation between Unix and Windows that you would need to change around the forward slashes to backwards slashes in the include lines.

    I'm not sure however where you can download missing libraries. Perhaps a Google might prove fruitful?
    Beware the fury of a patient man.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    The files placed in the sys-directory are part of the POSIX standard. Unix-like OS-es usally are POSIX complient, as far as I know Windows OS-es are not. But there are POSIX libraries which can be used to use POSIX calls on Windows OS-es.

    http://www.opengroup.org/onlinepubs/007904975/toc.htm
    http://pw32.sourceforge.net/

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    LCC has strftime() which is the same as ascftime but with a size specifier. Write your own one line ascftime function if you don't want to change the code.

    LCC does not have strptime() (at least in my version) but this would also be a couple of lines using sscanf if you know the input format.

    #include <time.h>

    Have Fun!

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    Thanks all,

    I tried the sscanf suggestion and with some additional code lines I was able to make it work!
    However I entered into a new problem (more complicated, I think ). My unix c code reads a binary file and as you might guess, it comes from a big-endian platform. Windows reads int in a little-endian fashion so I will have to look a way to rearrange the int/short int that I read to display them properly. I realized that the hard way (printf statements and hex viewers in unix)
    Anyway, I think this might be the start of another thread (have not found the answer yet within the forum posts)

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Converts from big-endian to little-endian on Win32. No op on big-endian machines:
    ntohs()
    ntohl()

    and reverse:
    htonl()
    htons()
    These are from the sockets library and should do the trick. Otherwise a macro could be used.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    I read about those but do not how to use them. The Solaris man page is not that clear (to me). Also it looks like LCC does not contain a library to support them (pls correct me if Im wrong).

    Anyway, I was able to convert from big to little endian using byte shifting. However I use tons of variables assigned to different values read from the binary file. So I would have to apply this byte shifting macro to every variable (??). If ntohl() / ntohs() have a better way to deal with it pls let me know

    Thanks!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21