ishwar...@gmail.com writes:
> System is Linux with gcc version 4.7.1 (Debian 4.7.1-2) and
> the following code writes to stdin.
>
> #include <stdio.h>
> #include <unistd.h>
>
> int main()
> {
> if (write(0, "Hello world!\n", 13) != 13)
> fprintf(stderr, "Write failed\n");
> return 0;
> }
It’ll succeed if fd 0 is writable. That’s likely to be the case if you
run it from a shell without redirection, since fd 0 will be the
terminal.
It’ll fail if fd 0 is closed or is not writable, for instance if you’ve
redirected it from a file.
--
http://www.greenend.org.uk/rjk/