1 /*
2 dxedll_pub.h - DXE client support code
3 
4 Copyright (c) 2002 - 2005, 2020 dbjh
5 
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 #ifndef DXEDLL_PUB_H
22 #define DXEDLL_PUB_H
23 
24 #ifdef  HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 #include <ctype.h>
28 #ifdef  HAVE_DIRENT_H
29 #include <dirent.h>
30 #endif
31 #include <dos.h>
32 #include <dpmi.h>
33 #include <fcntl.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <sys/stat.h>
39 #include <time.h>
40 #ifdef  HAVE_UNISTD_H
41 #include <unistd.h>
42 #endif
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 typedef struct st_symbol
49 {
50   // functions exported by the DXE module
51   int (*dxe_init) (void);
52   void *(*dxe_symbol) (char *symbol_name);
53 
54   // variables exported by the DXE module
55   int size;                                     // yes, this var needs to be here
56                                                 //  (or it could be a function)
57   /*
58      functions imported by the DXE module
59      Note that most functions used by the DXE module and not defined in it
60      should be listed here. That includes standard C library functions and
61      variables.
62   */
63   int (*open) (const char *, int, ...);
64 
65   int (*vfprintf) (FILE *, const char *, va_list);
66   int (*vsprintf) (char *, const char *, va_list);
67   int (*vsnprintf) (char *, size_t, const char *, va_list);
68   int (*puts) (const char *);
69   int (*fputs) (const char *, FILE *);
70   int (*vsscanf) (const char *, const char *, va_list);
71   FILE *(*fopen) (const char *, const char *);
72   FILE *(*fdopen) (int, const char *);
73   FILE *(*popen) (const char *, const char *);
74   int (*fclose) (FILE *);
75   int (*pclose) (FILE *);
76   int (*fseek) (FILE *, long, int);
77   long (*ftell) (FILE *);
78   void (*rewind) (FILE *);
79   size_t (*fread) (void *, size_t, size_t, FILE *);
80   size_t (*fwrite) (const void *, size_t, size_t, FILE *);
81   int (*fgetc) (FILE *);
82   char *(*fgets) (char *, int, FILE *);
83   int (*feof) (FILE *);
84   int (*fputc) (int, FILE *);
85   int (*fflush) (FILE *);
86   int (*ferror) (FILE *);
87   int (*rename) (const char *, const char *);
88   int (*remove) (const char *);
89   void (*clearerr) (FILE *);
90 
91   void (*free) (void *);
92   void *(*malloc) (size_t);
93   void *(*calloc) (size_t, size_t);
94   void *(*realloc) (void *, size_t);
95   void (*exit) (int) __attribute__ ((noreturn));
96   long (*strtol) (const char *, char **, int);
97   char *(*getenv) (const char *);
98   void (*srand) (unsigned);
99   int (*rand) (void);
100   int (*atoi) (const char *);
101 
102   int (*memcmp) (const void *, const void *, size_t);
103   void *(*memcpy) (void *, const void *, size_t);
104   void *(*memmove) (void *, const void *, size_t);
105   void *(*memset) (void *, int, size_t);
106   void *(*memchr) (const void *, int, size_t);
107   int (*strcmp) (const char *, const char *);
108   char *(*strcpy) (char *, const char *);
109   char *(*strncpy) (char *, const char *, size_t);
110   char *(*strcat) (char *, const char *);
111   char *(*strncat) (char *, const char *, size_t);
112   char *(*stpcpy) (char *, const char *);
113   int (*strcasecmp) (const char *, const char *);
114   int (*strncasecmp) (const char *, const char *, size_t);
115   char *(*strchr) (const char *, int);
116   char *(*strrchr) (const char *, int);
117   char *(*strpbrk) (const char *, const char *);
118   size_t (*strspn) (const char *, const char *);
119   size_t (*strcspn) (const char *, const char *);
120   size_t (*strlen) (const char *);
121   size_t (*strnlen) (const char *, size_t);
122   char *(*strstr) (const char *, const char *);
123   char *(*strdup) (const char *);
124   char *(*strtok) (char *, const char *);
125   char *(*strerror) (int);
126   char *(*strlwr) (char *);
127   char *(*strupr) (char *);
128 
129   int (*tolower) (int);
130   int (*toupper) (int);
131   int (*isupper) (int);
132 
133   DIR *(*opendir) (const char *);
134   struct dirent *(*readdir) (DIR *);
135   int (*closedir) (DIR *);
136 
137   // va_start(), va_arg() and va_end() are macros
138 
139   int (*access) (const char *, int);
140   ssize_t (*read) (int, void *, size_t);
141   ssize_t (*write) (int, const void *, size_t);
142   int (*close) (int);
143   off_t (*lseek) (int, off_t, int);
144   int (*readlink) (const char *, char *, size_t);
145   int (*rmdir) (const char *);
146   int (*isatty) (int);
147   int (*chdir) (const char *);
148   char *(*getcwd) (char *, size_t);
149   int (*getuid) (void);
150   int (*sync) (void);
151   int (*truncate) (const char *, off_t);
152 
153   int (*stat) (const char *, struct stat *);
154   int (*chmod) (const char *, mode_t);
155   int (*mkdir) (const char *, mode_t);
156 
157   time_t (*time) (time_t *);
158   double (*difftime) (time_t time1, time_t time0);
159 
160   void (*delay) (unsigned);
161   int (*__dpmi_int) (int, __dpmi_regs *);
162 
163   // Put all variables AFTER the functions. This makes it easy to catch
164   //  uninitialized function pointers.
165   FILE __dj_stdin, __dj_stdout, __dj_stderr;
166   // WARNING: actually the __dj_ctype_X variables are arrays
167   unsigned short *__dj_ctype_flags;
168   unsigned char *__dj_ctype_tolower, *__dj_ctype_toupper;
169   int errno;
170 } st_symbol_t;
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif // DXEDLL_PUB_H
177