ccompiler-warningsstrptime

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?


Solution

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