delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/08/11/04:49:31

X-Authentication-Warning: smtp3.ihug.com.au: Host p45-max18.syd.ihug.com.au [203.173.153.45] claimed to be acceleron
Message-ID: <003801c12241$d44f9b10$0a02a8c0@acceleron>
From: "Andrew Cottrell" <acottrel AT ihug DOT com DOT au>
To: <djgpp-workers AT delorie DOT com>
Cc: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Subject: Link function query
Date: Sat, 11 Aug 2001 18:44:25 +1000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700
Reply-To: djgpp-workers AT delorie DOT com

Hi,

My question is in link.s shouldn't we either use stat() or fstat() not both?
Stat calls lstat() and the lstat file

If I move the open path1 and use the fd1 and change the code to use fstat
then the function almost works. Once I use fstat() I then find that the
newely created file has the read only bit set, I am currently looking at
this issue. I may be able to produce a patch very quickly once I know the
answer to the stat() or fstat() question above.

In link.c source lines ( may have added extra braces and spaces as I am
debugging a link issue under Win 2K):

  /* Fail if path1 does not exist - stat() will set errno */
  if (stat(path1, &statbuf1) < 0) return -1;                        /* STAT
LINE !!!!! */

  /* Fail if path1 and path2 are on different devices */
  if (fstat(fd2, &statbuf2) < 0)  return -1;                            /*
FSTAT LINE !!!!! */

  if (statbuf1.st_dev != statbuf2.st_dev)            /* COMPARE FSTAT and
STAT */
  {
    (void)close(fd1);
    (void)close(fd2);
    (void)unlink(path2);
    errno = EXDEV;
    return -1;
  }

  /* Copy path1 to path2 */
  do
  {
    nbyte = read(fd1, buf, sizeof buf);
    if (nbyte <= 0) break;
    if (write(fd2, buf, nbyte) != nbyte) nbyte = -1;
  }
  while (nbyte > 0);

Andrew


- Raw text -


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