That has to be one of the more convoluted and inefficient ways of writing:
int lastModifiedTime(const char *filePath)
{
struct stat attrib;
if (stat(filePath, &attrib) != 0)
return -1;
return attrib.st_mtime;
}
However, to answer the question:
You get the error when you specify
-pedantic
(and not when you don't, even with all the other stringent warnings shown):$ gcc -O3 -g -std=c11 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Werror -pedantic -c stt.c stt.c: In function ‘lastModifiedTime’: stt.c:14:5: error: ISO C does not support the ‘%s’ gnu_strftime format [-Werror=format=] strftime(datestring, sizeof(datestring), "%s", tm); ^ cc1: all warnings being treated as errors $
As stated, by omitting the
-pedantic
, you avoid that error. Assuming-pedantic
is required, then you seem to be hosed. The nearest I can get is avoiding an error but still getting a warning:$ gcc -O3 -g -std=c11 -Wall -Wextra -Werror -pedantic -Wno-error=format= -c stt.c stt.c: In function ‘lastModifiedTime’: stt.c:14:5: warning: ISO C does not support the ‘%s’ gnu_strftime format [-Wformat=] strftime(datestring, sizeof(datestring), "%s", tm); ^ $
I'm probably suffering from a lack of imagination, but I can't suppress the warning. I've tried (with GCC 4.8.2 on Ubuntu 14.04):
-Wnoformat
-Wno-format
-Wno-format=
-Wnoerror=format=
-Wnoformat=
But none of these was accepted.