Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 402 lines (250 sloc) 7.677 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
/* File: "os_base.h" */

/* Copyright (c) 1994-2012 by Marc Feeley, All Rights Reserved. */

#ifndef ___OS_BASE_H
#define ___OS_BASE_H

#include "os.h"


/*---------------------------------------------------------------------------*/

/* Standard I/O emulation. */


#include <stdio.h>

typedef FILE ___FILE;

#define ___stdin stdin
#define ___stdout stdout
#define ___stderr stderr

extern ___FILE *___fopen
   ___P((const char *path,
         const char *mode),
        ());

extern int ___fclose
   ___P((___FILE *stream),
        ());

extern size_t ___fread
   ___P((void *ptr,
         size_t size,
         size_t nmemb,
         ___FILE *stream),
        ());

extern size_t ___fwrite
   ___P((const void *ptr,
         size_t size,
         size_t nmemb,
         ___FILE *stream),
        ());

extern int ___fflush
   ___P((___FILE *stream),
        ());

#ifdef ___DEBUG

extern int ___printf
   ___P((const char *format,
         ...),
        ());

#endif


/*---------------------------------------------------------------------------*/


typedef struct ___base_module_struct
  {
    int refcount;

#ifdef ___DEBUG

    ___FILE *debug;

    long alloc_mem_calls;
    long free_mem_calls;

#endif

#ifdef USE_CLASSIC_MACOS

    /* Which features are available. */

    ___BOOL has_GetUTCDateTime;
    ___BOOL has_GetDateTime;
    ___BOOL has_ReadLocation;
    ___BOOL has_Delay;
    ___BOOL has_IdleUpdate;
    ___BOOL has_WaitNextEvent;
    ___BOOL has_OSDispatch;
    ___BOOL has_FindFolder;
    ___BOOL has_AliasMgr;
    ___BOOL has_AppleEvents;

#define ___BASE_MODULE_INIT , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

#endif
  } ___base_module;


extern ___base_module ___base_mod;


/*---------------------------------------------------------------------------*/

/* Memory allocation. */


/*
* Does "___alloc_mem" allocate upwards (___ALLOC_MEM_UP) or downwards
* (___ALLOC_MEM_DOWN). This setting only affects performance.
*/

#define ___ALLOC_MEM_UP


extern void *___alloc_mem
   ___P((unsigned long bytes),
        ());

extern void ___free_mem
   ___P((void *ptr),
        ());


#ifdef ___DEBUG
#ifdef ___DEBUG_ALLOC_MEM_TRACE

extern void * ___alloc_mem_debug
   ___P((unsigned long bytes,
         int lineno,
         char *file),
        ());

#endif
#endif


extern void *___alloc_mem_code
   ___P((unsigned long bytes),
        ());

extern void ___free_mem_code
   ___P((void *ptr),
        ());


/*---------------------------------------------------------------------------*/

/* Program startup. */


extern ___program_startup_info_struct ___program_startup_info;


extern int ___main
   ___P((___mod_or_lnk (*linker)(___global_state_struct*)),
        ());


/*---------------------------------------------------------------------------*/

/* Process termination. */


extern void ___exit_process
   ___P((int status),
        ());


/* Process exit codes (see sysexits.h on many UNIX systems). */

#define ___EXIT_CODE_OK 0
#define ___EXIT_CODE_USAGE 64
#define ___EXIT_CODE_DATAERR 65
#define ___EXIT_CODE_NOINPUT 66
#define ___EXIT_CODE_NOUSER 67
#define ___EXIT_CODE_NOHOST 68
#define ___EXIT_CODE_UNAVAILABLE 69
#define ___EXIT_CODE_SOFTWARE 70
#define ___EXIT_CODE_OSERR 71
#define ___EXIT_CODE_OSFILE 72
#define ___EXIT_CODE_CANTCREAT 73
#define ___EXIT_CODE_IOERR 74
#define ___EXIT_CODE_TEMPFAIL 75
#define ___EXIT_CODE_PROTOCOL 76
#define ___EXIT_CODE_NOPERM 77
#define ___EXIT_CODE_CONFIG 78


/*---------------------------------------------------------------------------*/

/* Error handling. */


/* Max length of an error message, not including null. */

#define ___ERR_MAX_LENGTH 1024


/*
* The procedure "___fatal_error" is called by the runtime system when
* an unrecoverable error has occured.
*/

extern void ___fatal_error
   ___P((char **msgs),
        ());


/*
* The procedure "___display_error" is called by the runtime system to
* send an error message to the user.
*/

extern void ___display_error
   ___P((char **msgs),
        ());


/* Conversion of OS error codes to Scheme error codes. */


/**********************************/
#define err_code_from_errno() ___err_code_from_errno()
#define err_code_from_h_errno() ___err_code_from_h_errno()
#define err_code_from_gai_code(code) ___err_code_from_gai_code(code)
#define err_code_from_GetLastError() ___err_code_from_GetLastError()
#define err_code_from_WSAGetLastError() ___err_code_from_WSAGetLastError()
#define fnf_or_err_code_from_errno() ___fnf_or_err_code_from_errno()
#define fnf_or_err_code_from_GetLastError() ___fnf_or_err_code_from_GetLastError()


#ifdef USE_errno

#ifdef ___DEBUG

extern ___SCMOBJ ___err_code_from_errno_debug
   ___P((int lineno,
         char *file),
        ());

#define ___err_code_from_errno() \
___err_code_from_errno_debug(__LINE__,__FILE__)

#else

extern ___SCMOBJ ___err_code_from_errno ___PVOID;

#endif

#define ___fnf_or_err_code_from_errno() \
___err_code_from_errno()

#define ___ERR_CODE_EAGAIN ___FIX(___ERRNO_ERR(EAGAIN))
#define ___ERR_CODE_ENOENT ___FIX(___ERRNO_ERR(ENOENT))

#endif


#ifdef USE_h_errno

#ifdef ___DEBUG

extern ___SCMOBJ ___err_code_from_h_errno_debug
   ___P((int lineno,
         char *file),
        ());

#define ___err_code_from_h_errno() \
___err_code_from_h_errno_debug(__LINE__,__FILE__)

#else

extern ___SCMOBJ ___err_code_from_h_errno ___PVOID;

#endif

#endif


#ifdef USE_getaddrinfo

#ifdef ___DEBUG

extern ___SCMOBJ ___err_code_from_gai_code_debug
   ___P((int code,
         int lineno,
         char *file),
        ());

#define ___err_code_from_gai_code(code) \
___err_code_from_gai_code_debug(code,__LINE__,__FILE__)

#else

extern ___SCMOBJ ___err_code_from_gai_code
   ___P((int code),
        ());

#endif

#endif


#ifdef USE_GetLastError

#ifdef ___DEBUG

extern ___SCMOBJ ___err_code_from_GetLastError_debug
   ___P((int lineno,
         char *file),
        ());

#define ___err_code_from_GetLastError() \
___err_code_from_GetLastError_debug(__LINE__,__FILE__)

#else

extern ___SCMOBJ ___err_code_from_GetLastError ___PVOID;

#endif

#define ___fnf_or_err_code_from_GetLastError() \
___err_code_from_GetLastError()

#define ___ERR_CODE_ERROR_FILE_NOT_FOUND \
___FIX(___WIN32_ERR(ERROR_FILE_NOT_FOUND))

#endif


#ifdef USE_WSAGetLastError
#ifdef ___DEBUG

extern ___SCMOBJ ___err_code_from_WSAGetLastError_debug
   ___P((int lineno,
         char *file),
        ());

#define ___err_code_from_WSAGetLastError() \
___err_code_from_WSAGetLastError_debug(__LINE__,__FILE__)

#else

extern ___SCMOBJ ___err_code_from_WSAGetLastError ___PVOID;

#endif
#endif


#ifdef USE_OSErr
#ifdef ___DEBUG

extern ___SCMOBJ ___err_code_from_OSErr_debug
   ___P((OSErr e,
         int lineno,
         char *file),
        ());

#define ___err_code_from_OSErr(e) \
___err_code_from_OSErr_debug(e,__LINE__,__FILE__)

#else

extern ___SCMOBJ ___err_code_from_OSErr
   ___P((OSErr e),
        ());

#endif
#endif


/* Conversion of Scheme error codes to error messages. */

extern ___SCMOBJ ___os_err_code_to_string
   ___P((___SCMOBJ err),
        ());


/*---------------------------------------------------------------------------*/

/* Interrupt handling. */


extern void ___set_signal_handler
   ___P((int sig,
         void (*handler) ___P((int sig),())),
        ());


/*---------------------------------------------------------------------------*/

/* Basic OS services module initialization/finalization. */


extern ___SCMOBJ ___setup_base_module ___PVOID;

extern void ___cleanup_base_module ___PVOID;


/*---------------------------------------------------------------------------*/


#endif
Something went wrong with that request. Please try again.