2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
11 #ifdef HAVE_SYS_ERRNO_H
12 #include <sys/errno.h>
16 #include <sys/types.h>
18 #ifdef HAVE_SYS_MMAN_H
28 #include "wine/winbase16.h"
31 #include "debugtools.h"
33 DEFAULT_DEBUG_CHANNEL(file
);
35 /**************************************************************************
36 * SetFileAttributes (KERNEL.421)
38 BOOL16 WINAPI
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
40 return SetFileAttributesA( lpFileName
, attributes
);
44 /**************************************************************************
45 * SetFileAttributesA (KERNEL32.@)
47 BOOL WINAPI
SetFileAttributesA(LPCSTR lpFileName
, DWORD attributes
)
50 DOS_FULL_NAME full_name
;
52 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
))
55 TRACE("(%s,%lx)\n",lpFileName
,attributes
);
56 if (attributes
& FILE_ATTRIBUTE_NORMAL
) {
57 attributes
&= ~FILE_ATTRIBUTE_NORMAL
;
59 FIXME("(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
60 lpFileName
,attributes
);
62 if(stat(full_name
.long_name
,&buf
)==-1)
67 if (attributes
& FILE_ATTRIBUTE_READONLY
)
69 if(S_ISDIR(buf
.st_mode
))
71 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
73 buf
.st_mode
&= ~0222; /* octal!, clear write permission bits */
74 attributes
&= ~FILE_ATTRIBUTE_READONLY
;
78 /* add write permission */
79 buf
.st_mode
|= 0600 | ((buf
.st_mode
& 044) >> 1);
81 if (attributes
& FILE_ATTRIBUTE_DIRECTORY
)
83 if (!S_ISDIR(buf
.st_mode
))
84 FIXME("SetFileAttributes expected the file '%s' to be a directory",
86 attributes
&= ~FILE_ATTRIBUTE_DIRECTORY
;
88 attributes
&= ~(FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
90 FIXME("(%s):%lx attribute(s) not implemented.\n",
91 lpFileName
,attributes
);
92 if (-1==chmod(full_name
.long_name
,buf
.st_mode
))
95 MESSAGE("Wine ERROR: Couldn't set file attributes for existing file \"%s\".\n"
96 "Check permissions or set VFAT \"quiet\" mount flag\n", full_name
.long_name
);
103 /**************************************************************************
104 * SetFileAttributesW (KERNEL32.@)
106 BOOL WINAPI
SetFileAttributesW(LPCWSTR lpFileName
, DWORD attributes
)
109 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, lpFileName
, -1, NULL
, 0, NULL
, NULL
);
110 LPSTR afn
= HeapAlloc( GetProcessHeap(), 0, len
);
112 WideCharToMultiByte( CP_ACP
, 0, lpFileName
, -1, afn
, len
, NULL
, NULL
);
113 res
= SetFileAttributesA( afn
, attributes
);
114 HeapFree( GetProcessHeap(), 0, afn
);