1 /************************************************************************
2 * FILE.C Copyright (C) 1993 John Burton
4 * File I/O routines for the Linux Wine Project.
6 * WARNING : Many options of OpenFile are not yet implemeted.
8 * NOV 93 Erik Bos (erik@(trashcan.)hacktic.nl
9 * - removed ParseDosFileName, and DosDrive structures.
10 * - structures dynamically configured at runtime.
11 * - _lopen modified to use GetUnixFileName.
13 * DEC 93 Erik Bos (erik@(trashcan.)hacktic.nl)
14 * - Existing functions modified to use dosfs functions.
15 * - Added _llseek, _lcreate, GetDriveType, GetTempDrive,
16 * GetWindowsDirectory, GetSystemDirectory, GetTempFileName.
18 ************************************************************************/
26 #include "prototypes.h"
28 char WindowsDirectory
[256], SystemDirectory
[256], TempDirectory
[256];
31 /***************************************************************************
34 Emulate the _lopen windows call
35 ***************************************************************************/
36 WORD
KERNEL__lopen (LPSTR lpPathName
, WORD iReadWrite
)
42 fprintf (stderr
, "_lopen: open %s\n", lpPathName
);
45 if ((UnixFileName
= GetUnixFileName(lpPathName
)) == NULL
)
48 handle
= open (UnixFileName
, iReadWrite
);
51 fprintf (stderr
, "_lopen: open: %s (handle %d)\n", UnixFileName
, handle
);
60 /***************************************************************************
62 ***************************************************************************/
63 WORD
KERNEL__lread (WORD hFile
, LPSTR lpBuffer
, WORD wBytes
)
68 fprintf(stderr
, "_lread: handle %d, buffer = %ld, length = %d\n",
69 hFile
, lpBuffer
, wBytes
);
72 result
= read (hFile
, lpBuffer
, wBytes
);
80 /****************************************************************************
82 ****************************************************************************/
83 WORD
KERNEL__lwrite (WORD hFile
, LPSTR lpBuffer
, WORD wBytes
)
88 fprintf(stderr
, "_lwrite: handle %d, buffer = %ld, length = %d\n",
89 hFile
, lpBuffer
, wBytes
);
91 result
= write (hFile
, lpBuffer
, wBytes
);
99 /***************************************************************************
101 ***************************************************************************/
102 WORD
KERNEL__lclose (WORD hFile
)
105 fprintf(stderr
, "_lclose: handle %d\n", hFile
);
111 /**************************************************************************
114 Warning: This is nearly totally untested. It compiles, that's it...
116 **************************************************************************/
117 WORD
KERNEL_OpenFile (LPSTR lpFileName
, LPOFSTRUCT ofs
, WORD wStyle
)
122 fprintf(stderr
,"Openfile(%s,<struct>,%d) ",lpFileName
,wStyle
);
128 flags
&=0xFF0F; /* strip SHARE bits for now */
129 flags
&=0xD7FF; /* strip PROMPT & CANCEL bits for now */
130 flags
&=0x7FFF; /* strip REOPEN bit for now */
131 flags
&=0xFBFF; /* strib VERIFY bit for now */
133 if(flags
&OF_CREATE
) { base
|=O_CREAT
; flags
&=0xEFFF; }
135 fprintf(stderr
,"now %d,%d\n",base
,flags
);
137 if(flags
&(OF_DELETE
|OF_EXIST
))
139 fprintf(stderr
,"Unsupported OpenFile option\n");
144 return KERNEL__lopen (lpFileName
, wStyle
);
148 /**************************************************************************
151 Changes the number of file handles available to the application. Since
152 Linux isn't limited to 20 files, this one's easy. - SL
153 **************************************************************************/
155 WORD
SetHandleCount (WORD wNumber
)
157 printf("SetHandleCount(%d)\n",wNumber
);
158 return((wNumber
<OPEN_MAX
) ? wNumber
: OPEN_MAX
);
161 /***************************************************************************
163 ***************************************************************************/
164 LONG
KERNEL__llseek (WORD hFile
, LONG lOffset
, int nOrigin
)
169 fprintf(stderr
, "_llseek: handle %d, offset %ld, origin %d\n", hFile
, lOffset
, nOrigin
);
173 case 1: origin
= SEEK_CUR
;
175 case 2: origin
= SEEK_END
;
177 default: origin
= SEEK_SET
;
181 return ( lseek(hFile
, lOffset
, origin
) );
184 /***************************************************************************
186 ***************************************************************************/
187 LONG
KERNEL__lcreate (LPSTR lpszFilename
, int fnAttribute
)
193 fprintf(stderr
, "_lcreate: filename %s, attributes %d\n",lpszFilename
,
197 if ((UnixFileName
= GetUnixFileName(lpszFilename
)) == NULL
)
200 handle
= open (UnixFileName
, O_CREAT
| O_TRUNC
| O_WRONLY
);
208 /***************************************************************************
210 ***************************************************************************/
211 UINT
GetDriveType(int drive
)
215 fprintf(stderr
,"GetDriveType %c:\n",'A'+drive
);
218 if (!DOS_ValidDrive(drive
))
221 if (drive
== 0 || drive
== 1)
222 return DRIVE_REMOVABLE
;
227 /***************************************************************************
229 ***************************************************************************/
230 BYTE
GetTempDrive(BYTE chDriveLetter
)
233 fprintf(stderr
,"GetTempDrive (%d)\n",chDriveLetter
);
238 /***************************************************************************
240 ***************************************************************************/
241 UINT
GetWindowsDirectory(LPSTR lpszSysPath
, UINT cbSysPath
)
243 if (cbSysPath
< strlen(WindowsDirectory
))
246 strcpy(lpszSysPath
, WindowsDirectory
);
249 fprintf(stderr
,"GetWindowsDirectory (%s)\n",lpszSysPath
);
252 return(strlen(lpszSysPath
));
254 /***************************************************************************
256 ***************************************************************************/
257 UINT
GetSystemDirectory(LPSTR lpszSysPath
, UINT cbSysPath
)
259 if (cbSysPath
< strlen(SystemDirectory
))
262 strcpy(lpszSysPath
, SystemDirectory
);
265 fprintf(stderr
,"GetSystemDirectory (%s)\n",lpszSysPath
);
268 return(strlen(lpszSysPath
));
270 /***************************************************************************
272 ***************************************************************************/
273 int GetTempFileName(BYTE bDriveLetter
, LPCSTR lpszPrefixString
, UINT uUnique
, LPSTR lpszTempFileName
)
279 unique
= time(NULL
)%99999L;
281 unique
= uUnique
%99999L;
283 strcpy(tempname
,lpszPrefixString
);
286 sprintf(lpszTempFileName
,"%s\%s%d.tmp",WindowsDirectory
, tempname
,
289 ToDos(lpszTempFileName
);
292 fprintf(stderr
,"GetTempFilename: %c %s %d => %s\n",bDriveLetter
,
293 lpszPrefixString
,uUnique
,lpszTempFileName
);
299 /***************************************************************************
301 ***************************************************************************/
302 WORD
SetErrorMode(WORD x
)
304 fprintf(stderr
,"wine: SetErrorMode %4x (ignored)\n",x
);