(no commit message)
[geda-pcb/pcjc2.git] / src / compat.c
blob60927641a574648354394dfdb04cbf90f1335e2d
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 2004, 2006 Dan McMahill
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <math.h>
28 #include "compat.h"
29 #include "global.h"
31 #ifdef HAVE_LIBDMALLOC
32 #include <dmalloc.h>
33 #endif
35 #ifndef HAVE_EXPF
36 float
37 expf (float x)
39 return (float) exp ((double) x);
41 #endif
43 #ifndef HAVE_LOGF
44 float
45 logf (float x)
47 return (float) log ((double) x);
49 #endif
51 #ifndef HAVE_RANDOM
52 long
53 random (void)
55 return (long) rand ();
57 #endif
59 #if !defined(HAVE_DLFCN_H) && defined(WIN32)
60 #include <windows.h>
62 void *
63 dlopen (const char * f, int ATTRIBUTE_UNUSED flag)
65 return LoadLibrary (f);
68 void
69 dlclose (void * h)
71 FreeLibrary ((HINSTANCE) h);
74 char *
75 dlerror ()
77 static LPVOID lpMsgBuf = NULL;
78 DWORD dw;
80 /* free the error message buffer */
81 if (lpMsgBuf)
82 LocalFree (lpMsgBuf);
84 /* get the error code */
85 dw = GetLastError();
87 /* get the corresponding error message */
88 FormatMessage (
89 FORMAT_MESSAGE_ALLOCATE_BUFFER |
90 FORMAT_MESSAGE_FROM_SYSTEM |
91 FORMAT_MESSAGE_IGNORE_INSERTS,
92 NULL,
93 dw,
94 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
95 (LPTSTR) &lpMsgBuf,
96 0, NULL);
98 return (char *) lpMsgBuf;
101 void *
102 dlsym (void *handle, const char *symbol)
104 return (void *) GetProcAddress((HMODULE) handle, symbol);
108 #endif