mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
Added c_rename function to do platform specific renaming.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
parent
390a307840
commit
0bc0181f91
2 changed files with 32 additions and 1 deletions
|
@ -160,3 +160,23 @@ out:
|
|||
#endif
|
||||
}
|
||||
|
||||
int c_rename( const char *src, const char *dst ) {
|
||||
mbchar_t *nuri = c_multibyte(dst);
|
||||
mbchar_t *ouri = c_multibyte(src);
|
||||
|
||||
#ifdef _WIN32
|
||||
if(ouri && nuri) {
|
||||
if (MoveFileExW(ouri, nuri, MOVEFILE_COPY_ALLOWED + MOVEFILE_REPLACE_EXISTING + MOVEFILE_WRITE_THROUGH )) {
|
||||
return 0;
|
||||
}
|
||||
errno = GetLastError();
|
||||
} else {
|
||||
errno = ENOENT;
|
||||
}
|
||||
#else
|
||||
return rename(ouri, nuri);
|
||||
#endif
|
||||
c_free_multibyte(nuri);
|
||||
c_free_multibyte(ouri);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#define _C_FILE_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef BUFFER_SIZE
|
||||
#define BUFFER_SIZE (16 * 1024)
|
||||
|
@ -58,11 +59,21 @@ int c_isfile(const char *path);
|
|||
* @param mode File creation mode of the destination. If mode is 0 then the
|
||||
* mode from the source will be used.
|
||||
*
|
||||
* @return 0 on success, less then 0 on error with errno set.
|
||||
* @return 0 on success, less than 0 on error with errno set.
|
||||
* EISDIR if src or dst is a file.
|
||||
*/
|
||||
int c_copy(const char *src, const char *dst, mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief move a file from source to destination.
|
||||
*
|
||||
* @param src Path to the source file
|
||||
* @param dst Path to the destination file
|
||||
*
|
||||
* @return 0 on success, less than 0 on error with errno set.
|
||||
*/
|
||||
int c_rename( const char *src, const char *dst );
|
||||
|
||||
/**
|
||||
* }@
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue