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