OpenCBM
arch.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2004-2007 Spiro Trikaliotis
8  */
9 
19 #ifndef CBM_ARCH_H
20 #define CBM_ARCH_H
21 
22 #include <sys/types.h> /* for off_t */
23 
24 #define ARCH_EMPTY
25 
26 #include "version.h"
27 #define OPENCBM_VERSION OPENCBM_VERSION_STRING
28 
29 #ifdef WIN32
30 # define ARCH_CBM_LINUX_WIN( _linux, _win) _win
31 
32 # include <stdio.h>
33 # include <io.h>
34 # include <fcntl.h>
35 
36 #if (_MSC_VER <= 1200) // MSVC 6 or older
37 typedef unsigned long ULONG_PTR;
38 #endif
39 
40 #else
41 
42 # define ARCH_CBM_LINUX_WIN( _linux, _win) _linux
43 
44 # include <unistd.h>
45 # include <errno.h>
46 # include <stdbool.h>
47 
48 #ifdef __LP64__
49 typedef unsigned long UINT_PTR;
50 #else
51 typedef unsigned int UINT_PTR;
52 #endif
53 
54 /* error.h is only available on Linux */
55 #ifdef __linux__
56 # include <error.h>
57 #endif
58 
59 typedef unsigned long ULONG_PTR;
60 
61 typedef bool BOOL;
62 
63 # ifndef TRUE
64 # define TRUE true
65 # endif
66 # ifndef FALSE
67 # define FALSE false
68 # endif
69 
70 #endif // WIN32
71 
72 #include <string.h>
73 
74 #define arch_strcasecmp(_x,_y) ARCH_CBM_LINUX_WIN(strcasecmp(_x,_y), _stricmp(_x,_y))
75 #define arch_strncasecmp(_x,_y,_z) ARCH_CBM_LINUX_WIN(strncasecmp(_x,_y,_z), _strnicmp(_x,_y,_z))
76 
77 #define arch_sleep(_x) ARCH_CBM_LINUX_WIN(sleep(_x), Sleep((_x) * 1000))
78 #define arch_usleep(_x) ARCH_CBM_LINUX_WIN(usleep(_x), Sleep( ((_x) + 999) / 1000))
79 
80 #ifdef WIN32
81  extern void arch_error(int AUnused, unsigned int ErrorCode, const char *format, ...);
82  extern char *arch_strerror(unsigned int ErrorCode);
83 #else
84 #if defined(__APPLE__) || defined(__FreeBSD__)
85  extern void arch_error(int AUnused, unsigned int ErrorCode, const char *format, ...);
86 #else
87 # define arch_error error
88 #endif
89 # define arch_strerror strerror
90 #endif
91 
93 #define arch_set_errno(_x) ARCH_CBM_LINUX_WIN((errno = (_x)), SetLastError(_x))
94 #define arch_get_errno() ARCH_CBM_LINUX_WIN((errno), GetLastError())
95 
96 #define arch_atoc(_x) ((unsigned char) atoi(_x))
97 
98 /* dummys for compiling */
99 
100 #ifdef WIN32
101 # include <stdlib.h> /* for getenv */
102 
103 /* Make sure that getenv() will not be defined with a prototype
104  in arch/windows/getopt.c, which would result in a compiler error
105  "error C2373: 'getenv' : redefinition; different type modifiers".
106 */
107 # define getenv getenv
108 #endif
109 
110 #define arch_unlink(_x) ARCH_CBM_LINUX_WIN(unlink(_x), _unlink(_x))
111 
112 int arch_filesize(const char *Filename, off_t *Filesize);
113 
114 #define arch_strdup(_x) ARCH_CBM_LINUX_WIN(strdup(_x), _strdup(_x))
115 
116 #define arch_fileno(_x) ARCH_CBM_LINUX_WIN(fileno(_x), _fileno(_x))
117 
118 #define arch_setbinmode(_x) ARCH_CBM_LINUX_WIN(ARCH_EMPTY/* already in bin mode */, _setmode(_x, _O_BINARY))
119 
120 #define arch_ftruncate(_x, _y) ARCH_CBM_LINUX_WIN(ftruncate(_x, _y), _chsize(_x, _y))
121 
122 #define arch_fdopen(_x, _y) ARCH_CBM_LINUX_WIN(fdopen(_x, _y), _fdopen(_x, _y))
123 
124 #define arch_snprintf ARCH_CBM_LINUX_WIN(snprintf, _snprintf)
125 
126 #define ARCH_MAINDECL ARCH_CBM_LINUX_WIN(ARCH_EMPTY, __cdecl)
127 #define ARCH_SIGNALDECL ARCH_CBM_LINUX_WIN(ARCH_EMPTY, __cdecl)
128 
129 typedef void (ARCH_SIGNALDECL *ARCH_CTRLBREAK_HANDLER)(int dummy);
130 extern void arch_set_ctrlbreak_handler(ARCH_CTRLBREAK_HANDLER Handler);
131 
132 #endif /* #ifndef CBM_ARCH_H */
void arch_set_ctrlbreak_handler(ARCH_CTRLBREAK_HANDLER Handler)
Set the Ctrl+C / Ctrl+Break handler.
Definition: ctrlbreak.c:62
int arch_filesize(const char *Filename, off_t *Filesize)
Obtain the size of a given file.
Definition: file.c:38
Defining OpenCBM version.