我正在使用帖子592448中显示的代码示例来尝试授予完整文件权限。当我使用以下代码编译代码片段时:
gcc -shared -mno-cygwin -Wall -o native.dll native.c
我得到以下错误:
native.c:8: error: conflicting types for 'mode_t'
/usr/i686-pc-mingw32/sys-root/mingw/include/sys/types.h:99: error: previous declaration of 'mode_t' was here
native.c:21: error: parse error before numeric constant
native.c:22: error: parse error before numeric constant
native.c:23: error: parse error before numeric constant
native.c:25: error: parse error before "mode_t"
native.c:26: error: parse error before "mode_t"
native.c:28: error: parse error before "mode_t"
native.c:29: error: parse error before "mode_t"
我剥离了代码以减少到下面,它编译得很好,但似乎没有根据需要更改文件权限。
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#ifdef _WIN32
# include <io.h>
typedef signed int md_t;
static const md_t MS_MODE_MASK = 0x0000ffff; ///< low word
int fchmod(const char * path, md_t mode)
{
int result = _chmod(path, (mode & MS_MODE_MASK));
if (result != 0)
{
result = errno;
}
return (result);
}
#else
int fchmod(const char * path, md_t mode)
{
int result = chmod(path, mode);
if (result != 0)
{
result = errno;
}
return (result);
}
#endif
关于如何使它工作的任何指示?