Added link() Support
- Added link() support using the CreateHardLink() function. - Made readlink() and link() declarations consistent with other functions.
This commit is contained in:
parent
c1aaa5d5a3
commit
296c6934bc
|
@ -1204,3 +1204,36 @@ cleanup:
|
||||||
free(resolved_utf16);
|
free(resolved_utf16);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
fileio_link(const char *oldpath, const char *newpath)
|
||||||
|
{
|
||||||
|
if (oldpath == NULL || newpath == NULL) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD ret = 0;
|
||||||
|
wchar_t *oldpath_utf16 = utf8_to_utf16(resolved_path(oldpath));
|
||||||
|
wchar_t *newpath_utf16 = utf8_to_utf16(resolved_path(newpath));
|
||||||
|
if (oldpath_utf16 == NULL || newpath_utf16 == NULL) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CreateHardLinkW(newpath_utf16, oldpath_utf16, NULL) == 0) {
|
||||||
|
errno = errno_from_Win32LastError();
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
|
||||||
|
if (oldpath_utf16)
|
||||||
|
free(oldpath_utf16);
|
||||||
|
if (newpath_utf16)
|
||||||
|
free(newpath_utf16);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -76,11 +76,14 @@ int w32_chdir(const char *dirname);
|
||||||
char *w32_getcwd(char *buffer, int maxlen);
|
char *w32_getcwd(char *buffer, int maxlen);
|
||||||
#define getcwd w32_getcwd
|
#define getcwd w32_getcwd
|
||||||
|
|
||||||
|
int w32_readlink(const char *path, char *link, int linklen);
|
||||||
|
#define readlink w32_readlink
|
||||||
|
|
||||||
|
int w32_link(const char *oldpath, const char *newpath);
|
||||||
|
#define link w32_link
|
||||||
|
|
||||||
int daemon(int nochdir, int noclose);
|
int daemon(int nochdir, int noclose);
|
||||||
char *crypt(const char *key, const char *salt);
|
char *crypt(const char *key, const char *salt);
|
||||||
int link(const char *oldpath, const char *newpath);
|
|
||||||
int readlink(const char *path, char *link, int linklen);
|
|
||||||
|
|
||||||
int chroot(const char *path);
|
int chroot(const char *path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -661,11 +661,9 @@ w32_symlink(const char *target, const char *linkpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
link(const char *oldpath, const char *newpath)
|
w32_link(const char *oldpath, const char *newpath)
|
||||||
{
|
{
|
||||||
/* Not supported in windows */
|
return fileio_link(oldpath, newpath);
|
||||||
errno = EOPNOTSUPP;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -831,7 +829,7 @@ w32_lstat(const char *input_path, struct w32_stat *buf)
|
||||||
|
|
||||||
/* if file is symbolic link, copy its link into "link" */
|
/* if file is symbolic link, copy its link into "link" */
|
||||||
int
|
int
|
||||||
readlink(const char *path, char *link, int linklen)
|
w32_readlink(const char *path, char *link, int linklen)
|
||||||
{
|
{
|
||||||
return fileio_readlink(resolved_path(path), link, linklen);
|
return fileio_readlink(resolved_path(path), link, linklen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,4 +165,5 @@ int fileio_lstat(const char *path, struct _stat64 *buf);
|
||||||
long fileio_lseek(struct w32_io* pio, unsigned __int64 offset, int origin);
|
long fileio_lseek(struct w32_io* pio, unsigned __int64 offset, int origin);
|
||||||
FILE* fileio_fdopen(struct w32_io* pio, const char *mode);
|
FILE* fileio_fdopen(struct w32_io* pio, const char *mode);
|
||||||
ssize_t fileio_readlink(const char *path, char *buf, size_t bufsiz);
|
ssize_t fileio_readlink(const char *path, char *buf, size_t bufsiz);
|
||||||
int fileio_symlink(const char *target, const char *linkpath);
|
int fileio_symlink(const char *target, const char *linkpath);
|
||||||
|
int fileio_link(const char *oldpath, const char *newpath);
|
Loading…
Reference in New Issue