Rev 193 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
2 | This file is part of a common library |
||
3 | Copyright (C) 2002-7 Toby Thain, toby@telegraphics.com.au |
||
4 | |||
5 | This program is free software; you can redistribute it and/or modify |
||
6 | it under the terms of the GNU General Public License as published by |
||
7 | the Free Software Foundation; either version 2 of the License, or |
||
8 | (at your option) any later version. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | GNU General Public License for more details. |
||
14 | |||
15 | You should have received a copy of the GNU General Public License |
||
16 | along with this program; if not, write to the Free Software |
||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | */ |
||
19 | |||
20 | #include <stdio.h> |
||
21 | |||
22 | #include "file_compat.h" |
||
23 | #include "str.h" |
||
24 | |||
25 | OSErr FSWrite(FILEREF refNum, long *count, const void *buffPtr){ |
||
26 | long n = *count; |
||
27 | *count = fwrite(buffPtr,1,*count,refNum); |
||
28 | return *count == n ? noErr : ioErr ; |
||
29 | } |
||
30 | OSErr FSRead(FILEREF refNum, long *count, void *buffPtr){ |
||
31 | long n = *count; |
||
32 | *count = fread(buffPtr,1,*count,refNum); |
||
33 | return *count == n ? noErr : ioErr ; |
||
34 | } |
||
35 | |||
36 | OSErr FSClose(FILEREF refNum){ |
||
37 | return fclose(refNum) ? noErr : ioErr ; |
||
38 | } |
||
39 | |||
40 | OSErr GetFPos(FILEREF refNum, FILEPOS *filePos){ |
||
41 | *filePos = ftell(refNum); |
||
42 | return noErr; |
||
43 | } |
||
44 | |||
45 | OSErr SetFPos(FILEREF refNum, short posMode, long posOff){ |
||
46 | int whence[] = {0,SEEK_SET,SEEK_END,SEEK_CUR}; |
||
47 | return fseek(refNum,posOff,whence[posMode]) ? ioErr : noErr; |
||
48 | } |
||
49 | |||
50 | #if 0 |
||
51 | OSErr FSpOpenDF(const FSSpec *spec, int8 permission, FILEREF *refNum){ |
||
52 | DWORD perm[] = {GENERIC_READ|GENERIC_WRITE,GENERIC_READ,GENERIC_WRITE,GENERIC_READ|GENERIC_WRITE}; |
||
53 | |||
54 | myp2cstr((StringPtr)spec->name); |
||
55 | *refNum = CreateFile((char*)spec->name,perm[permission],0,0,OPEN_EXISTING,0,0); |
||
56 | // sprintf(s,"FSpOpenDF(\"%s\",\"%s\"):%#x",spec->name,perm[permission],*refNum); dbg(s); |
||
57 | myc2pstr((char*)spec->name); |
||
58 | return *refNum == INVALID_HANDLE_VALUE ? ioErr : noErr ; |
||
59 | } |
||
60 | /* |
||
61 | OSErr FSpOpenDF(const FSSpec *spec, int8 permission, FILEREF *refNum){ |
||
62 | char *perm[] = {"wb+","rb","wb","rwb"}; |
||
63 | OSErr e; |
||
64 | |||
65 | myp2cstr((unsigned char*)spec->name); |
||
66 | e = (*refNum = fopen(spec->name,perm[permission])) ? noErr : ioErr; |
||
67 | sprintf(s,"FSpOpenDF(\"%s\",\"%s\"):%#x",spec->name,perm[permission],*refNum); dbg(s); |
||
68 | myc2pstr(spec->name); |
||
69 | return e; |
||
70 | } |
||
71 | */ |
||
72 | OSErr FSpCreate(const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag){ |
||
73 | HANDLE h; |
||
74 | myp2cstr((unsigned char*)spec->name); |
||
75 | h = CreateFile((char*)spec->name,0,0,0,CREATE_NEW,0,0); |
||
76 | // sprintf(s,"FSpCreate(\"%s\"):%#x",spec->name,h); dbg(s); |
||
77 | myc2pstr((char*)spec->name); |
||
78 | if( h == INVALID_HANDLE_VALUE ) |
||
79 | return ioErr; |
||
80 | else{ |
||
81 | CloseHandle(h); |
||
82 | return noErr ; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | OSErr FSpDelete(const FSSpec *spec){ |
||
87 | BOOL f; |
||
88 | myp2cstr((StringPtr)spec->name); |
||
89 | f = DeleteFile((char*)spec->name); |
||
90 | myc2pstr((char*)spec->name); |
||
91 | return f ? noErr : ioErr ; |
||
92 | } |
||
93 | |||
94 | OSErr GetEOF(FILEREF refNum,long * logEOF){ |
||
95 | DWORD n = GetFileSize(refNum,&n); |
||
96 | // sprintf(s,"GetEOF(%#x):%d",refNum,n); dbg(s); |
||
97 | *logEOF = n; |
||
98 | return n == 0xFFFFFFFF ? ioErr : noErr; |
||
99 | } |
||
100 | #endif |