Added an unknown VxD error code.
[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 #include "winbase.h"
25 #include "winerror.h"
26 #include "file.h"
27 #include "heap.h"
28 #include "debugtools.h"
29
30 DEFAULT_DEBUG_CHANNEL(file);
31
32 /***********************************************************************
33  *              ReadFileEx                (KERNEL32.@)
34  */
35 BOOL WINAPI ReadFileEx(HFILE hFile, LPVOID lpBuffer, DWORD numtoread,
36                          LPOVERLAPPED lpOverlapped, 
37                          LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
38 {
39
40     FIXME("file %d to buf %p num %ld %p func %p stub\n",
41           hFile, lpBuffer, numtoread, lpOverlapped, lpCompletionRoutine);
42     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
43     return 0;
44 }
45
46 /**************************************************************************
47  *              SetFileAttributes       (KERNEL.421)
48  */
49 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
50 {
51     return SetFileAttributesA( lpFileName, attributes );
52 }
53
54
55 /**************************************************************************
56  *              SetFileAttributesA      (KERNEL32.@)
57  */
58 BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD attributes)
59 {
60     struct stat64 buf;
61     DOS_FULL_NAME full_name;
62
63     if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name ))
64         return FALSE;
65
66     TRACE("(%s,%lx)\n",lpFileName,attributes);
67     if (attributes & FILE_ATTRIBUTE_NORMAL) {
68       attributes &= ~FILE_ATTRIBUTE_NORMAL;
69       if (attributes)
70         FIXME("(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
71               lpFileName,attributes);
72     }
73     if(stat64(full_name.long_name,&buf)==-1)
74     {
75         FILE_SetDosError();
76         return FALSE;
77     }
78     if (attributes & FILE_ATTRIBUTE_READONLY)
79     {
80         if(S_ISDIR(buf.st_mode))
81             /* FIXME */
82             WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
83         else
84             buf.st_mode &= ~0222; /* octal!, clear write permission bits */
85         attributes &= ~FILE_ATTRIBUTE_READONLY;
86     }
87     else
88     {
89         /* add write permission */
90         buf.st_mode |= 0600 | ((buf.st_mode & 044) >> 1);
91     }
92     if (attributes & FILE_ATTRIBUTE_DIRECTORY)
93     {
94         if (!S_ISDIR(buf.st_mode))
95             FIXME("SetFileAttributes expected the file '%s' to be a directory",
96                   lpFileName);
97         attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
98     }
99     attributes &= ~(FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
100     if (attributes)
101         FIXME("(%s):%lx attribute(s) not implemented.\n",
102               lpFileName,attributes);
103     if (-1==chmod(full_name.long_name,buf.st_mode))
104     {
105         FILE_SetDosError();
106         MESSAGE("Wine ERROR: Couldn't set file attributes for existing file \"%s\". Check permissions or set VFAT \"quiet\" flag !\n", full_name.long_name);
107         return TRUE;
108     }
109     return TRUE;
110 }
111
112
113 /**************************************************************************
114  *              SetFileAttributesW      (KERNEL32.@)
115  */
116 BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD attributes)
117 {
118     LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
119     BOOL res = SetFileAttributesA( afn, attributes );
120     HeapFree( GetProcessHeap(), 0, afn );
121     return res;
122 }