The output from errno = 0 is less portable.
printf("write to stdout\n");
fflush(stdout);
printf("write to stdout\n");
fflush(stdout);
perror("error!");
write(STDERR_FILENO, "write to stderr 2", 17);
perror("error!");
write(STDERR_FILENO, "write to stderr 2", 17);
>STDERR>write to stderr: 1
<STDERR<write to stdout
>STDERR>write to stderr: 1
<STDERR<write to stdout
+>STDERR>error!: Cannot allocate memory
<STDERR<>STDERR>write to stderr 2<STDERR<write to stdout 2>STDERR>
<STDERR<
>STDERR>more on stderr
<STDERR<>STDERR>write to stderr 2<STDERR<write to stdout 2>STDERR>
<STDERR<
>STDERR>more on stderr
write to stderr: 1
write to stdout
write to stderr: 1
write to stdout
+error!: Cannot allocate memory
write to stderr 2write to stdout 2
more on stderr
write to stderr 2write to stdout 2
more on stderr