1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include "mysys_err.h"
21
#include <sys/param.h>
26
Reads the content of a symbolic link
27
If the file is not a symbolic link, return the original file name in to.
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)
35
int my_readlink(char *to, const char *filename, myf MyFlags)
43
DBUG_ENTER("my_readlink");
45
if ((length=readlink(filename, to, FN_REFLEN-1)) < 0)
47
/* Don't give an error if this wasn't a symlink */
48
if ((my_errno=errno) == EINVAL)
56
my_error(EE_CANT_READLINK, MYF(0), filename, errno);
62
DBUG_PRINT("exit" ,("result: %d", result));
64
#endif /* HAVE_READLINK */
68
/* Create a symbolic link */
70
int my_symlink(const char *content, const char *linkname, myf MyFlags)
76
DBUG_ENTER("my_symlink");
77
DBUG_PRINT("enter",("content: %s linkname: %s", content, linkname));
80
if (symlink(content, linkname))
85
my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno);
87
else if ((MyFlags & MY_SYNC_DIR) && my_sync_dir_by_file(linkname, MyFlags))
90
#endif /* HAVE_READLINK */
94
Resolve all symbolic links in path
95
'to' may be equal to 'filename'
97
Because purify gives a lot of UMR errors when using realpath(),
98
this code is disabled when using purify.
100
If MY_RESOLVE_LINK is given, only do realpath if the file is a link.
104
#define BUFF_LEN 4097
105
#elif defined(MAXPATHLEN)
106
#define BUFF_LEN MAXPATHLEN
108
#define BUFF_LEN FN_LEN
111
int my_realpath(char *to, const char *filename,
112
myf MyFlags __attribute__((unused)))
114
#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH)
117
struct stat stat_buff;
118
DBUG_ENTER("my_realpath");
120
if (!(MyFlags & MY_RESOLVE_LINK) ||
121
(!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
124
DBUG_PRINT("info",("executing realpath"));
125
if ((ptr=realpath(filename,buff)))
127
strmake(to,ptr,FN_REFLEN-1);
132
Realpath didn't work; Use my_load_path() which is a poor substitute
133
original name but will at least be able to resolve paths that starts
136
DBUG_PRINT("error",("realpath failed with errno: %d", errno));
138
if (MyFlags & MY_WME)
139
my_error(EE_REALPATH, MYF(0), filename, my_errno);
140
my_load_path(to, filename, NullS);
146
my_load_path(to, filename, NullS);