- Made sure that the files that contains the declarations
[wine] / win32 / file.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
5  */
6
7 #include "config.h"
8 #include "wine/port.h"
9
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>
24
25 #include "winbase.h"
26 #include "winerror.h"
27
28 #include "wine/winbase16.h"
29 #include "file.h"
30 #include "heap.h"
31
32 #include "debugtools.h"
33
34 DEFAULT_DEBUG_CHANNEL(file);
35
36 /**************************************************************************
37  *              SetFileAttributes       (KERNEL.421)
38  */
39 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
40 {
41     return SetFileAttributesA( lpFileName, attributes );
42 }
43
44
45 /**************************************************************************
46  *              SetFileAttributesA      (KERNEL32.@)
47  */
48 BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD attributes)
49 {
50     struct stat buf;
51     DOS_FULL_NAME full_name;
52
53     if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name ))
54         return FALSE;
55
56     TRACE("(%s,%lx)\n",lpFileName,attributes);
57     if (attributes & FILE_ATTRIBUTE_NORMAL) {
58       attributes &= ~FILE_ATTRIBUTE_NORMAL;
59       if (attributes)
60         FIXME("(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
61               lpFileName,attributes);
62     }
63     if(stat(full_name.long_name,&buf)==-1)
64     {
65         FILE_SetDosError();
66         return FALSE;
67     }
68     if (attributes & FILE_ATTRIBUTE_READONLY)
69     {
70         if(S_ISDIR(buf.st_mode))
71             /* FIXME */
72             WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
73         else
74             buf.st_mode &= ~0222; /* octal!, clear write permission bits */
75         attributes &= ~FILE_ATTRIBUTE_READONLY;
76     }
77     else
78     {
79         /* add write permission */
80         buf.st_mode |= 0600 | ((buf.st_mode & 044) >> 1);
81     }
82     if (attributes & FILE_ATTRIBUTE_DIRECTORY)
83     {
84         if (!S_ISDIR(buf.st_mode))
85             FIXME("SetFileAttributes expected the file '%s' to be a directory",
86                   lpFileName);
87         attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
88     }
89     attributes &= ~(FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
90     if (attributes)
91         FIXME("(%s):%lx attribute(s) not implemented.\n",
92               lpFileName,attributes);
93     if (-1==chmod(full_name.long_name,buf.st_mode))
94     {
95         FILE_SetDosError();
96         MESSAGE("Wine ERROR: Couldn't set file attributes for existing file \"%s\".\n"
97                 "Check permissions or set VFAT \"quiet\" mount flag\n", full_name.long_name);
98         return TRUE;
99     }
100     return TRUE;
101 }
102
103
104 /**************************************************************************
105  *              SetFileAttributesW      (KERNEL32.@)
106  */
107 BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD attributes)
108 {
109     LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
110     BOOL res = SetFileAttributesA( afn, attributes );
111     HeapFree( GetProcessHeap(), 0, afn );
112     return res;
113 }