Fix return value of GetWindowsDirectoryA/W and GetSystemDirectoryA/W.
[wine/wine-kai.git] / win32 / file.c
blobd390be1ac50c18682a42f155143d59c87fa2fa20
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
5 */
7 #include "config.h"
8 #include "wine/port.h"
10 #include <errno.h>
11 #ifdef HAVE_SYS_ERRNO_H
12 #include <sys/errno.h>
13 #endif
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #ifdef HAVE_SYS_MMAN_H
19 #include <sys/mman.h>
20 #endif
21 #include <fcntl.h>
22 #include <string.h>
23 #include <time.h>
25 #include "winbase.h"
26 #include "winerror.h"
28 #include "wine/winbase16.h"
29 #include "file.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)
49 struct stat buf;
50 DOS_FULL_NAME full_name;
52 if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name ))
53 return FALSE;
55 TRACE("(%s,%lx)\n",lpFileName,attributes);
56 if (attributes & FILE_ATTRIBUTE_NORMAL) {
57 attributes &= ~FILE_ATTRIBUTE_NORMAL;
58 if (attributes)
59 FIXME("(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
60 lpFileName,attributes);
62 if(stat(full_name.long_name,&buf)==-1)
64 FILE_SetDosError();
65 return FALSE;
67 if (attributes & FILE_ATTRIBUTE_READONLY)
69 if(S_ISDIR(buf.st_mode))
70 /* FIXME */
71 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
72 else
73 buf.st_mode &= ~0222; /* octal!, clear write permission bits */
74 attributes &= ~FILE_ATTRIBUTE_READONLY;
76 else
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",
85 lpFileName);
86 attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
88 attributes &= ~(FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
89 if (attributes)
90 FIXME("(%s):%lx attribute(s) not implemented.\n",
91 lpFileName,attributes);
92 if (-1==chmod(full_name.long_name,buf.st_mode))
94 FILE_SetDosError();
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);
97 return TRUE;
99 return TRUE;
103 /**************************************************************************
104 * SetFileAttributesW (KERNEL32.@)
106 BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD attributes)
108 BOOL res;
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 );
115 return res;