~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_copy.c

Renamed strings to mystrings, for include/lib naming consistency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include "mysys_priv.h"
17
17
#include <my_dir.h> /* for stat */
18
 
#include <mystrings/m_string.h>
 
18
#include <m_string.h>
19
19
#if defined(HAVE_UTIME_H)
20
20
#include <utime.h>
21
21
#elif defined(HAVE_SYS_UTIME_H)
28
28
};
29
29
#endif
30
30
 
31
 
#include <drizzled/util/test.h>
32
31
 
33
32
/*
34
33
  int my_copy(const char *from, const char *to, myf MyFlags)
51
50
 
52
51
int my_copy(const char *from, const char *to, myf MyFlags)
53
52
{
54
 
  uint32_t Count;
 
53
  uint Count;
55
54
  bool new_file_stat= 0; /* 1 if we could stat "to" */
56
55
  int create_flag;
57
56
  File from_file,to_file;
58
 
  unsigned char buff[IO_SIZE];
 
57
  uchar buff[IO_SIZE];
59
58
  struct stat stat_buff,new_stat_buff;
60
59
 
61
60
  from_file=to_file= -1;
63
62
  if (MyFlags & MY_HOLD_ORIGINAL_MODES)         /* Copy stat if possible */
64
63
    new_file_stat= test(!stat((char*) to, &new_stat_buff));
65
64
 
66
 
  if ((from_file=my_open(from,O_RDONLY,MyFlags)) >= 0)
 
65
  if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)
67
66
  {
68
67
    if (stat(from, &stat_buff))
69
68
    {
75
74
    create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
76
75
 
77
76
    if ((to_file=  my_create(to,(int) stat_buff.st_mode,
78
 
                             O_WRONLY | create_flag,
 
77
                             O_WRONLY | create_flag | O_BINARY | O_SHARE,
79
78
                             MyFlags)) < 0)
80
79
      goto err;
81
80
 
93
92
 
94
93
    if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
95
94
        return(0);                      /* File copyed but not stat */
96
 
    chmod(to, stat_buff.st_mode & 07777); /* Copy modes */
97
 
    if(chown(to, stat_buff.st_uid,stat_buff.st_gid)!=0)
98
 
        return 0;
 
95
    VOID(chmod(to, stat_buff.st_mode & 07777)); /* Copy modes */
 
96
    VOID(chown(to, stat_buff.st_uid,stat_buff.st_gid)); /* Copy ownership */
99
97
    if (MyFlags & MY_COPYTIME)
100
98
    {
101
99
      struct utimbuf timep;
102
100
      timep.actime  = stat_buff.st_atime;
103
101
      timep.modtime = stat_buff.st_mtime;
104
 
      utime((char*) to, &timep); /* last accessed and modified times */
 
102
      VOID(utime((char*) to, &timep)); /* last accessed and modified times */
105
103
    }
106
104
    return(0);
107
105
  }
108
106
 
109
107
err:
110
 
  if (from_file >= 0) my_close(from_file,MyFlags);
 
108
  if (from_file >= 0) VOID(my_close(from_file,MyFlags));
111
109
  if (to_file >= 0)
112
110
  {
113
 
    my_close(to_file, MyFlags);
 
111
    VOID(my_close(to_file, MyFlags));
114
112
    /* attempt to delete the to-file we've partially written */
115
 
    my_delete(to, MyFlags);
 
113
    VOID(my_delete(to, MyFlags));
116
114
  }
117
115
  return(-1);
118
116
} /* my_copy */