16 #include "mysys_priv.h"
19 #include "mysys_err.h"
20 #if defined(HAVE_UTIME_H)
22 #elif defined(HAVE_SYS_UTIME_H)
23 #include <sys/utime.h>
24 #elif !defined(HPUX10)
52 int my_copy(
const char *from,
const char *
to, myf MyFlags)
55 my_bool new_file_stat= 0;
57 File from_file,to_file;
59 MY_STAT stat_buff,new_stat_buff;
60 DBUG_ENTER(
"my_copy");
61 DBUG_PRINT(
"my",(
"from %s to %s MyFlags %d", from, to, MyFlags));
63 from_file=to_file= -1;
64 DBUG_ASSERT(!(MyFlags & (MY_FNABP | MY_NABP)));
65 if (MyFlags & MY_HOLD_ORIGINAL_MODES)
66 new_file_stat=
test(my_stat((
char*) to, &new_stat_buff, MYF(0)));
68 if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)
70 if (!my_stat(from, &stat_buff, MyFlags))
75 if (MyFlags & MY_HOLD_ORIGINAL_MODES && new_file_stat)
76 stat_buff=new_stat_buff;
77 create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
79 if ((to_file= my_create(to,(
int) stat_buff.st_mode,
80 O_WRONLY | create_flag | O_BINARY | O_SHARE,
84 while ((Count=my_read(from_file, buff,
sizeof(buff), MyFlags)) != 0)
86 if (Count == (uint) -1 ||
87 my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP)))
92 if (MyFlags & MY_SYNC)
94 if (my_sync(to_file, MyFlags))
98 if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags))
103 if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
106 if (chmod(to, stat_buff.st_mode & 07777))
109 if (MyFlags & (MY_FAE+MY_WME))
111 char errbuf[MYSYS_STRERROR_SIZE];
112 my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), from,
113 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
117 #if !defined(__WIN__)
119 if (chown(to, stat_buff.st_uid, stat_buff.st_gid))
122 if (MyFlags & (MY_FAE+MY_WME))
124 char errbuf[MYSYS_STRERROR_SIZE];
125 my_error(EE_CHANGE_OWNERSHIP, MYF(ME_BELL+ME_WAITTANG), from,
126 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
132 if (MyFlags & MY_COPYTIME)
135 timep.actime = stat_buff.st_atime;
136 timep.modtime = stat_buff.st_mtime;
137 (void) utime((
char*)
to, &timep);
144 if (from_file >= 0) (void) my_close(from_file,MyFlags);
147 (void) my_close(to_file, MyFlags);
149 (void) my_delete(to, MyFlags);