Adds a warning message if permissions not sufficient.
[wine/wine64.git] / win32 / file.c
blob4e4c142efdafe4d2c0bd17febf94feab2bc80934
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
5 */
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"
26 DWORD ErrnoToLastError(int errno_num);
28 /***********************************************************************
29 * ReadFileEx (KERNEL32.)
31 typedef
32 VOID
33 (CALLBACK *LPOVERLAPPED_COMPLETION_ROUTINE)(
34 DWORD dwErrorCode,
35 DWORD dwNumberOfBytesTransfered,
36 LPOVERLAPPED lpOverlapped
39 BOOL32 WINAPI ReadFileEx(HFILE32 hFile, LPVOID lpBuffer, DWORD numtoread,
40 LPOVERLAPPED lpOverlapped,
41 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
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;
50 /**************************************************************************
51 * SetFileAttributes16 (KERNEL.421)
53 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
55 return SetFileAttributes32A( lpFileName, attributes );
59 /**************************************************************************
60 * SetFileAttributes32A (KERNEL32.490)
62 BOOL32 WINAPI SetFileAttributes32A(LPCSTR lpFileName, DWORD attributes)
64 struct stat buf;
65 DOS_FULL_NAME full_name;
67 if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name ))
68 return FALSE;
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);
77 if(stat(full_name.long_name,&buf)==-1)
79 SetLastError(ErrnoToLastError(errno));
80 return FALSE;
82 if (attributes & FILE_ATTRIBUTE_READONLY)
84 buf.st_mode &= ~0222; /* octal!, clear write permission bits */
85 attributes &= ~FILE_ATTRIBUTE_READONLY;
87 else
89 /* add write permission */
90 buf.st_mode |= 0600 | ((buf.st_mode & 044) >> 1);
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))
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;
102 return TRUE;
106 /**************************************************************************
107 * SetFileAttributes32W (KERNEL32.491)
109 BOOL32 WINAPI SetFileAttributes32W(LPCWSTR lpFileName, DWORD attributes)
111 LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
112 BOOL32 res = SetFileAttributes32A( afn, attributes );
113 HeapFree( GetProcessHeap(), 0, afn );
114 return res;
118 /**************************************************************************
119 * SetFileApisToOEM (KERNEL32.645)
121 VOID WINAPI SetFileApisToOEM(void)
123 /*FIXME(file,"(): stub!\n");*/
127 /**************************************************************************
128 * SetFileApisToANSI (KERNEL32.644)
130 VOID WINAPI SetFileApisToANSI(void)
132 /*FIXME(file,"(): stub\n");*/
136 /******************************************************************************
137 * AreFileApisANSI [KERNEL32.105] Determines if file functions are using ANSI
139 * RETURNS
140 * TRUE: Set of file functions is using ANSI code page
141 * FALSE: Set of file functions is using OEM code page
143 BOOL32 WINAPI AreFileApisANSI(void)
145 FIXME(file,"(void): stub\n");
146 return TRUE;