- New implementation of SendMessage, ReceiveMessage, ReplyMessage functions
[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 <errno.h>
8 #include <sys/errno.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <sys/mman.h>
14 #include <fcntl.h>
15 #include <string.h>
16 #include <time.h>
17 #include "windows.h"
18 #include "winbase.h"
19 #include "winerror.h"
20 #include "file.h"
21 #include "device.h"
22 #include "process.h"
23 #include "heap.h"
24 #include "debug.h"
25
26 DWORD ErrnoToLastError(int errno_num);
27
28 /***********************************************************************
29  *              ReadFileEx                (KERNEL32.)
30  */
31 typedef
32 VOID
33 (CALLBACK *LPOVERLAPPED_COMPLETION_ROUTINE)(
34     DWORD dwErrorCode,
35     DWORD dwNumberOfBytesTransfered,
36     LPOVERLAPPED lpOverlapped
37     );
38
39 BOOL32 WINAPI ReadFileEx(HFILE32 hFile, LPVOID lpBuffer, DWORD numtoread,
40                          LPOVERLAPPED lpOverlapped, 
41                          LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
42 {
43
44     FIXME(file, "file %d to buf %p num %ld %p func %p stub\n",
45           hFile, lpBuffer, numtoread, lpOverlapped, lpCompletionRoutine);
46     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
47     return 0;
48 }
49
50 /**************************************************************************
51  *              SetFileAttributes16     (KERNEL.421)
52  */
53 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
54 {
55     return SetFileAttributes32A( lpFileName, attributes );
56 }
57
58
59 /**************************************************************************
60  *              SetFileAttributes32A    (KERNEL32.490)
61  */
62 BOOL32 WINAPI SetFileAttributes32A(LPCSTR lpFileName, DWORD attributes)
63 {
64     struct stat buf;
65     DOS_FULL_NAME full_name;
66
67     if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name ))
68         return FALSE;
69
70     TRACE(file,"(%s,%lx)\n",lpFileName,attributes);
71     if (attributes & FILE_ATTRIBUTE_NORMAL) {
72       attributes &= ~FILE_ATTRIBUTE_NORMAL;
73       if (attributes)
74         FIXME(file,"(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
75               lpFileName,attributes);
76     }
77     if(stat(full_name.long_name,&buf)==-1)
78     {
79         SetLastError(ErrnoToLastError(errno));
80         return FALSE;
81     }
82     if (attributes & FILE_ATTRIBUTE_READONLY)
83     {
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     attributes &= ~(FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
93     if (attributes)
94         FIXME(file,"(%s):%lx attribute(s) not implemented.\n",
95               lpFileName,attributes);
96     if (-1==chmod(full_name.long_name,buf.st_mode))
97     {
98         MSG("Wine ERROR: Couldn't set file attributes for existing file \"%s\". Check permissions !\n", full_name.long_name);
99         SetLastError(ErrnoToLastError(errno));
100         return FALSE;
101     }
102     return TRUE;
103 }
104
105
106 /**************************************************************************
107  *              SetFileAttributes32W    (KERNEL32.491)
108  */
109 BOOL32 WINAPI SetFileAttributes32W(LPCWSTR lpFileName, DWORD attributes)
110 {
111     LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
112     BOOL32 res = SetFileAttributes32A( afn, attributes );
113     HeapFree( GetProcessHeap(), 0, afn );
114     return res;
115 }
116
117
118 /**************************************************************************
119  *              SetFileApisToOEM   (KERNEL32.645)
120  */
121 VOID WINAPI SetFileApisToOEM(void)
122 {
123   /*FIXME(file,"(): stub!\n");*/
124 }
125
126
127 /**************************************************************************
128  *              SetFileApisToANSI   (KERNEL32.644)
129  */
130 VOID WINAPI SetFileApisToANSI(void)
131 {
132     /*FIXME(file,"(): stub\n");*/
133 }
134
135
136 /******************************************************************************
137  * AreFileApisANSI [KERNEL32.105]  Determines if file functions are using ANSI
138  *
139  * RETURNS
140  *    TRUE:  Set of file functions is using ANSI code page
141  *    FALSE: Set of file functions is using OEM code page
142  */
143 BOOL32 WINAPI AreFileApisANSI(void)
144 {
145     FIXME(file,"(void): stub\n");
146     return TRUE;
147 }
148