Subject: open vs stat and install behavior
From: [email-masked] (Marcus G. Daniels)

2 Aug 1997 11:49:25 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Original-To: [email-masked]
X-Mailer: Gnus v5.5/Emacs 20.0
Original-Sender: [email-masked]

I think `install' should be able to deal with executable filenames
without an .exe suffix.  The b18 behavior is that `stat' will succeed
finding an executable named "t", but `open' will fail.  For example,
the following program correctly prints the file size of itself, but
fails on the open.  If there is an important reason for the different
open and stat behavior, I propose the patch that follows to install.c.

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

main()
{
  struct stat statbuf;
  const char *file = "t";

  if (stat (file, &statbuf) == 1) 
    {
      fprintf (stderr, "stat failed to find `%s'\n",file);
      exit (1);
    }
  printf ("%d\n", statbuf.st_size);
  if (open (file, O_BINARY | O_RDONLY) == -1)
    {
      fprintf (stderr, "open failed to find `%s'\n", file);
      exit (1);
    }
}

/*
Local Variables:
compile-command: "gcc t.c -o t"
End:
*/

*** install.c	Tue Apr 15 00:57:17 1997
--- install.c.new	Sat Aug  2 10:00:52 1997
***************
*** 309,321 ****
     Return 0 if successful, 1 if an error occurs. */
  
  static int
! install_file_in_file (char *from, char *to)
  {
    int to_created;
    int no_need_to_chown;
! 
    if (copy_file (from, to, &to_created))
!     return 1;
    if (strip_files)
      strip (to);
    no_need_to_chown = (to_created
--- 309,346 ----
     Return 0 if successful, 1 if an error occurs. */
  
  static int
! install_file_in_file (char *from_, char *to_)
  {
    int to_created;
    int no_need_to_chown;
!   char *from, *to;
!   int fromfd = open (from, O_RDONLY | O_BINARY, 0);
!   if (fromfd == -1)
!     {
!       from = alloca (strlen (from_) + 5);
!       to = alloca (strlen (to_) + 5);
!       strcpy (from, from_);
!       strcat (from, ".exe");
!       strcpy (to, to_);
!       strcat (to, ".exe");
!       fromfd = open (from, O_RDONLY | O_BINARY, 0);
!       if (fromfd == -1)
!         {
!           from = from_;
!           to = to_;
!         }
!       else
!         close (fromfd);
!     }
!   else
!     {
!       close (fromfd);
!       from = from_;
!       to = to_;
!     }
!   
    if (copy_file (from, to, &to_created))
!     return 1;    
    if (strip_files)
      strip (to);
    no_need_to_chown = (to_created

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".