1 /* File: "os_base.h" */
3 /* Copyright (c) 1994-2012 by Marc Feeley, All Rights Reserved. */
11 /*---------------------------------------------------------------------------*/
13 /* Standard I/O emulation. */
20 #define ___stdin stdin
21 #define ___stdout stdout
22 #define ___stderr stderr
24 extern ___FILE
*___fopen
25 ___P((const char *path
,
30 ___P((___FILE
*stream
),
33 extern size_t ___fread
40 extern size_t ___fwrite
41 ___P((const void *ptr
,
48 ___P((___FILE
*stream
),
54 ___P((const char *format
,
61 /*---------------------------------------------------------------------------*/
64 typedef struct ___base_module_struct
77 #ifdef USE_CLASSIC_MACOS
79 /* Which features are available. */
81 ___BOOL has_GetUTCDateTime
;
82 ___BOOL has_GetDateTime
;
83 ___BOOL has_ReadLocation
;
85 ___BOOL has_IdleUpdate
;
86 ___BOOL has_WaitNextEvent
;
87 ___BOOL has_OSDispatch
;
88 ___BOOL has_FindFolder
;
90 ___BOOL has_AppleEvents
;
92 #define ___BASE_MODULE_INIT , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
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
),
118 extern void ___free_mem
124 #ifdef ___DEBUG_ALLOC_MEM_TRACE
126 extern void * ___alloc_mem_debug
127 ___P((unsigned long bytes
,
136 extern void *___alloc_mem_code
137 ___P((unsigned long bytes
),
140 extern void ___free_mem_code
145 /*---------------------------------------------------------------------------*/
147 /* Program startup. */
150 extern ___program_startup_info_struct ___program_startup_info
;
154 ___P((___mod_or_lnk (*linker
)(___global_state_struct
*)),
158 /*---------------------------------------------------------------------------*/
160 /* Process termination. */
163 extern void ___exit_process
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
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
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()
235 extern ___SCMOBJ ___err_code_from_errno_debug
240 #define ___err_code_from_errno() \
241 ___err_code_from_errno_debug(__LINE__,__FILE__)
245 extern ___SCMOBJ ___err_code_from_errno ___PVOID
;
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))
262 extern ___SCMOBJ ___err_code_from_h_errno_debug
267 #define ___err_code_from_h_errno() \
268 ___err_code_from_h_errno_debug(__LINE__,__FILE__)
272 extern ___SCMOBJ ___err_code_from_h_errno ___PVOID
;
279 #ifdef USE_getaddrinfo
283 extern ___SCMOBJ ___err_code_from_gai_code_debug
289 #define ___err_code_from_gai_code(code) \
290 ___err_code_from_gai_code_debug(code,__LINE__,__FILE__)
294 extern ___SCMOBJ ___err_code_from_gai_code
303 #ifdef USE_GetLastError
307 extern ___SCMOBJ ___err_code_from_GetLastError_debug
312 #define ___err_code_from_GetLastError() \
313 ___err_code_from_GetLastError_debug(__LINE__,__FILE__)
317 extern ___SCMOBJ ___err_code_from_GetLastError ___PVOID
;
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))
330 #ifdef USE_WSAGetLastError
333 extern ___SCMOBJ ___err_code_from_WSAGetLastError_debug
338 #define ___err_code_from_WSAGetLastError() \
339 ___err_code_from_WSAGetLastError_debug(__LINE__,__FILE__)
343 extern ___SCMOBJ ___err_code_from_WSAGetLastError ___PVOID
;
352 extern ___SCMOBJ ___err_code_from_OSErr_debug
358 #define ___err_code_from_OSErr(e) \
359 ___err_code_from_OSErr_debug(e,__LINE__,__FILE__)
363 extern ___SCMOBJ ___err_code_from_OSErr
371 /* Conversion of Scheme error codes to error messages. */
373 extern ___SCMOBJ ___os_err_code_to_string
374 ___P((___SCMOBJ err
),
378 /*---------------------------------------------------------------------------*/
380 /* Interrupt handling. */
383 extern void ___set_signal_handler
385 void (*handler
) ___P((int sig
),())),
389 /*---------------------------------------------------------------------------*/
391 /* Basic OS services module initialization/finalization. */
394 extern ___SCMOBJ ___setup_base_module ___PVOID
;
396 extern void ___cleanup_base_module ___PVOID
;
399 /*---------------------------------------------------------------------------*/