From: simonmar Date: Mon, 21 May 2001 11:02:15 +0000 (+0000) Subject: [project @ 2001-05-21 11:02:15 by simonmar] X-Git-Tag: Approximately_9120_patches~1920 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=df318cbdc37897c4c73839ff97414b518ec268f5;p=ghc-hetmet.git [project @ 2001-05-21 11:02:15 by simonmar] Re-instate the missing fstat call. By some bizarre coincidence, this function declared a 'struct stat', and failed to initialize it, but in practice the uninitialized memory was in the exact same place on the stack as the struct stat from a previous call to fstat, which meant all the tests worked :-) Also, apparently gcc doesn't warn about uninitialised use of structure fields. --- diff --git a/ghc/lib/std/cbits/lockFile.c b/ghc/lib/std/cbits/lockFile.c index 14a0a38..f6a9aea 100644 --- a/ghc/lib/std/cbits/lockFile.c +++ b/ghc/lib/std/cbits/lockFile.c @@ -1,7 +1,7 @@ /* * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998 * - * $Id: lockFile.c,v 1.1 2001/05/18 16:54:06 simonmar Exp $ + * $Id: lockFile.c,v 1.2 2001/05/21 11:02:15 simonmar Exp $ * * stdin/stout/stderr Runtime Support */ @@ -27,8 +27,21 @@ static int writeLocks = 0; int lockFile(int fd, int for_writing, int exclusive) { - int i; struct stat sb; + int i; + + while (fstat(fd, &sb) < 0) { + if (errno != EINTR) { +#ifndef _WIN32 + return -1; +#else + /* fstat()ing socket fd's seems to fail with CRT's fstat(), + so let's just silently return and hope for the best.. + */ + return 0; +#endif + } + } if (for_writing) { /* opening a file for writing, check to see whether