On Fri, Jan 26, 2007 at 11:52:12AM +0100, David Härdeman wrote:
> On Fri, Jan 26, 2007 at 10:52:39AM +0100, Sven Luther wrote:
> >Next step would be :
> >
> > 1) write a program writing to stdout and dropping the actual error message
> > somewhere.
> 
> How about this:
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <string.h>
> 
> #define LOGFILE "/stdouttest.log"
> #define TESTMSG "This is a test string\n"
> 
> int
> main(int argc, char **argv, char **envp)
> {
>       FILE *logfile;
>       int printerrno;
>       char *printerror;
>       int retval = EXIT_FAILURE;
>       int result;
> 
>       /* Setup a log file */
>       logfile = fopen(LOGFILE, "a");
>       if (!logfile)
>               exit(retval);
>       
>       fprintf(logfile, "Program %s started\n", argv[0]); 
> 
>       /* Print to stdout */
>       result = fprintf(stdout, TESTMSG);
> 
>       /* Log results */
>       if (result < 0) {
>               printerrno = errno;
>               printerror = strerror(printerrno);
>               fprintf(logfile, "Printing failed (%i): %s\n",
>                       printerrno, printerror);
>       } else if (result < strlen(TESTMSG)) {
>               fprintf(logfile, "Printing was truncated to %i bytes\n", 
>               result);
>       } else {
>               fprintf(logfile, "Printing successful\n");
>               retval = EXIT_SUCCESS;
>       }
> 
>       /* We're done */
>       fclose(logfile);
>       exit(retval);
> }

Thanks, i will try, but i won't have time until i am back from solution linux
next thursday.

Friendly,

Sven Luther


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to