delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/05/26/15:50:37

From: cgf AT cygnus DOT com (Christopher Faylor)
Subject: Re: fflush and exec
26 May 1998 15:50:37 -0700 :
Message-ID: <199805262219.SAA28778.cygnus.cygwin32.developers@kramden.cygnus.com>
To: cygwin32-developers AT cygnus DOT com, newsham AT lava DOT net

Have you ever tried this on UNIX?  I don't believe it flushes a stdio output
stream either.

cgf

>(note: disreguard my last post about the setfd close-on-exec code.
>I misread the code.  I think there is a problem there somewhere but
>I haven't been able to reproduce it in a test program yet).
>
>While testing other things I ran across this.  Doing an exec doesn't
>necessarily flush the output stream.  This can be confusing.  Here's
>a test program to reproduce this (remove the ifdef lines to see proper
>output,  shouldn't be needed).
>
>---- flush.c ----
>#include <stdio.h>
>
>main()
>{
>    printf("---- hello ----\n");
>#ifdef SHOULDNT_NEED_THIS
>    fflush(stdout);
>#endif
>
>    execl("./envargs", "envargs", 0);
>    perror("execl");
>    return -1;
>}
>---- end flush.c ----
>
>---- envargs.c : compile to envargs in same dir ----
>void
>print_list(char **l)
>{
>    int i;
>
>    for(i = 0; l[i]; i++) {
>        printf("    [%d] %s\n", i, l[i]);
>    }
>    return;
>}
>
>int
>main(int argc, char **argv)
>{
>    extern char **environ;
>    int i;
>
>    printf("Env: \n");
>    print_list(environ);
>    printf("\nArgs: \n");
>    print_list(argv);
>
>    printf("open files: ");
>    for(i = 0; i < 100; i++) {
>        if(i == 1 || close(i) == 0)
>            printf("%d ", i);
>    }
>    printf("\n");
>
>    return 0;
>}
>---- end envargs.c ----
>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019