~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_symlink.cc

pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
macros.
Add PANDORA_DRIZZLE_BUILD to run the extra checks that drizzle needs that 
plugins would also need to run so we can just use that macro in generated
external plugin builds.
Added support to register_plugins for external plugin building.
Renamed register_plugins.py to pandora-plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "mysys_priv.h"
17
 
#include "mysys_err.h"
 
16
#include "mysys/mysys_priv.h"
 
17
#include "mysys/mysys_err.h"
18
18
#include <mystrings/m_string.h>
19
19
#include <errno.h>
20
 
#ifdef HAVE_REALPATH
21
 
#include <sys/param.h>
22
 
#include <sys/stat.h>
23
 
#endif
24
 
 
25
 
/*
26
 
  Reads the content of a symbolic link
27
 
  If the file is not a symbolic link, return the original file name in to.
28
 
 
29
 
  RETURN
30
 
    0  If filename was a symlink,    (to will be set to value of symlink)
31
 
    1  If filename was a normal file (to will be set to filename)
32
 
   -1  on error.
33
 
*/
34
 
 
35
 
int my_readlink(char *to, const char *filename, myf MyFlags)
36
 
{
37
 
#ifndef HAVE_READLINK
38
 
  stpcpy(to,filename);
39
 
  return 1;
40
 
#else
41
 
  int result=0;
42
 
  int length;
43
 
 
44
 
  if ((length=readlink(filename, to, FN_REFLEN-1)) < 0)
45
 
  {
46
 
    /* Don't give an error if this wasn't a symlink */
47
 
    if ((my_errno=errno) == EINVAL)
48
 
    {
49
 
      result= 1;
50
 
      stpcpy(to,filename);
51
 
    }
52
 
    else
53
 
    {
54
 
      if (MyFlags & MY_WME)
55
 
        my_error(EE_CANT_READLINK, MYF(0), filename, errno);
56
 
      result= -1;
57
 
    }
58
 
  }
59
 
  else
60
 
    to[length]=0;
61
 
  return(result);
62
 
#endif /* HAVE_READLINK */
63
 
}
64
 
 
65
 
 
66
 
/* Create a symbolic link */
67
 
 
68
 
int my_symlink(const char *content, const char *linkname, myf MyFlags)
69
 
{
70
 
#ifndef HAVE_READLINK
71
 
  return 0;
72
 
#else
73
 
  int result;
74
 
 
75
 
  result= 0;
76
 
  if (symlink(content, linkname))
77
 
  {
78
 
    result= -1;
79
 
    my_errno=errno;
80
 
    if (MyFlags & MY_WME)
81
 
      my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno);
82
 
  }
83
 
  else if ((MyFlags & MY_SYNC_DIR) && my_sync_dir_by_file(linkname, MyFlags))
84
 
    result= -1;
85
 
  return(result);
86
 
#endif /* HAVE_READLINK */
87
 
}
88
 
 
89
 
/*
90
 
  Resolve all symbolic links in path
91
 
  'to' may be equal to 'filename'
92
 
 
93
 
  Because purify gives a lot of UMR errors when using realpath(),
94
 
  this code is disabled when using purify.
95
 
 
96
 
  If MY_RESOLVE_LINK is given, only do realpath if the file is a link.
97
 
*/
98
 
 
99
 
#if defined(SCO)
100
 
#define BUFF_LEN 4097
101
 
#elif defined(MAXPATHLEN)
102
 
#define BUFF_LEN MAXPATHLEN
103
 
#else
104
 
#define BUFF_LEN FN_LEN
105
 
#endif
106
 
 
107
 
int my_realpath(char *to, const char *filename,
108
 
                myf MyFlags __attribute__((unused)))
109
 
{
110
 
#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH)
111
 
  int result=0;
112
 
  char buff[BUFF_LEN];
113
 
  struct stat stat_buff;
114
 
 
115
 
  if (!(MyFlags & MY_RESOLVE_LINK) ||
116
 
      (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
117
 
  {
118
 
    char *ptr;
119
 
    if ((ptr=realpath(filename,buff)))
120
 
    {
121
 
      strmake(to,ptr,FN_REFLEN-1);
122
 
    }
123
 
    else
124
 
    {
125
 
      /*
126
 
        Realpath didn't work;  Use my_load_path() which is a poor substitute
127
 
        original name but will at least be able to resolve paths that starts
128
 
        with '.'.
129
 
      */
130
 
      my_errno=errno;
131
 
      if (MyFlags & MY_WME)
132
 
        my_error(EE_REALPATH, MYF(0), filename, my_errno);
133
 
      my_load_path(to, filename, NullS);
134
 
      result= -1;
135
 
    }
136
 
  }
137
 
  return(result);
138
 
#else
139
 
  my_load_path(to, filename, NullS);
140
 
  return 0;
141
 
#endif
142
 
}
 
20
 
 
21
bool test_if_hard_path(const char *dir_name)
 
22
{
 
23
  if (dir_name[0] == FN_HOMELIB && dir_name[1] == FN_LIBCHAR)
 
24
    return (home_dir != NULL && test_if_hard_path(home_dir));
 
25
  if (dir_name[0] == FN_LIBCHAR)
 
26
    return (true);
 
27
  return false;
 
28
} /* test_if_hard_path */