Don't create the WINEPREFIX directory if it doesn't exist.
[wine/multimedia.git] / relay32 / builtin32.c
blobbea5db68e45e664e4b0e05b5fb355268be3cd085
1 /*
2 * Win32 builtin functions
4 * Copyright 1997 Alexandre Julliard
5 */
7 #include "config.h"
9 #include <assert.h>
10 #include <string.h>
11 #include <stdio.h>
12 #include <ctype.h>
13 #include <sys/types.h>
14 #ifdef HAVE_SYS_MMAN_H
15 #include <sys/mman.h>
16 #endif
18 #include "windef.h"
19 #include "wine/winbase16.h"
20 #include "wine/library.h"
21 #include "module.h"
22 #include "file.h"
23 #include "winerror.h"
24 #include "wine/server.h"
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(module);
28 DECLARE_DEBUG_CHANNEL(relay);
30 extern void RELAY_SetupDLL( const char *module );
32 static HMODULE main_module;
34 /***********************************************************************
35 * BUILTIN32_dlopen
37 void *BUILTIN32_dlopen( const char *name )
39 void *handle;
40 char error[256];
42 if (!(handle = wine_dll_load( name, error, sizeof(error) )))
44 if (strstr(error, "cannot open")) /* cannot open -> WARN() */
45 WARN("cannot open .so lib for builtin %s: %s\n", name, error);
46 else /* ERR() for all other errors (missing functions, ...) */
47 ERR("failed to load .so lib for builtin %s: %s\n", name, error );
49 return handle;
52 /***********************************************************************
53 * BUILTIN32_dlclose
55 int BUILTIN32_dlclose( void *handle )
57 /* FIXME: should unregister descriptors first */
58 /* wine_dll_unload( handle ); */
59 return 0;
63 /***********************************************************************
64 * load_library
66 * Load a library in memory; callback function for wine_dll_register
68 static void load_library( void *base, const char *filename )
70 HMODULE module = (HMODULE)base;
71 WINE_MODREF *wm;
73 if (!base)
75 ERR("could not map image for %s\n", filename ? filename : "main exe" );
76 return;
79 if (!(PE_HEADER(module)->FileHeader.Characteristics & IMAGE_FILE_DLL))
81 /* if we already have an executable, ignore this one */
82 if (!main_module) main_module = module;
83 return; /* don't create the modref here, will be done later on */
86 if (GetModuleHandleA( filename ))
87 MESSAGE( "Warning: loading builtin %s, but native version already present. Expect trouble.\n", filename );
89 /* Create 32-bit MODREF */
90 if (!(wm = PE_CreateModule( module, filename, 0, 0, TRUE )))
92 ERR( "can't load %s\n", filename );
93 SetLastError( ERROR_OUTOFMEMORY );
94 return;
96 TRACE( "loaded %s %p %x\n", filename, wm, module );
97 wm->refCount++; /* we don't support freeing builtin dlls (FIXME)*/
99 /* setup relay debugging entry points */
100 if (TRACE_ON(relay)) RELAY_SetupDLL( (void *)module );
104 /***********************************************************************
105 * BUILTIN32_LoadLibraryExA
107 * Partly copied from the original PE_ version.
110 WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR path, DWORD flags)
112 WINE_MODREF *wm;
113 char dllname[20], *p;
114 LPCSTR name;
115 void *handle;
117 /* Fix the name in case we have a full path and extension */
118 name = path;
119 if ((p = strrchr( name, '\\' ))) name = p + 1;
120 if ((p = strrchr( name, '/' ))) name = p + 1;
122 if (strlen(name) >= sizeof(dllname)-4) goto error;
124 strcpy( dllname, name );
125 p = strrchr( dllname, '.' );
126 if (!p) strcat( dllname, ".dll" );
127 for (p = dllname; *p; p++) *p = FILE_tolower(*p);
129 if (!(handle = BUILTIN32_dlopen( dllname ))) goto error;
131 if (!(wm = MODULE_FindModule( path ))) wm = MODULE_FindModule( dllname );
132 if (!wm)
134 ERR( "loaded .so but dll %s still not found\n", dllname );
135 /* wine_dll_unload( handle );*/
136 return NULL;
138 wm->dlhandle = handle;
139 return wm;
141 error:
142 SetLastError( ERROR_FILE_NOT_FOUND );
143 return NULL;
146 /***********************************************************************
147 * BUILTIN32_Init
149 * Initialize loading callbacks and return HMODULE of main exe.
150 * 'main' is the main exe in case if was already loaded from a PE file.
152 HMODULE BUILTIN32_LoadExeModule( HMODULE main )
154 main_module = main;
155 wine_dll_set_callback( load_library );
156 if (!main_module)
157 MESSAGE( "No built-in EXE module loaded! Did you create a .spec file?\n" );
158 return main_module;
162 /***********************************************************************
163 * BUILTIN32_RegisterDLL
165 * Register a built-in DLL descriptor.
167 void BUILTIN32_RegisterDLL( const IMAGE_NT_HEADERS *header, const char *filename )
169 extern void __wine_dll_register( const IMAGE_NT_HEADERS *header, const char *filename );
170 __wine_dll_register( header, filename );