MenuItemFromPoint: rough implementation.
[wine/wine-gecko.git] / win32 / file.c
blobb37f032f1d972bd62af496e59cef02622b128768
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <errno.h>
25 #ifdef HAVE_SYS_ERRNO_H
26 #include <sys/errno.h>
27 #endif
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #ifdef HAVE_SYS_MMAN_H
33 #include <sys/mman.h>
34 #endif
35 #include <fcntl.h>
36 #include <string.h>
37 #include <time.h>
39 #include "winbase.h"
40 #include "winerror.h"
42 #include "wine/winbase16.h"
43 #include "file.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(file);
49 /**************************************************************************
50 * SetFileAttributes (KERNEL.421)
52 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
54 return SetFileAttributesA( lpFileName, attributes );
58 /**************************************************************************
59 * SetFileAttributesA (KERNEL32.@)
61 BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD attributes)
63 struct stat buf;
64 DOS_FULL_NAME full_name;
66 if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name ))
67 return FALSE;
69 TRACE("(%s,%lx)\n",lpFileName,attributes);
70 if (attributes & FILE_ATTRIBUTE_NORMAL) {
71 attributes &= ~FILE_ATTRIBUTE_NORMAL;
72 if (attributes)
73 FIXME("(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
74 lpFileName,attributes);
76 if(stat(full_name.long_name,&buf)==-1)
78 FILE_SetDosError();
79 return FALSE;
81 if (attributes & FILE_ATTRIBUTE_READONLY)
83 if(S_ISDIR(buf.st_mode))
84 /* FIXME */
85 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
86 else
87 buf.st_mode &= ~0222; /* octal!, clear write permission bits */
88 attributes &= ~FILE_ATTRIBUTE_READONLY;
90 else
92 /* add write permission */
93 buf.st_mode |= 0600 | ((buf.st_mode & 044) >> 1);
95 if (attributes & FILE_ATTRIBUTE_DIRECTORY)
97 if (!S_ISDIR(buf.st_mode))
98 FIXME("SetFileAttributes expected the file '%s' to be a directory",
99 lpFileName);
100 attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
102 attributes &= ~(FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
103 if (attributes)
104 FIXME("(%s):%lx attribute(s) not implemented.\n",
105 lpFileName,attributes);
106 if (-1==chmod(full_name.long_name,buf.st_mode))
108 if(GetDriveTypeA(lpFileName) == DRIVE_CDROM) {
109 SetLastError( ERROR_ACCESS_DENIED );
110 return FALSE;
114 * FIXME: We don't return FALSE here because of differences between
115 * Linux and Windows privileges. Under Linux only the owner of
116 * the file is allowed to change file attributes. Under Windows,
117 * applications expect that if you can write to a file, you can also
118 * change its attributes (see GENERIC_WRITE). We could try to be
119 * clever here but that would break multi-user installations where
120 * users share read-only DLLs. This is because some installers like
121 * to change attributes of already installed DLLs.
123 FIXME("Couldn't set file attributes for existing file \"%s\".\n"
124 "Check permissions or set VFAT \"quiet\" mount flag\n", full_name.long_name);
126 return TRUE;
130 /**************************************************************************
131 * SetFileAttributesW (KERNEL32.@)
133 BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD attributes)
135 BOOL res;
136 DWORD len = WideCharToMultiByte( CP_ACP, 0, lpFileName, -1, NULL, 0, NULL, NULL );
137 LPSTR afn = HeapAlloc( GetProcessHeap(), 0, len );
139 WideCharToMultiByte( CP_ACP, 0, lpFileName, -1, afn, len, NULL, NULL );
140 res = SetFileAttributesA( afn, attributes );
141 HeapFree( GetProcessHeap(), 0, afn );
142 return res;