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