18#include <drizzled/internal/my_sys.h>
22#include <drizzled/internal/m_string.h>
27#include <drizzled/util/test.h>
53int my_copy(
const char *from,
const char *to, myf MyFlags)
56 bool new_file_stat= 0;
58 int from_file,to_file;
59 unsigned char buff[IO_SIZE];
60 struct stat stat_buff,new_stat_buff;
62 from_file=to_file= -1;
63 assert(!(MyFlags & (MY_FNABP | MY_NABP)));
64 if (MyFlags & MY_HOLD_ORIGINAL_MODES)
65 new_file_stat= test(!stat((
char*) to, &new_stat_buff));
67 if ((from_file=my_open(from,O_RDONLY,MyFlags)) >= 0)
69 if (stat(from, &stat_buff))
74 if (MyFlags & MY_HOLD_ORIGINAL_MODES && new_file_stat)
75 stat_buff=new_stat_buff;
76 create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
78 if ((to_file= my_create(to,(
int) stat_buff.st_mode,
79 O_WRONLY | create_flag,
83 while ((Count=
static_cast<uint32_t
>(my_read(from_file, buff,
84 sizeof(buff), MyFlags))) != 0)
86 if (Count == (uint32_t) -1 ||
87 my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP)))
91 if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags))
96 if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
98 chmod(to, stat_buff.st_mode & 07777);
99 if(chown(to, stat_buff.st_uid,stat_buff.st_gid)!=0)
101 if (MyFlags & MY_COPYTIME)
103 struct utimbuf timep;
104 timep.actime = stat_buff.st_atime;
105 timep.modtime = stat_buff.st_mtime;
106 utime((
char*) to, &timep);
112 if (from_file >= 0) my_close(from_file,MyFlags);
115 my_close(to_file, MyFlags);
117 my_delete(to, MyFlags);
TODO: Rename this file - func.h is stupid.