delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/05/12/14:45:32

From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10305121847.AA21879@clio.rice.edu>
Subject: From djgpp mailing list - fstat() on stdout NT/W2K
To: djgpp-workers AT delorie DOT com (DJGPP developers)
Date: Mon, 12 May 2003 13:47:50 -0500 (CDT)
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

As noted on the djgpp discussion, the following program is on NT/W2K using
v2.03 causes problems when it's output is >> to an existing file :

#include <stdio.h>
#include <sys/stat.h>

int main(){
    struct stat sbuf;

    char tx[]="bbbb\n";

    if (fstat(1, &sbuf) < 0) {
       tx[1]='x';
    }

    return printf (tx);
}

I have confirmed that v2.04 alpha doesn't suffer this problem under 
Win2K SP3.  It appears that the seeks in __filelength called by fstat()
cause the file pointer to be left in the wrong place.  We originally
saw a similar (but completely different it turns out) problem on stdin
almost 2 years ago.  __filelength for v2.04 uses an LFN function to get
the length; v2.03 seeks - so v2.04 works and v2.03 doesn't.  I expect
(and just confirmed) that v2.04 won't work on NT without the LFN TSR 
installed.

I'll try to look at the old email logs - Andrew had some code which
helped on the stdin problem (that we didn't use) that might help
here - or maybe we just need to identify these handles before hand
and avoid seeking on them.

I don't mind 2.03 being broken since we are soon to release 2.04, but
I'd like it if 2.04 wasn't broken in some cases.

- Raw text -


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