delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/04/16/15:13:53

From: yuri AT cs DOT cracksoft DOT kiev DOT ua (Yuri Kuzmenko)
Subject: b19.x trouble
16 Apr 1998 15:13:53 -0700 :
Message-ID: <199804161042.MAA13712.cygnus.gnu-win32@cs.cracksoft.kiev.ua>
To: gnu-win32 AT cygnus DOT com

I have a small trouble with stat() call in cygwin32 beta 19. Unfortunately, I
don't test my programm on the older versions. Problem is stat() returns time
(mtime) = original file mtime - 1 second. I have run cygwin on win95osr2,
vfat. Then, if I call utime() with mtime which returned by stat(), as result I
got time of file = original file time - 2 seconds. There is example:

// please reply to me by mail because I don't connected to mailing list

#ifndef O_BINARY
#define O_BINARY 0
#endif
#define CP_BUFSIZE (1024*128L) /* 128k blocks */
static int cp_(char *oldname,char *newname,int add)
/*
   copy oldname to newname
   use mmap with maximal buffer size = CP_BUFSIZE
	 >>> gnu_z: FUCKOFF, don't use mmap (?), use xmalloc
   mmap fails on big size files

	* xmalloc is malloc with auto-zero check
*/
{
  struct stat stbuf; int r,fd_in,fd_out; ssize_t write_return;
  char *data; struct utimbuf utbuf; unsigned long a,b,i;
	int read_res;
  if((r=stat(oldname,&stbuf)))
    return r;
  fd_in=open(oldname,O_RDONLY|O_BINARY);
  if(fd_in==-1) return -2;
  if(add==FALSE)
    fd_out=open(newname,O_BINARY|O_WRONLY|O_CREAT|O_TRUNC,stbuf.st_mode);
  else
    fd_out=open(newname,O_WRONLY|O_CREAT|O_APPEND|O_BINARY,stbuf.st_mode);
  if(fd_out==-1) { close(fd_in); return -3; }

  a=stbuf.st_size / CP_BUFSIZE; /* how many blocks */
  b=stbuf.st_size % CP_BUFSIZE; /* last block size */

	if(a)
		data=xmalloc(CP_BUFSIZE);

  for(i=0;i<a;i++)
  {
		if((read_res=read(fd_in,data,CP_BUFSIZE))!=CP_BUFSIZE)
		{
			fprintf(stderr,"cp(): read() returns %d (need %d)\n",read_res,CP_BUFSIZE);
			close(fd_in);
			close(fd_out);
			remove(newname);
			xfree(data);
			return -123;
		}
    write_return=write(fd_out,data,CP_BUFSIZE);
    if(write_return!=CP_BUFSIZE)
    {
      close(fd_in);
      close(fd_out);
      remove(newname);
			xfree(data);
      return -5;
    }
  }
	
	if(a)
		xfree(data);
		
	if(b)
	{
	  data=xmalloc(b);
		if((read_res=read(fd_in,data,b))!=b)
		{
			fprintf(stderr,"cp(): read() returns %d (need %d)\n",read_res,b);
			close(fd_in);
			close(fd_out);
			remove(newname);
			return -124;
		}
    write_return=write(fd_out,data,b);
		xfree(data);
  	close(fd_in);
	  close(fd_out);
	  if(write_return!=b)
	  {
	    remove(newname);
  	  return -7;
	  }
	}
 	utbuf.actime=stbuf.st_atime;
  utbuf.modtime=stbuf.st_mtime;
printf("DEBUG: mtime = %s\n",ctime(&stbuf.st_mtime));
  utime(newname,&utbuf);
  chmod(newname,stbuf.st_mode);
  chown(newname,stbuf.st_uid,stbuf.st_gid);
  return 0;
}
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


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