delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/05/13/06:42:59

From: Andris Pavenis <pavenis AT latnet DOT lv>
To: djgpp-workers AT delorie DOT com
Subject: Patch for dtou.c and utod.c
Date: Sat, 13 May 2000 13:35:51 +0200
X-Mailer: KMail [version 1.0.28]
MIME-Version: 1.0
Message-Id: <00051313422100.25039@hal>
Reply-To: djgpp-workers AT delorie DOT com

--Boundary-=_nWlrBbmQBhCDarzOwKkYHIDdqSCD
Content-Type: text/plain
Content-Transfer-Encoding: 8bit

Hi!

I'm including below a patches for src/utils/dtou.c and src/utils/utod.c 
to make the same sources usable not only on DOS platform as I think it 
could be usefull to use the same utilities together with DJGPP targetted
cross-compiler instead of looking for other ones.

Andris

--Boundary-=_nWlrBbmQBhCDarzOwKkYHIDdqSCD
Content-Type: text/x-c;
  name="utils.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="utils.diff"

*** src/utils/dtou.c~1	Thu Jun  3 20:27:41 1999
--- src/utils/dtou.c	Fri Jan 21 18:00:13 2000
***************
*** 1,29 ****
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <stdio.h>
- #include <dir.h>
- #include <dos.h>
  #include <fcntl.h>
  #include <sys/stat.h>
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
  
  static int
  dtou(char *fname)
  {
!   int sf, df, l;
    char buf[16384];
!   char tfname[MAXPATH], drive[3], path[MAXPATH];
!   struct ftime ftime;
!   sf = open(fname, O_RDONLY|O_TEXT);
    if (sf < 1)
    {
      perror(fname);
      return 1;
    }
!   fnsplit(fname, drive, path, NULL, NULL);
!   fnmerge(tfname, drive, path, "utod", "tm$");
    df = open(tfname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if (df < 1)
    {
--- 1,45 ----
+ /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+ /* Modified by A.Pavenis to work also in different Unix clones */
  #include <stdio.h>
  #include <fcntl.h>
  #include <sys/stat.h>
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
+ #include <utime.h>
+ 
+ #ifndef O_BINARY
+ #define O_BINARY 0
+ #endif
  
  static int
  dtou(char *fname)
  {
!   int i, k, k2, sf, df, l, l2, err=0;
    char buf[16384];
!   char tfname[FILENAME_MAX], *bn, *w;
!   struct stat st;
!   struct utimbuf tim1;
!   sf = open(fname, O_RDONLY|O_BINARY);
    if (sf < 1)
    {
      perror(fname);
      return 1;
    }
!   
!   fstat (sf,&st);
!   tim1.actime = st.st_atime;
!   tim1.modtime = st.st_mtime;
! 
!   strcpy (tfname, fname);
!   for (bn=w=tfname; *w; w++) 
!     if (*w=='/' || *w=='\\') 
!       bn = w+1;  
!   if (bn) *bn=0;
!   strcat (tfname,"utod.tm$");
!   
    df = open(tfname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if (df < 1)
    {
***************
*** 32,47 ****
      return 1;
    }
  
    while ((l=read(sf, buf, 16384)) > 0)
!     write(df, buf, l);
  
-   getftime(sf, &ftime);
-   setftime(df, &ftime);
    close(sf);
    close(df);
  
!   remove(fname);
!   rename(tfname, fname);
    return 0;
  }
  
--- 48,83 ----
      return 1;
    }
  
+   k2=0;
    while ((l=read(sf, buf, 16384)) > 0)
!   { 
!     for (i=k=0; i<l; i++) 
!       if (buf[i]!=13)
!         buf[k++]=buf[i];
!     l2=write(df, buf, k);
!     if (l2<0) break;
!     if (l2!=k) { err=1; break; }
!   }
! 
!   if (l<0) perror (fname);
!   if (l2<0) perror (tfname);
!   if (err) fprintf (stderr,"Cannot process file %s\n",fname);
  
    close(sf);
    close(df);
  
!   if (l>=0 && l2>=0 && err==0)
!   {
!     remove(fname);
!     rename(tfname, fname);
!     utime(fname, &tim1);
!     chown(fname, st.st_uid, st.st_gid);
!     chmod(fname, st.st_mode);
!   }
!   else 
!   {
!     remove(tfname);
!   }
    return 0;
  }
  
*** src/utils/utod.c~1	Thu Jun  3 20:27:41 1999
--- src/utils/utod.c	Fri Jan 21 18:05:32 2000
***************
*** 1,31 ****
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <stdio.h>
- #include <dir.h>
- #include <dos.h>
  #include <fcntl.h>
  #include <sys/stat.h>
- #include <unistd.h>
- #include <string.h>
  #include <stdlib.h>
  
  static int
  utod(char *fname)
  {
!   int sf, df, l;
!   struct ftime ftime;
!   char buf[16384];
!   char tfname[MAXPATH], drive[3], path[MAXPATH];
!   sf = open(fname, O_RDONLY|O_TEXT);
    if (sf < 0)
    {
      perror(fname);
      return 1;
    }
!   fnsplit(fname, drive, path, NULL, NULL);
!   fnmerge(tfname, drive, path, "utod", "tm$");
!   df = open(tfname, O_WRONLY|O_CREAT|O_TRUNC|O_TEXT, 0644);
    if (df < 0)
    {
      perror(tfname);
--- 1,48 ----
+ /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+ /* Modified by A.Pavenis to work also in different Unix clones */
  #include <stdio.h>
  #include <fcntl.h>
  #include <sys/stat.h>
  #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <utime.h>
+ 
+ #ifndef O_BINARY
+ #define O_BINARY 0
+ #endif
+ 
  
  static int
  utod(char *fname)
  {
!   int i, k, k2, sf, df, l, l2, err=0;
!   char buf[16384], buf2[32768];
!   char tfname[FILENAME_MAX], *bn, *w;
!   struct stat st;
!   struct utimbuf tim1;
!   sf = open(fname, O_RDONLY|O_BINARY);
    if (sf < 0)
    {
      perror(fname);
      return 1;
    }
! 
!   fstat (sf,&st);
!   tim1.actime = st.st_atime;
!   tim1.modtime = st.st_mtime;
! 
!   strcpy (tfname, fname);
!   for (bn=w=tfname; *w; w++) 
!     if (*w=='/' || *w=='\\') 
!       bn = w+1;  
!   if (bn) *bn=0;
!   strcat (tfname,"utod.tm$");
!   
!   df = open(tfname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if (df < 0)
    {
      perror(tfname);
***************
*** 34,48 ****
    }
  
    while ((l=read(sf, buf, 16384)) > 0)
!     write(df, buf, l);
  
-   getftime(sf, &ftime);
-   setftime(df, &ftime);
    close(sf);
    close(df);
  
!   remove(fname);
!   rename(tfname, fname);
    return 0;
  }
  
--- 51,88 ----
    }
  
    while ((l=read(sf, buf, 16384)) > 0)
!   {
!     int iscr=0;
!     for (i=k=0; i<l; i++)
!     {
!       if (buf[i]==10 && !iscr) buf2[k++]=13;
!       iscr=buf[i]==13 ? 1 : 0;
!       buf2[k++]=buf[i];
!     }
!     l2=write(df, buf2, k);
!     if (l2<0) break;
!     if (l2!=k) { err=1; break; }
!   }
! 
!   if (l<0) perror (fname);
!   if (l2<0) perror (tfname);
!   if (err) fprintf (stderr,"Cannot process file %s\n",fname);
  
    close(sf);
    close(df);
  
!   if (l>=0 && l2>=0 && err==0)
!   {
!     remove(fname);
!     rename(tfname, fname);
!     utime(fname, &tim1);
!     chown(fname, st.st_uid, st.st_gid);
!     chmod(fname, st.st_mode);
!   }
!   else 
!   {
!     remove(tfname);
!   }
    return 0;
  }
  

--Boundary-=_nWlrBbmQBhCDarzOwKkYHIDdqSCD--

- Raw text -


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