[win32] various tweaks to build support (NOTE: meant for 5.004_57)
[p5sagit/p5-mst-13.2.git] / win32 / win32iop.h
1 #ifndef WIN32IOP_H
2 #define WIN32IOP_H
3
4 #ifndef START_EXTERN_C
5 #ifdef __cplusplus
6 #  define START_EXTERN_C extern "C" {
7 #  define END_EXTERN_C }
8 #  define EXTERN_C extern "C"
9 #else
10 #  define START_EXTERN_C 
11 #  define END_EXTERN_C 
12 #  define EXTERN_C
13 #endif
14 #endif
15
16 /*
17  * defines for flock emulation
18  */
19 #define LOCK_SH 1
20 #define LOCK_EX 2
21 #define LOCK_NB 4
22 #define LOCK_UN 8
23
24 /*
25  * Make this as close to original stdio as possible.
26  */
27
28 /*
29  * function prototypes for our own win32io layer
30  */
31 START_EXTERN_C
32
33 DllExport  int *        win32_errno(void);
34 DllExport  char ***     win32_environ(void);
35 DllExport  FILE*        win32_stdin(void);
36 DllExport  FILE*        win32_stdout(void);
37 DllExport  FILE*        win32_stderr(void);
38 DllExport  int          win32_ferror(FILE *fp);
39 DllExport  int          win32_feof(FILE *fp);
40 DllExport  char*        win32_strerror(int e);
41
42 DllExport  int          win32_fprintf(FILE *pf, const char *format, ...);
43 DllExport  int          win32_printf(const char *format, ...);
44 DllExport  int          win32_vfprintf(FILE *pf, const char *format, va_list arg);
45 DllExport  int          win32_vprintf(const char *format, va_list arg);
46 DllExport  size_t       win32_fread(void *buf, size_t size, size_t count, FILE *pf);
47 DllExport  size_t       win32_fwrite(const void *buf, size_t size, size_t count, FILE *pf);
48 DllExport  FILE*        win32_fopen(const char *path, const char *mode);
49 DllExport  FILE*        win32_fdopen(int fh, const char *mode);
50 DllExport  FILE*        win32_freopen(const char *path, const char *mode, FILE *pf);
51 DllExport  int          win32_fclose(FILE *pf);
52 DllExport  int          win32_fputs(const char *s,FILE *pf);
53 DllExport  int          win32_fputc(int c,FILE *pf);
54 DllExport  int          win32_ungetc(int c,FILE *pf);
55 DllExport  int          win32_getc(FILE *pf);
56 DllExport  int          win32_fileno(FILE *pf);
57 DllExport  void         win32_clearerr(FILE *pf);
58 DllExport  int          win32_fflush(FILE *pf);
59 DllExport  long         win32_ftell(FILE *pf);
60 DllExport  int          win32_fseek(FILE *pf,long offset,int origin);
61 DllExport  int          win32_fgetpos(FILE *pf,fpos_t *p);
62 DllExport  int          win32_fsetpos(FILE *pf,const fpos_t *p);
63 DllExport  void         win32_rewind(FILE *pf);
64 DllExport  FILE*        win32_tmpfile(void);
65 DllExport  void         win32_abort(void);
66 DllExport  int          win32_fstat(int fd,struct stat *sbufptr);
67 DllExport  int          win32_stat(const char *name,struct stat *sbufptr);
68 DllExport  int          win32_pipe( int *phandles, unsigned int psize, int textmode );
69 DllExport  FILE*        win32_popen( const char *command, const char *mode );
70 DllExport  int          win32_pclose( FILE *pf);
71 DllExport  int          win32_setmode( int fd, int mode);
72 DllExport  long         win32_lseek( int fd, long offset, int origin);
73 DllExport  long         win32_tell( int fd);
74 DllExport  int          win32_dup( int fd);
75 DllExport  int          win32_dup2(int h1, int h2);
76 DllExport  int          win32_open(const char *path, int oflag,...);
77 DllExport  int          win32_close(int fd);
78 DllExport  int          win32_eof(int fd);
79 DllExport  int          win32_read(int fd, void *buf, unsigned int cnt);
80 DllExport  int          win32_write(int fd, const void *buf, unsigned int cnt);
81 DllExport  int          win32_spawnvp(int mode, const char *cmdname,
82                               const char *const *argv);
83 DllExport  int          win32_mkdir(const char *dir, int mode);
84 DllExport  int          win32_rmdir(const char *dir);
85 DllExport  int          win32_chdir(const char *dir);
86 DllExport  int          win32_flock(int fd, int oper);
87 DllExport  int          win32_execvp(const char *cmdname, const char *const *argv);
88 DllExport  void         win32_perror(const char *str);
89 DllExport  void         win32_setbuf(FILE *pf, char *buf);
90 DllExport  int          win32_setvbuf(FILE *pf, char *buf, int type, size_t size);
91 DllExport  int          win32_flushall(void);
92 DllExport  int          win32_fcloseall(void);
93 DllExport  char*        win32_fgets(char *s, int n, FILE *pf);
94 DllExport  char*        win32_gets(char *s);
95 DllExport  int          win32_fgetc(FILE *pf);
96 DllExport  int          win32_putc(int c, FILE *pf);
97 DllExport  int          win32_puts(const char *s);
98 DllExport  int          win32_getchar(void);
99 DllExport  int          win32_putchar(int c);
100 DllExport  void*        win32_malloc(size_t size);
101 DllExport  void*        win32_calloc(size_t numitems, size_t size);
102 DllExport  void*        win32_realloc(void *block, size_t size);
103 DllExport  void         win32_free(void *block);
104
105 DllExport  int          win32_open_osfhandle(long handle, int flags);
106 DllExport  long         win32_get_osfhandle(int fd);
107
108 #ifndef USE_WIN32_RTL_ENV
109 DllExport  char*        win32_getenv(const char *name);
110 #endif
111
112 DllExport  unsigned     win32_sleep(unsigned int);
113 DllExport  int          win32_times(struct tms *timebuf);
114 DllExport  unsigned     win32_alarm(unsigned int sec);
115 DllExport  int          win32_stat(const char *path, struct stat *buf);
116 DllExport  int          win32_ioctl(int i, unsigned int u, char *data);
117 DllExport  int          win32_wait(int *status);
118
119 #ifdef HAVE_DES_FCRYPT
120 DllExport char *        win32_crypt(const char *txt, const char *salt);
121 #endif
122
123 END_EXTERN_C
124
125 /*
126  * the following six(6) is #define in stdio.h
127  */
128 #ifndef WIN32IO_IS_STDIO
129 #undef errno
130 #undef environ
131 #undef stderr
132 #undef stdin
133 #undef stdout
134 #undef ferror
135 #undef feof
136 #undef fclose
137 #undef pipe
138 #undef pause
139 #undef sleep
140 #undef times
141 #undef alarm
142 #undef ioctl
143 #undef wait
144
145 #ifdef __BORLANDC__
146 #undef ungetc
147 #undef getc
148 #undef putc
149 #undef getchar
150 #undef putchar
151 #undef fileno
152 #endif
153
154 #define stderr                          win32_stderr()
155 #define stdout                          win32_stdout()
156 #define stdin                           win32_stdin()
157 #define feof(f)                         win32_feof(f)
158 #define ferror(f)                       win32_ferror(f)
159 #define errno                           (*win32_errno())
160 #define environ                         (*win32_environ())
161 #define strerror                        win32_strerror
162
163 /*
164  * redirect to our own version
165  */
166 #define fprintf                 win32_fprintf
167 #define vfprintf                win32_vfprintf
168 #define printf                  win32_printf
169 #define vprintf                 win32_vprintf
170 #define fread(buf,size,count,f) win32_fread(buf,size,count,f)
171 #define fwrite(buf,size,count,f)        win32_fwrite(buf,size,count,f)
172 #define fopen                   win32_fopen
173 #undef fdopen
174 #define fdopen                  win32_fdopen
175 #define freopen                 win32_freopen
176 #define fclose(f)               win32_fclose(f)
177 #define fputs(s,f)              win32_fputs(s,f)
178 #define fputc(c,f)              win32_fputc(c,f)
179 #define ungetc(c,f)             win32_ungetc(c,f)
180 #define getc(f)                 win32_getc(f)
181 #define fileno(f)               win32_fileno(f)
182 #define clearerr(f)             win32_clearerr(f)
183 #define fflush(f)               win32_fflush(f)
184 #define ftell(f)                win32_ftell(f)
185 #define fseek(f,o,w)            win32_fseek(f,o,w)
186 #define fgetpos(f,p)            win32_fgetpos(f,p)
187 #define fsetpos(f,p)            win32_fsetpos(f,p)
188 #define rewind(f)               win32_rewind(f)
189 #define tmpfile()               win32_tmpfile()
190 #define abort()                 win32_abort()
191 #define fstat(fd,bufptr)        win32_fstat(fd,bufptr)
192 #define stat(pth,bufptr)        win32_stat(pth,bufptr)
193 #define setmode(fd,mode)        win32_setmode(fd,mode)
194 #define lseek(fd,offset,orig)   win32_lseek(fd,offset,orig)
195 #define tell(fd)                win32_tell(fd)
196 #define dup(fd)                 win32_dup(fd)
197 #define dup2(fd1,fd2)           win32_dup2(fd1,fd2)
198 #define open                    win32_open
199 #define close(fd)               win32_close(fd)
200 #define eof(fd)                 win32_eof(fd)
201 #define read(fd,b,s)            win32_read(fd,b,s)
202 #define write(fd,b,s)           win32_write(fd,b,s)
203 #define _open_osfhandle         win32_open_osfhandle
204 #define _get_osfhandle          win32_get_osfhandle
205 #define spawnvp                 win32_spawnvp
206 #define mkdir                   win32_mkdir
207 #define rmdir                   win32_rmdir
208 #define chdir                   win32_chdir
209 #define flock(fd,o)             win32_flock(fd,o)
210 #define execvp                  win32_execvp
211 #define perror                  win32_perror
212 #define setbuf                  win32_setbuf
213 #define setvbuf                 win32_setvbuf
214 #undef flushall
215 #define flushall                win32_flushall
216 #undef fcloseall
217 #define fcloseall               win32_fcloseall
218 #define fgets                   win32_fgets
219 #define gets                    win32_gets
220 #define fgetc                   win32_fgetc
221 #define putc                    win32_putc
222 #define puts                    win32_puts
223 #define getchar                 win32_getchar
224 #define putchar                 win32_putchar
225
226 #if !defined(MYMALLOC) || !defined(PERL_CORE)
227 #undef malloc
228 #undef calloc
229 #undef realloc
230 #undef free
231 #define malloc                  win32_malloc
232 #define calloc                  win32_calloc
233 #define realloc                 win32_realloc
234 #define free                    win32_free
235 #endif
236
237 #define pipe(fd)                win32_pipe((fd), 512, O_BINARY)
238 #define pause()                 win32_sleep((32767L << 16) + 32767)
239 #define sleep                   win32_sleep
240 #define times                   win32_times
241 #define alarm                   win32_alarm
242 #define ioctl                   win32_ioctl
243 #define wait                    win32_wait
244
245 #ifdef HAVE_DES_FCRYPT
246 #undef crypt
247 #define crypt                   win32_crypt
248 #endif
249
250 #ifndef USE_WIN32_RTL_ENV
251 #undef getenv
252 #define getenv win32_getenv
253 #endif
254
255 #endif /* WIN32IO_IS_STDIO */
256 #endif /* WIN32IOP_H */
257