delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/05/26/13:54:35

From: newsham AT lava DOT net (Tim Newsham)
Subject: fflush and exec
26 May 1998 13:54:35 -0700 :
Message-ID: <m0yeQU2-00114cC.cygnus.cygwin32.developers@malasada.lava.net>
Mime-Version: 1.0
To: cygwin32-developers AT cygnus DOT com

(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).

                                       Tim N.

---- 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