Improve GambitREPL iOS example.
[gambit-c.git] / lib / os_base.h
blob76a678120d329f6dbf71ea5ea33b65ced1929c16
1 /* File: "os_base.h" */
3 /* Copyright (c) 1994-2012 by Marc Feeley, All Rights Reserved. */
5 #ifndef ___OS_BASE_H
6 #define ___OS_BASE_H
8 #include "os.h"
11 /*---------------------------------------------------------------------------*/
13 /* Standard I/O emulation. */
16 #include <stdio.h>
18 typedef FILE ___FILE;
20 #define ___stdin stdin
21 #define ___stdout stdout
22 #define ___stderr stderr
24 extern ___FILE *___fopen
25 ___P((const char *path,
26 const char *mode),
27 ());
29 extern int ___fclose
30 ___P((___FILE *stream),
31 ());
33 extern size_t ___fread
34 ___P((void *ptr,
35 size_t size,
36 size_t nmemb,
37 ___FILE *stream),
38 ());
40 extern size_t ___fwrite
41 ___P((const void *ptr,
42 size_t size,
43 size_t nmemb,
44 ___FILE *stream),
45 ());
47 extern int ___fflush
48 ___P((___FILE *stream),
49 ());
51 #ifdef ___DEBUG
53 extern int ___printf
54 ___P((const char *format,
55 ...),
56 ());
58 #endif
61 /*---------------------------------------------------------------------------*/
64 typedef struct ___base_module_struct
66 int refcount;
68 #ifdef ___DEBUG
70 ___FILE *debug;
72 long alloc_mem_calls;
73 long free_mem_calls;
75 #endif
77 #ifdef USE_CLASSIC_MACOS
79 /* Which features are available. */
81 ___BOOL has_GetUTCDateTime;
82 ___BOOL has_GetDateTime;
83 ___BOOL has_ReadLocation;
84 ___BOOL has_Delay;
85 ___BOOL has_IdleUpdate;
86 ___BOOL has_WaitNextEvent;
87 ___BOOL has_OSDispatch;
88 ___BOOL has_FindFolder;
89 ___BOOL has_AliasMgr;
90 ___BOOL has_AppleEvents;
92 #define ___BASE_MODULE_INIT , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
94 #endif
95 } ___base_module;
98 extern ___base_module ___base_mod;
101 /*---------------------------------------------------------------------------*/
103 /* Memory allocation. */
107 * Does "___alloc_mem" allocate upwards (___ALLOC_MEM_UP) or downwards
108 * (___ALLOC_MEM_DOWN). This setting only affects performance.
111 #define ___ALLOC_MEM_UP
114 extern void *___alloc_mem
115 ___P((unsigned long bytes),
116 ());
118 extern void ___free_mem
119 ___P((void *ptr),
120 ());
123 #ifdef ___DEBUG
124 #ifdef ___DEBUG_ALLOC_MEM_TRACE
126 extern void * ___alloc_mem_debug
127 ___P((unsigned long bytes,
128 int lineno,
129 char *file),
130 ());
132 #endif
133 #endif
136 extern void *___alloc_mem_code
137 ___P((unsigned long bytes),
138 ());
140 extern void ___free_mem_code
141 ___P((void *ptr),
142 ());
145 /*---------------------------------------------------------------------------*/
147 /* Program startup. */
150 extern ___program_startup_info_struct ___program_startup_info;
153 extern int ___main
154 ___P((___mod_or_lnk (*linker)(___global_state_struct*)),
155 ());
158 /*---------------------------------------------------------------------------*/
160 /* Process termination. */
163 extern void ___exit_process
164 ___P((int status),
165 ());
168 /* Process exit codes (see sysexits.h on many UNIX systems). */
170 #define ___EXIT_CODE_OK 0
171 #define ___EXIT_CODE_USAGE 64
172 #define ___EXIT_CODE_DATAERR 65
173 #define ___EXIT_CODE_NOINPUT 66
174 #define ___EXIT_CODE_NOUSER 67
175 #define ___EXIT_CODE_NOHOST 68
176 #define ___EXIT_CODE_UNAVAILABLE 69
177 #define ___EXIT_CODE_SOFTWARE 70
178 #define ___EXIT_CODE_OSERR 71
179 #define ___EXIT_CODE_OSFILE 72
180 #define ___EXIT_CODE_CANTCREAT 73
181 #define ___EXIT_CODE_IOERR 74
182 #define ___EXIT_CODE_TEMPFAIL 75
183 #define ___EXIT_CODE_PROTOCOL 76
184 #define ___EXIT_CODE_NOPERM 77
185 #define ___EXIT_CODE_CONFIG 78
188 /*---------------------------------------------------------------------------*/
190 /* Error handling. */
193 /* Max length of an error message, not including null. */
195 #define ___ERR_MAX_LENGTH 1024
199 * The procedure "___fatal_error" is called by the runtime system when
200 * an unrecoverable error has occured.
203 extern void ___fatal_error
204 ___P((char **msgs),
205 ());
209 * The procedure "___display_error" is called by the runtime system to
210 * send an error message to the user.
213 extern void ___display_error
214 ___P((char **msgs),
215 ());
218 /* Conversion of OS error codes to Scheme error codes. */
221 /**********************************/
222 #define err_code_from_errno() ___err_code_from_errno()
223 #define err_code_from_h_errno() ___err_code_from_h_errno()
224 #define err_code_from_gai_code(code) ___err_code_from_gai_code(code)
225 #define err_code_from_GetLastError() ___err_code_from_GetLastError()
226 #define err_code_from_WSAGetLastError() ___err_code_from_WSAGetLastError()
227 #define fnf_or_err_code_from_errno() ___fnf_or_err_code_from_errno()
228 #define fnf_or_err_code_from_GetLastError() ___fnf_or_err_code_from_GetLastError()
231 #ifdef USE_errno
233 #ifdef ___DEBUG
235 extern ___SCMOBJ ___err_code_from_errno_debug
236 ___P((int lineno,
237 char *file),
238 ());
240 #define ___err_code_from_errno() \
241 ___err_code_from_errno_debug(__LINE__,__FILE__)
243 #else
245 extern ___SCMOBJ ___err_code_from_errno ___PVOID;
247 #endif
249 #define ___fnf_or_err_code_from_errno() \
250 ___err_code_from_errno()
252 #define ___ERR_CODE_EAGAIN ___FIX(___ERRNO_ERR(EAGAIN))
253 #define ___ERR_CODE_ENOENT ___FIX(___ERRNO_ERR(ENOENT))
255 #endif
258 #ifdef USE_h_errno
260 #ifdef ___DEBUG
262 extern ___SCMOBJ ___err_code_from_h_errno_debug
263 ___P((int lineno,
264 char *file),
265 ());
267 #define ___err_code_from_h_errno() \
268 ___err_code_from_h_errno_debug(__LINE__,__FILE__)
270 #else
272 extern ___SCMOBJ ___err_code_from_h_errno ___PVOID;
274 #endif
276 #endif
279 #ifdef USE_getaddrinfo
281 #ifdef ___DEBUG
283 extern ___SCMOBJ ___err_code_from_gai_code_debug
284 ___P((int code,
285 int lineno,
286 char *file),
287 ());
289 #define ___err_code_from_gai_code(code) \
290 ___err_code_from_gai_code_debug(code,__LINE__,__FILE__)
292 #else
294 extern ___SCMOBJ ___err_code_from_gai_code
295 ___P((int code),
296 ());
298 #endif
300 #endif
303 #ifdef USE_GetLastError
305 #ifdef ___DEBUG
307 extern ___SCMOBJ ___err_code_from_GetLastError_debug
308 ___P((int lineno,
309 char *file),
310 ());
312 #define ___err_code_from_GetLastError() \
313 ___err_code_from_GetLastError_debug(__LINE__,__FILE__)
315 #else
317 extern ___SCMOBJ ___err_code_from_GetLastError ___PVOID;
319 #endif
321 #define ___fnf_or_err_code_from_GetLastError() \
322 ___err_code_from_GetLastError()
324 #define ___ERR_CODE_ERROR_FILE_NOT_FOUND \
325 ___FIX(___WIN32_ERR(ERROR_FILE_NOT_FOUND))
327 #endif
330 #ifdef USE_WSAGetLastError
331 #ifdef ___DEBUG
333 extern ___SCMOBJ ___err_code_from_WSAGetLastError_debug
334 ___P((int lineno,
335 char *file),
336 ());
338 #define ___err_code_from_WSAGetLastError() \
339 ___err_code_from_WSAGetLastError_debug(__LINE__,__FILE__)
341 #else
343 extern ___SCMOBJ ___err_code_from_WSAGetLastError ___PVOID;
345 #endif
346 #endif
349 #ifdef USE_OSErr
350 #ifdef ___DEBUG
352 extern ___SCMOBJ ___err_code_from_OSErr_debug
353 ___P((OSErr e,
354 int lineno,
355 char *file),
356 ());
358 #define ___err_code_from_OSErr(e) \
359 ___err_code_from_OSErr_debug(e,__LINE__,__FILE__)
361 #else
363 extern ___SCMOBJ ___err_code_from_OSErr
364 ___P((OSErr e),
365 ());
367 #endif
368 #endif
371 /* Conversion of Scheme error codes to error messages. */
373 extern ___SCMOBJ ___os_err_code_to_string
374 ___P((___SCMOBJ err),
375 ());
378 /*---------------------------------------------------------------------------*/
380 /* Interrupt handling. */
383 extern void ___set_signal_handler
384 ___P((int sig,
385 void (*handler) ___P((int sig),())),
386 ());
389 /*---------------------------------------------------------------------------*/
391 /* Basic OS services module initialization/finalization. */
394 extern ___SCMOBJ ___setup_base_module ___PVOID;
396 extern void ___cleanup_base_module ___PVOID;
399 /*---------------------------------------------------------------------------*/
402 #endif