Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The C standard only states that time_t is an integer (or floating-point) type, and POSIX further states it represents seconds since the epoch, so a 64-bit time_t is a good solution.

In order to find and change occurrences of time_t in ports more easily, they could use the Coccinelle tool.[1] The following semantic patch would find and replace variable declarations of type time_t:

    @sys_types@
    @@
    #include <sys/types.h>
    
    @time_t depends on sys_types@
    identifier x;
    @@
    - time_t x
    + long long int x
      ;
Replacing printf format specifiers is more difficult, so the following semantic patch will find printf statements which use time_t variables, which can then be edited manually:

    @sys_types@
    @@
    #include <sys/types.h>
    
    @stdio@
    @@
    #include <stdio.h>
    
    @printf depends on sys_types && stdio@
    identifier x;
    @@
      time_t x;
      ...
    * printf(..., x, ...);
These can be used as follows:

    $ spatch --sp-file foo.cocci --dir /path/to/ports
where `foo.cocci` is the name of one of the semantic patches above.

[1] http://coccinelle.lip6.fr/



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: