16 #include "mysys_priv.h"
17 #include "mysys_err.h"
21 #include <sys/param.h>
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)
48 if ((my_errno=errno) == EINVAL)
57 char errbuf[MYSYS_STRERROR_SIZE];
58 my_error(EE_CANT_READLINK, MYF(0), filename,
59 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
66 DBUG_PRINT(
"exit" ,(
"result: %d", result));
74 int my_symlink(
const char *content,
const char *linkname, myf MyFlags)
80 DBUG_ENTER(
"my_symlink");
81 DBUG_PRINT(
"enter",(
"content: %s linkname: %s", content, linkname));
84 if (symlink(content, linkname))
90 char errbuf[MYSYS_STRERROR_SIZE];
91 my_error(EE_CANT_SYMLINK, MYF(0), linkname, content,
92 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
95 else if ((MyFlags & MY_SYNC_DIR) && my_sync_dir_by_file(linkname, MyFlags))
102 #define BUFF_LEN 4097
103 #elif defined(MAXPATHLEN)
104 #define BUFF_LEN MAXPATHLEN
106 #define BUFF_LEN FN_LEN
110 int my_is_symlink(
const char *filename __attribute__((unused)))
112 #if defined (HAVE_LSTAT) && defined (S_ISLNK)
113 struct stat stat_buff;
114 return !lstat(filename, &stat_buff) && S_ISLNK(stat_buff.st_mode);
115 #elif defined (_WIN32)
116 DWORD dwAttr = GetFileAttributes(filename);
117 return (dwAttr != INVALID_FILE_ATTRIBUTES) &&
118 (dwAttr & FILE_ATTRIBUTE_REPARSE_POINT);
129 int my_realpath(
char *to,
const char *filename, myf MyFlags)
131 #if defined(HAVE_REALPATH) && !defined(HAVE_BROKEN_REALPATH)
135 DBUG_ENTER(
"my_realpath");
137 DBUG_PRINT(
"info",(
"executing realpath"));
138 if ((ptr=realpath(filename,buff)))
139 strmake(to,ptr,FN_REFLEN-1);
147 DBUG_PRINT(
"error",(
"realpath failed with errno: %d", errno));
149 if (MyFlags & MY_WME)
151 char errbuf[MYSYS_STRERROR_SIZE];
152 my_error(EE_REALPATH, MYF(0), filename,
153 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
155 my_load_path(to, filename, NullS);
159 #elif defined(_WIN32)
160 int ret= GetFullPathName(filename,FN_REFLEN, to, NULL);
161 if (ret == 0 || ret > FN_REFLEN)
163 my_errno= (ret > FN_REFLEN) ? ENAMETOOLONG : GetLastError();
164 if (MyFlags & MY_WME)
166 char errbuf[MYSYS_STRERROR_SIZE];
167 my_error(EE_REALPATH, MYF(0), filename,
168 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
175 my_load_path(to, filename, NullS);
179 my_load_path(to, filename, NullS);