Fix for building lzexpand with Mingw or MS_VC++ includes
[wine] / dlls / lzexpand / lzexpand16.c
1 /*
2  * LZ Decompression functions
3  *
4  * Copyright 1996 Marcus Meissner
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "winbase.h"
22 #include "lzexpand.h"
23
24 #include "wine/winbase16.h"
25
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(file);
29
30 #define MAX_LZSTATES 16
31
32 #define IS_LZ_HANDLE(h) (((h) >= 0x400) && ((h) < 0x400+MAX_LZSTATES))
33
34
35 /***********************************************************************
36  *           LZStart   (LZEXPAND.7)
37  */
38 INT16 WINAPI LZStart16(void)
39 {
40     TRACE("(void)\n");
41     return 1;
42 }
43
44
45 /***********************************************************************
46  *           LZInit   (LZEXPAND.3)
47  */
48 HFILE16 WINAPI LZInit16( HFILE16 hfSrc )
49 {
50     HFILE ret = LZInit( (HFILE)DosFileHandleToWin32Handle(hfSrc) );
51     if (IS_LZ_HANDLE(ret)) return ret;
52     if ((INT)ret <= 0) return ret;
53     return hfSrc;
54 }
55
56
57 /***********************************************************************
58  *           GetExpandedName   (LZEXPAND.10)
59  */
60 INT16 WINAPI GetExpandedName16( LPSTR in, LPSTR out )
61 {
62     return (INT16)GetExpandedNameA( in, out );
63 }
64
65
66 /***********************************************************************
67  *           LZRead   (LZEXPAND.5)
68  */
69 INT16 WINAPI LZRead16( HFILE16 fd, LPVOID buf, UINT16 toread )
70 {
71     if (IS_LZ_HANDLE(fd)) return LZRead( fd, buf, toread );
72     return _lread( (HFILE)DosFileHandleToWin32Handle(fd), buf, toread );
73 }
74
75
76 /***********************************************************************
77  *           LZSeek   (LZEXPAND.4)
78  */
79 LONG WINAPI LZSeek16( HFILE16 fd, LONG off, INT16 type )
80 {
81     if (IS_LZ_HANDLE(fd)) return LZSeek( fd, off, type );
82     return _llseek( (HFILE)DosFileHandleToWin32Handle(fd), off, type );
83 }
84
85
86 /***********************************************************************
87  *           LZCopy   (LZEXPAND.1)
88  *
89  */
90 LONG WINAPI LZCopy16( HFILE16 src, HFILE16 dest )
91 {
92     /* already a LZ handle? */
93     if (IS_LZ_HANDLE(src)) return LZCopy( src, (HFILE)DosFileHandleToWin32Handle(dest) );
94
95     /* no, try to open one */
96     src = LZInit16(src);
97     if ((INT16)src <= 0) return 0;
98     if (IS_LZ_HANDLE(src))
99     {
100         LONG ret = LZCopy( src, (HFILE)DosFileHandleToWin32Handle(dest) );
101         LZClose( src );
102         return ret;
103     }
104     /* it was not a compressed file */
105     return LZCopy( (HFILE)DosFileHandleToWin32Handle(src), (HFILE)DosFileHandleToWin32Handle(dest) );
106 }
107
108
109 /***********************************************************************
110  *           LZOpenFile   (LZEXPAND.2)
111  */
112 HFILE16 WINAPI LZOpenFile16( LPSTR fn, LPOFSTRUCT ofs, UINT16 mode )
113 {
114     HFILE hfret = LZOpenFileA( fn, ofs, mode );
115     /* return errors and LZ handles unmodified */
116     if ((INT)hfret <= 0) return hfret;
117     if (IS_LZ_HANDLE(hfret)) return hfret;
118     /* but allocate a dos handle for 'normal' files */
119     return Win32HandleToDosFileHandle((HANDLE)hfret);
120 }
121
122
123 /***********************************************************************
124  *           LZClose   (LZEXPAND.6)
125  */
126 void WINAPI LZClose16( HFILE16 fd )
127 {
128     if (IS_LZ_HANDLE(fd)) LZClose( fd );
129     else DisposeLZ32Handle( DosFileHandleToWin32Handle((HFILE)fd) );
130 }
131
132
133 /***********************************************************************
134  *           CopyLZFile   (LZEXPAND.8)
135  */
136 LONG WINAPI CopyLZFile16( HFILE16 src, HFILE16 dest )
137 {
138     TRACE("(%d,%d)\n",src,dest);
139     return LZCopy16(src,dest);
140 }