redirecting output
Peter da Silva
peter at ficc.ferranti.com
Mon Jul 2 09:52:01 AEST 1990
In article <1990Jun29.172429.2818 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
> You have the right idea, but you left something out. Try this instead:
While picking nits, how about doing it right. There's really no excuse for
not calling perror:
> #define FILENAME "filename"
> if (freopen(FILENAME, "w", stdout) == NULL) {
+ perror(FILENAME);
! fprintf(stderr, "Can't re-open standard output -- exiting\n");
> exit(1);
> }
> God is not on your side; such a call *will* fail eventually. Life is
> much more pleasant if your code copes properly.
And life is even better if it tells you *why* it fails. If your C runtime
doesn't implement perror, make it. I don't know of any operating system where
you can't at least differentiate between missing files and other errors.
Well, outside the top levels of the orange book, anyway.
--
Peter da Silva. `-_-'
+1 713 274 5180.
<peter at ficc.ferranti.com>
More information about the Comp.lang.c
mailing list