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 ************************************************************************/
28 #include "prototypes.h"
30 char WindowsDirectory
[256], SystemDirectory
[256], TempDirectory
[256];
32 /***************************************************************************
35 Emulate the _lopen windows call
36 ***************************************************************************/
37 int _lopen (LPSTR lpPathName
, int iReadWrite
)
43 fprintf (stderr
, "_lopen: open('%s', %X);\n", lpPathName
, iReadWrite
);
46 if ((UnixFileName
= GetUnixFileName(lpPathName
)) == NULL
)
49 handle
= open (UnixFileName
, iReadWrite
);
52 fprintf (stderr
, "_lopen: open: %s (handle %d)\n", UnixFileName
, handle
);
61 /***************************************************************************
63 ***************************************************************************/
64 WORD
_lread (int hFile
, LPSTR lpBuffer
, int wBytes
)
69 fprintf(stderr
, "_lread: handle %d, buffer = %ld, length = %d\n",
70 hFile
, (int) lpBuffer
, wBytes
);
73 result
= read (hFile
, lpBuffer
, wBytes
);
81 /****************************************************************************
83 ****************************************************************************/
84 WORD
_lwrite (int hFile
, LPSTR lpBuffer
, int wBytes
)
89 fprintf(stderr
, "_lwrite: handle %d, buffer = %ld, length = %d\n",
90 hFile
, (int) lpBuffer
, wBytes
);
92 result
= write (hFile
, lpBuffer
, wBytes
);
100 /***************************************************************************
102 ***************************************************************************/
103 int _lclose (int hFile
)
106 fprintf(stderr
, "_lclose: handle %d\n", hFile
);
114 /**************************************************************************
117 Warning: This is nearly totally untested. It compiles, that's it...
119 **************************************************************************/
120 int OpenFile (LPSTR lpFileName
, LPOFSTRUCT ofs
, WORD wStyle
)
125 fprintf(stderr
,"Openfile(%s,<struct>,%d) ",lpFileName
,wStyle
);
131 flags
&=0xFF0F; /* strip SHARE bits for now */
132 flags
&=0xD7FF; /* strip PROMPT & CANCEL bits for now */
133 flags
&=0x7FFF; /* strip REOPEN bit for now */
134 flags
&=0xFBFF; /* strib VERIFY bit for now */
136 if(flags
&OF_CREATE
) { base
|=O_CREAT
; flags
&=0xEFFF; }
138 fprintf(stderr
,"now %d,%d\n",base
,flags
);
140 if(flags
&(OF_DELETE
|OF_EXIST
))
142 fprintf(stderr
,"Unsupported OpenFile option\n");
147 return _lopen (lpFileName
, wStyle
);
151 /**************************************************************************
154 Changes the number of file handles available to the application. Since
155 Linux isn't limited to 20 files, this one's easy. - SL
156 **************************************************************************/
158 #if !defined (OPEN_MAX)
159 /* This one is for the Sun */
160 #define OPEN_MAX _POSIX_OPEN_MAX
162 WORD
SetHandleCount (WORD wNumber
)
164 printf("SetHandleCount(%d)\n",wNumber
);
165 return((wNumber
<OPEN_MAX
) ? wNumber
: OPEN_MAX
);
168 /***************************************************************************
170 ***************************************************************************/
171 LONG
_llseek (int hFile
, LONG lOffset
, int nOrigin
)
176 fprintf(stderr
, "_llseek: handle %d, offset %ld, origin %d\n", hFile
, lOffset
, nOrigin
);
180 case 1: origin
= SEEK_CUR
;
182 case 2: origin
= SEEK_END
;
184 default: origin
= SEEK_SET
;
188 return ( lseek(hFile
, lOffset
, origin
) );
191 /***************************************************************************
193 ***************************************************************************/
194 LONG
_lcreate (LPSTR lpszFilename
, int fnAttribute
)
200 fprintf(stderr
, "_lcreate: filename %s, attributes %d\n",lpszFilename
,
204 if ((UnixFileName
= GetUnixFileName(lpszFilename
)) == NULL
)
207 handle
= open (UnixFileName
, O_CREAT
| O_TRUNC
| O_WRONLY
);
215 /***************************************************************************
217 ***************************************************************************/
218 UINT
GetDriveType(int drive
)
222 fprintf(stderr
,"GetDriveType %c:\n",'A'+drive
);
225 if (!DOS_ValidDrive(drive
))
226 return DRIVE_DOESNOTEXIST
;
228 if (drive
== 0 || drive
== 1)
229 return DRIVE_REMOVABLE
;
231 return DRIVE_REMOVABLE
;
234 /***************************************************************************
236 ***************************************************************************/
237 BYTE
GetTempDrive(BYTE chDriveLetter
)
240 fprintf(stderr
,"GetTempDrive (%d)\n",chDriveLetter
);
245 /***************************************************************************
247 ***************************************************************************/
248 UINT
GetWindowsDirectory(LPSTR lpszSysPath
, UINT cbSysPath
)
250 if (cbSysPath
< strlen(WindowsDirectory
))
253 strcpy(lpszSysPath
, WindowsDirectory
);
256 fprintf(stderr
,"GetWindowsDirectory (%s)\n",lpszSysPath
);
259 ChopOffSlash(lpszSysPath
);
260 return(strlen(lpszSysPath
));
262 /***************************************************************************
264 ***************************************************************************/
265 UINT
GetSystemDirectory(LPSTR lpszSysPath
, UINT cbSysPath
)
267 if (cbSysPath
< strlen(SystemDirectory
))
270 strcpy(lpszSysPath
, SystemDirectory
);
273 fprintf(stderr
,"GetSystemDirectory (%s)\n",lpszSysPath
);
276 ChopOffSlash(lpszSysPath
);
277 return(strlen(lpszSysPath
));
279 /***************************************************************************
281 ***************************************************************************/
282 int GetTempFileName(BYTE bDriveLetter
, LPCSTR lpszPrefixString
, UINT uUnique
, LPSTR lpszTempFileName
)
288 unique
= time(NULL
)%99999L;
290 unique
= uUnique
%99999L;
292 strcpy(tempname
,lpszPrefixString
);
295 sprintf(lpszTempFileName
,"%s\\%s%d.tmp",WindowsDirectory
, tempname
,
298 ToDos(lpszTempFileName
);
301 fprintf(stderr
,"GetTempFilename: %c %s %d => %s\n",bDriveLetter
,
302 lpszPrefixString
,uUnique
,lpszTempFileName
);
308 /***************************************************************************
310 ***************************************************************************/
311 WORD
SetErrorMode(WORD x
)
313 fprintf(stderr
,"wine: SetErrorMode %4x (ignored)\n",x
);
316 /***************************************************************************
318 ***************************************************************************/
319 long _hread(int hf
, void FAR
*hpvBuffer
, long cbBuffer
)
326 size
= cbBuffer
< 30000 ? cbBuffer
: 30000;
328 status
= read(hf
, hpvBuffer
, size
);
340 /***************************************************************************
342 ***************************************************************************/
343 long _hwrite(int hf
, const void FAR
*hpvBuffer
, long cbBuffer
)
345 long datawritten
= 0;
350 size
= cbBuffer
< 30000 ? cbBuffer
: 30000;
352 status
= write(hf
, hpvBuffer
, size
);
358 datawritten
+= status
;