- improve some parameter checking in WSAIoctl
[wine.git] / dlls / lzexpand / lzexpand16.c
blob791a7b198238f408f3a052002539a875371307c8
1 /*
2 * LZ Decompression functions
4 * Copyright 1996 Marcus Meissner
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.
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.
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
21 #include "winbase.h"
22 #include "lzexpand.h"
24 #include "wine/winbase16.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(file);
30 #define MAX_LZSTATES 16
32 #define IS_LZ_HANDLE(h) (((h) >= 0x400) && ((h) < 0x400+MAX_LZSTATES))
35 /***********************************************************************
36 * LZStart (LZEXPAND.7)
38 INT16 WINAPI LZStart16(void)
40 TRACE("(void)\n");
41 return 1;
45 /***********************************************************************
46 * LZInit (LZEXPAND.3)
48 HFILE16 WINAPI LZInit16( HFILE16 hfSrc )
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;
57 /***********************************************************************
58 * GetExpandedName (LZEXPAND.10)
60 INT16 WINAPI GetExpandedName16( LPSTR in, LPSTR out )
62 return (INT16)GetExpandedNameA( in, out );
66 /***********************************************************************
67 * LZRead (LZEXPAND.5)
69 INT16 WINAPI LZRead16( HFILE16 fd, LPVOID buf, UINT16 toread )
71 if (IS_LZ_HANDLE(fd)) return LZRead( fd, buf, toread );
72 return _lread( (HFILE)DosFileHandleToWin32Handle(fd), buf, toread );
76 /***********************************************************************
77 * LZSeek (LZEXPAND.4)
79 LONG WINAPI LZSeek16( HFILE16 fd, LONG off, INT16 type )
81 if (IS_LZ_HANDLE(fd)) return LZSeek( fd, off, type );
82 return _llseek( (HFILE)DosFileHandleToWin32Handle(fd), off, type );
86 /***********************************************************************
87 * LZCopy (LZEXPAND.1)
90 LONG WINAPI LZCopy16( HFILE16 src, HFILE16 dest )
92 /* already a LZ handle? */
93 if (IS_LZ_HANDLE(src)) return LZCopy( src, (HFILE)DosFileHandleToWin32Handle(dest) );
95 /* no, try to open one */
96 src = LZInit16(src);
97 if ((INT16)src <= 0) return 0;
98 if (IS_LZ_HANDLE(src))
100 LONG ret = LZCopy( src, (HFILE)DosFileHandleToWin32Handle(dest) );
101 LZClose( src );
102 return ret;
104 /* it was not a compressed file */
105 return LZCopy( (HFILE)DosFileHandleToWin32Handle(src), (HFILE)DosFileHandleToWin32Handle(dest) );
109 /***********************************************************************
110 * LZOpenFile (LZEXPAND.2)
112 HFILE16 WINAPI LZOpenFile16( LPSTR fn, LPOFSTRUCT ofs, UINT16 mode )
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);
123 /***********************************************************************
124 * LZClose (LZEXPAND.6)
126 void WINAPI LZClose16( HFILE16 fd )
128 if (IS_LZ_HANDLE(fd)) LZClose( fd );
129 else DisposeLZ32Handle( DosFileHandleToWin32Handle((HFILE)fd) );
133 /***********************************************************************
134 * CopyLZFile (LZEXPAND.8)
136 LONG WINAPI CopyLZFile16( HFILE16 src, HFILE16 dest )
138 TRACE("(%d,%d)\n",src,dest);
139 return LZCopy16(src,dest);