=================================================================== RCS file: /cvs/djgpp/djgpp/src/utils/utod.c,v retrieving revision 1.5 retrieving revision 1.6 diff -p -u -r1.5 -r1.6 --- djgpp/src/utils/utod.c 1999/06/03 17:27:41 1.5 +++ /cvs/djgpp/djgpp/src/utils/utod.c 2000/11/07 20:22:31 1.6 @@ -1,31 +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 -#include -#include #include #include -#include -#include #include +#include +#include +#include + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + 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); + int i, k, k2, sf, df, l, l2, err=0, iscr=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; } - fnsplit(fname, drive, path, NULL, NULL); - fnmerge(tfname, drive, path, "utod", "tm$"); - df = open(tfname, O_WRONLY|O_CREAT|O_TRUNC|O_TEXT, 0644); + + 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=='\\' || *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,15 +51,37 @@ utod(char *fname) } while ((l=read(sf, buf, 16384)) > 0) - write(df, buf, l); + { + for (i=k=0; i=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; }