Avoid excessive heap memory reallocation when generating EMF
[wine] / dlls / win32s / w32sys.c
1 /*
2  * W32SYS
3  * helper DLL for Win32s
4  *
5  * Copyright (c) 1996 Anand Kumria
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wine/windef16.h"
32 #include "wine/winbase16.h"
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(dll);
36
37 typedef struct
38 {
39     BYTE   bMajor;
40     BYTE   bMinor;
41     WORD   wBuildNumber;
42     BOOL16 fDebug;
43 } WIN32SINFO, *LPWIN32SINFO;
44
45 /***********************************************************************
46  *           GetWin32sInfo   (W32SYS.12)
47  * RETURNS
48  *  0 on success, 1 on failure
49  */
50 WORD WINAPI GetWin32sInfo16(
51         LPWIN32SINFO lpInfo     /* [out] Win32S special information */
52 ) {
53     lpInfo->bMajor = 1;
54     lpInfo->bMinor = 3;
55     lpInfo->wBuildNumber = 0;
56     lpInfo->fDebug = FALSE;
57
58     return 0;
59 }
60
61 /***********************************************************************
62  *            GetW32SysVersion  (W32SYS.5)
63  */
64 WORD WINAPI GetW32SysVersion16(void)
65 {
66     return 0x100;
67 }
68
69 /***********************************************************************
70  *           GetPEResourceTable   (W32SYS.7)
71  * retrieves the resourcetable from the passed filedescriptor
72  * RETURNS
73  *      dunno what.
74  */
75 WORD WINAPI GetPEResourceTable16(
76         HFILE16 hf              /* [in] filedescriptor to opened executeable */
77 ) {
78         return 0;
79 }
80
81 /***********************************************************************
82  *           LoadPeResource (W32SYS.11)
83  */
84 DWORD WINAPI LoadPeResource16(WORD x,SEGPTR y) {
85         FIXME("(0x%04x,0x%08lx),stub!\n",x,y);
86         return 0;
87 }
88
89
90 /**********************************************************************
91  *              IsPeFormat              (W32SYS.2)
92  * Checks the passed filename if it is a PE format executeable
93  * RETURNS
94  *  TRUE, if it is.
95  *  FALSE if not.
96  */
97 BOOL16 WINAPI IsPeFormat16( LPSTR fn,      /* [in] filename to executeable */
98                             HFILE16 hf16 ) /* [in] open file, if filename is NULL */
99 {
100     BOOL16 ret = FALSE;
101     IMAGE_DOS_HEADER mzh;
102     OFSTRUCT ofs;
103     DWORD xmagic;
104     HFILE hf;
105
106     if (fn) hf = OpenFile(fn,&ofs,OF_READ);
107     else hf = (HFILE)DosFileHandleToWin32Handle( hf16 );
108     if (hf == HFILE_ERROR) return FALSE;
109     _llseek(hf,0,SEEK_SET);
110     if (sizeof(mzh)!=_lread(hf,&mzh,sizeof(mzh))) goto done;
111     if (mzh.e_magic!=IMAGE_DOS_SIGNATURE) goto done;
112     _llseek(hf,mzh.e_lfanew,SEEK_SET);
113     if (sizeof(DWORD)!=_lread(hf,&xmagic,sizeof(DWORD))) goto done;
114     ret = (xmagic == IMAGE_NT_SIGNATURE);
115  done:
116     if (fn) _lclose(hf);
117     return ret;
118 }