2
* UAE - The Un*x Amiga Emulator
4
* Try to include the right system headers and get other system-specific
5
* stuff right & other collected kludges.
7
* If you think about modifying this, think twice. Some systems rely on
8
* the exact order of the #include statements. That's also the reason
9
* why everything gets included unconditionally regardless of whether
10
* it's actually needed by the .c file.
12
* Copyright 1996, 1997 Bernd Schmidt
15
#if defined __AMIGA__ || defined __amiga__
16
#include <devices/timer.h>
27
#error "Your compiler is not ANSI. Get a real one."
33
#ifdef HAVE_SYS_TYPES_H
34
#include <sys/types.h>
41
#include "uae_string.h"
54
#ifdef HAVE_SYS_STAT_H
58
#if TIME_WITH_SYS_TIME
59
# include <sys/time.h>
63
# include <sys/time.h>
72
# define dirent direct
74
# include <sys/ndir.h>
84
#ifdef HAVE_SYS_UTIME_H
85
# include <sys/utime.h>
91
#if EEXIST == ENOTEMPTY
92
#define BROKEN_OS_PROBABLY_AIX
96
#define S_IRUSR S_IREAD
97
#define S_IWUSR S_IWRITE
98
#define S_IXUSR S_IEXEC
99
#define S_ISDIR(val) (S_IFDIR & val)
107
#include "uae_types.h"
109
#include "uae_malloc.h"
111
#include "writelog.h"
114
/* While we're here, make abort more useful. */
116
/* This fails to compile on Morphos - not sure why yet */
119
write_log ("Internal error; file %s, line %d\n", __FILE__, __LINE__); \
123
#define abort() exit(0)
128
* Porters to weird systems, look! This is the preferred way to get
129
* filesys.c (and other stuff) running on your system. Define the
130
* appropriate macros and implement wrappers in a machine-specific file.
132
* I guess the Mac port could use this (Ernesto?)
135
#undef DONT_HAVE_POSIX
136
#undef DONT_HAVE_REAL_POSIX /* define if open+delete doesn't do what it should */
137
#undef DONT_HAVE_STDIO
138
#undef DONT_HAVE_MALLOC
142
#if defined __WATCOMC__
146
#define dirent direct
147
#define mkdir(a,b) mkdir(a)
149
#elif defined __MINGW32__
151
#define FILEFLAG_DIR 0x1
152
#define FILEFLAG_ARCHIVE 0x2
153
#define FILEFLAG_WRITE 0x4
154
#define FILEFLAG_READ 0x8
155
#define FILEFLAG_EXECUTE 0x10
156
#define FILEFLAG_SCRIPT 0x20
157
#define FILEFLAG_PURE 0x40
160
#define mkdir(a,b) mkdir(a)
162
#elif defined _MSC_VER
164
#ifdef HAVE_GETTIMEOFDAY
165
#include <winsock.h> // for 'struct timeval' definition
166
extern void gettimeofday( struct timeval *tv, void *blah );
171
#define FILEFLAG_DIR 0x1
172
#define FILEFLAG_ARCHIVE 0x2
173
#define FILEFLAG_WRITE 0x4
174
#define FILEFLAG_READ 0x8
175
#define FILEFLAG_EXECUTE 0x10
176
#define FILEFLAG_SCRIPT 0x20
177
#define FILEFLAG_PURE 0x40
181
#define O_BINARY _O_BINARY
182
#define O_WRONLY _O_WRONLY
183
#define O_RDONLY _O_RDONLY
184
#define O_RDWR _O_RDWR
185
#define O_CREAT _O_CREAT
186
#define O_TRUNC _O_TRUNC
189
#define STAT struct stat
190
#define DIR struct DIR
195
#include <sys/utime.h>
196
#define utimbuf _utimbuf
203
#define S_ISDIR(a) (a&FILEFLAG_DIR)
204
#define S_ISARC(a) (a&FILEFLAG_ARCHIVE)
205
#define S_IWUSR FILEFLAG_WRITE
206
#define S_IRUSR FILEFLAG_READ
207
#define S_IXUSR FILEFLAG_EXECUTE
209
/* These are prototypes for functions from the Win32 posixemu file */
210
extern void get_time(time_t t, long* days, long* mins, long* ticks);
211
extern time_t put_time (long days, long mins, long ticks);
212
extern DWORD getattr(const char *name, LPFILETIME lpft, size_t *size);
214
/* #define DONT_HAVE_POSIX - don't need all of Mathias' posixemu_functions, just a subset (below) */
215
#define chmod(a,b) posixemu_chmod ((a), (b))
216
extern int posixemu_chmod (const char *, int);
217
#define stat(a,b) posixemu_stat ((a), (b))
218
extern int posixemu_stat (const char *, struct stat *);
219
#define mkdir(x,y) mkdir(x)
220
#define truncate posixemu_truncate
221
extern int posixemu_truncate (const char *, long int);
222
#define utime posixemu_utime
223
extern int posixemu_utime (const char *, struct utimbuf *);
224
#define opendir posixemu_opendir
225
extern DIR * posixemu_opendir (const char *);
226
#define readdir posixemu_readdir
227
extern struct dirent* posixemu_readdir (DIR *);
228
#define closedir posixemu_closedir
229
extern void posixemu_closedir (DIR *);
235
#ifdef DONT_HAVE_POSIX
237
#define access posixemu_access
238
extern int posixemu_access (const char *, int);
239
#define open posixemu_open
240
extern int posixemu_open (const char *, int, int);
241
#define close posixemu_close
242
extern void posixemu_close (int);
243
#define read posixemu_read
244
extern int posixemu_read (int, char *, int);
245
#define write posixemu_write
246
extern int posixemu_write (int, const char *, int);
248
#define lseek posixemu_seek
249
extern int posixemu_seek (int, int, int);
250
#define stat(a,b) posixemu_stat ((a), (b))
251
extern int posixemu_stat (const char *, STAT *);
252
#define mkdir posixemu_mkdir
253
extern int mkdir (const char *, int);
254
#define rmdir posixemu_rmdir
255
extern int posixemu_rmdir (const char *);
256
#define unlink posixemu_unlink
257
extern int posixemu_unlink (const char *);
258
#define truncate posixemu_truncate
259
extern int posixemu_truncate (const char *, long int);
260
#define rename posixemu_rename
261
extern int posixemu_rename (const char *, const char *);
262
#define chmod posixemu_chmod
263
extern int posixemu_chmod (const char *, int);
264
#define tmpnam posixemu_tmpnam
265
extern void posixemu_tmpnam (char *);
266
#define utime posixemu_utime
267
extern int posixemu_utime (const char *, struct utimbuf *);
268
#define opendir posixemu_opendir
269
extern DIR * posixemu_opendir (const char *);
270
#define readdir posixemu_readdir
271
extern struct dirent* readdir (DIR *);
272
#define closedir posixemu_closedir
273
extern void closedir (DIR *);
275
/* This isn't the best place for this, but it fits reasonably well. The logic
276
* is that you probably don't have POSIX errnos if you don't have the above
278
extern long dos_errno (void);
282
#ifdef DONT_HAVE_STDIO
284
extern FILE *stdioemu_fopen (const char *, const char *);
285
#define fopen(a,b) stdioemu_fopen(a, b)
286
extern int stdioemu_fseek (FILE *, int, int);
287
#define fseek(a,b,c) stdioemu_fseek(a, b, c)
288
extern int stdioemu_fread (char *, int, int, FILE *);
289
#define fread(a,b,c,d) stdioemu_fread(a, b, c, d)
290
extern int stdioemu_fwrite (const char *, int, int, FILE *);
291
#define fwrite(a,b,c,d) stdioemu_fwrite(a, b, c, d)
292
extern int stdioemu_ftell (FILE *);
293
#define ftell(a) stdioemu_ftell(a)
294
extern int stdioemu_fclose (FILE *);
295
#define fclose(a) stdioemu_fclose(a)
299
#ifdef DONT_HAVE_MALLOC
301
#define malloc(a) mallocemu_malloc(a)
302
extern void *mallocemu_malloc (int size);
303
#define free(a) mallocemu_free(a)
304
extern void mallocemu_free (void *ptr);
309
#define ASM_SYM_FOR_FUNC(a) __asm__(a)
311
#define ASM_SYM_FOR_FUNC(a)
315
#include "machdep/machdep.h"
316
#include "gfxdep/gfx.h"
318
extern void console_out (const char *, ...);
319
extern void console_flush (void);
320
extern int console_get (char *, int);
321
extern void f_out (void *, const char *, ...);
322
extern void gui_message (const char *,...);
323
extern int gui_message_multibutton (int flags, const char *format,...);
324
#define write_log_err write_log
331
# define MAX_PATH 512
334
# define MAX_DPATH 512