Compiler gets warnings when using strptime functio

2020-07-06 07:19发布

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?

1条回答
Fickle 薄情
2楼-- · 2020-07-06 08:18

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

查看更多
登录 后发表回答