Closed iphydf closed 4 months ago
It looks like localtime() set errno when the compiled executable is executed with docker RUN
Probably specific to Ubuntu docker, changed base to debian:latest
or debian:buster-slim
and the errno is gone.
localtime_errno.c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
int main(void) {
time_t now = time(NULL);
if (errno)
fprintf(stderr, "time() set errno to %d", errno), exit(1);
struct tm *tmp = localtime(&now);
if (!tmp)
fprintf(stderr, "localtime() return null"), exit(1);
if (errno)
fprintf(stderr, "localtime() set errno to %d", errno), exit(1);
}
dockerfile
...
WORKDIR /work/localtime_errno_test
COPY localtime_errno.c /work/localtime_errno_test/
RUN gcc localtime_errno.c -o out
RUN ./out #bad
Tried a few more dockerhub images
localtime()
set ENOENT: alpine:latest
, ubuntu:20.04
localtime()
doesn't set ENOENT fedora:40
debian:latest
gcc:latest
Anyway, I removed the assert and main
should be good now.
https://github.com/fuhsnn/slimcc/commit/7b7c98604ab3eb85e68d7b3ae7f884d5537638c8 the assert added here triggers.
Input file:
Another option: