Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
UNISTD_DECL.cpp
Go to the documentation of this file.
1// checking the contents of <unistd.h>
2
3
25#include "config.h"
26
27#include <sys/types.h>
28#include <fcntl.h>
29#include <stdio.h>
30
31#if defined (_WIN32) && !defined (__CYGWIN__)
32# include <io.h>
33#else
34# include <unistd.h>
35#endif // _WIN32
36
37// Windows defines the equivalent SSIZE_T in the platform SDK
38// as the signed equivalent of size_t which is defined as long
39// on WIN32 and long long/__int64 on WIN64
40#if defined (_WIN64)
41# define ssize_t __int64
42#elif defined (_WIN32)
43# define ssize_t long
44#endif
45
46#if !defined (STDIN_FILENO)
47# define STDIN_FILENO 0
48# define STDOUT_FILENO 1
49# define STDERR_FILENO 2
50#endif // STDIN_FILENO
51
52
53static void print_macros ()
54{
55 struct {
56 int value;
57 const char *name;
58 } macros[] = {
59
60#define MACRO(name) { name, #name }
64
65 // open(2) oflag constants
66 MACRO (O_RDONLY),
67 MACRO (O_WRONLY),
68 MACRO (O_RDWR),
69
70#if defined (O_ACCMODE)
71 // fcntl(2) file access mask
72 MACRO (O_ACCMODE),
73#endif // O_ACCMODE
74
75 MACRO (O_APPEND),
76 MACRO (O_EXCL),
77 MACRO (O_CREAT),
78 MACRO (O_TRUNC),
79
80 // lseek(2) whence constants
84
85#if defined (F_GETFL)
86 // fcntl(2) cmd argument
87 , MACRO (F_GETFL)
88#endif // F_GETFL
89 };
90
91 for (unsigned i = 0; i != sizeof macros / sizeof *macros; ++i)
92 printf ("#define _RWSTD_%-20s %#8x // %s\n",
94}
95
96// POSIX: off_t is a signed integral type
97const char* off_t_name (short) { return "short"; }
98const char* off_t_name (int) { return "int"; }
99const char* off_t_name (long) { return "long"; }
100
101// POSIX: ssize_t is a signed integral type
102const char* ssize_t_name (short) { return "short"; }
103const char* ssize_t_name (unsigned short) { return "unsigned short"; }
104const char* ssize_t_name (int) { return "int"; }
105const char* ssize_t_name (unsigned int) { return "unsigned int"; }
106const char* ssize_t_name (long) { return "long"; }
107const char* ssize_t_name (unsigned long) { return "unsigned long"; }
108
109#ifndef _RWSTD_NO_LONG_LONG
110# define LONG_LONG long long
111#elif defined (_WIN32)
112# define LONG_LONG __int64
113#endif // _RWSTD_NO_LONG_LONG, _WIN32
114
115
116#if defined (LONG_LONG)
117
118# define STRSTR(x) #x
119# define STR(x) STRSTR (x)
120
122{
123 return STR (LONG_LONG);
124}
125
127{
128 return STR (LONG_LONG);
129}
130
131const char* ssize_t_name (unsigned LONG_LONG)
132{
133 return STR (unsigned LONG_LONG);
134}
135
136#endif // LONG_LONG
137
138
139int main ()
140{
141 print_macros ();
142
143 off_t off = 0;
144 printf ("#define _RWSTD_OFF_T %s // off_t\n", off_t_name (off));
145
146 ssize_t s = 0;
147 printf ("#define _RWSTD_SSIZE_T %s // ssize_t\n", ssize_t_name (s));
148
149 return 0;
150}
#define i
Definition 17.names.cpp:126
#define off
Definition 17.names.cpp:507
#define s
macros
T value(const T &val)
IMPORT_C SInt32 printf(const Char *,...)
#define STR(x)
#define MACRO(name)
const char * off_t_name(short)
const char * ssize_t_name(short)
#define STDOUT_FILENO
#define STDERR_FILENO
int main()
#define LONG_LONG
#define STDIN_FILENO
#define SEEK_SET
#define SEEK_CUR
#define SEEK_END
const char * name
Definition codecvt1.cpp:72