Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler gets warnings when using strptime function (C)

Typing man strptime it sais that this function needs to have declared _XOPEN_SOURCE and included time.h header. I did it. But, when I try to compile my code I get:

./check.c:56: warning: implicit declaration of function ‘strptime’

Look at my code:

int lockExpired(const char *date, const char *format, time_t current) {
        struct tm *tmp = malloc(sizeof(struct tm *));
        time_t lt;
        int et;

        strptime(date, format, tmp);
        lt = mktime(tmp);
        et = difftime(current, lt);

        if (et < 3600)
                return -et;

        return 1;
}

Also the function declaration is:

char *strptime(const char *s, const char *format, struct tm *tm);

Can anyone tell me where my problem come from?

like image 811
artaxerxe Avatar asked Mar 11 '13 09:03

artaxerxe


1 Answers

I've found that I needed to define __USE_XOPEN and also _GNU_SOURCE to get it to be happy.

like image 75
Joe Avatar answered Sep 20 '22 14:09

Joe