This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
84fe1e5e5c373445a6b760af3da8c7d361f3ab14
[perl5.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 #include <sys/utime.h>
17
18 /*
19  * defines for flock emulation
20  */
21 #define LOCK_SH 1
22 #define LOCK_EX 2
23 #define LOCK_NB 4
24 #define LOCK_UN 8
25
26 /*
27  * Make this as close to original stdio as possible.
28  */
29
30 /*
31  * function prototypes for our own win32io layer
32  */
33 START_EXTERN_C
34
35 DllExport  int *        win32_errno(void);
36 DllExport  char ***     win32_environ(void);
37 DllExport  FILE*        win32_stdin(void);
38 DllExport  FILE*        win32_stdout(void);
39 DllExport  FILE*        win32_stderr(void);
40 DllExport  int          win32_ferror(FILE *fp);
41 DllExport  int          win32_feof(FILE *fp);
42 DllExport  char*        win32_strerror(int e);
43
44 DllExport  int          win32_fprintf(FILE *pf, const char *format, ...);
45 DllExport  int          win32_printf(const char *format, ...);
46 DllExport  int          win32_vfprintf(FILE *pf, const char *format, va_list arg);
47 DllExport  int          win32_vprintf(const char *format, va_list arg);
48 DllExport  size_t       win32_fread(void *buf, size_t size, size_t count, FILE *pf);
49 DllExport  size_t       win32_fwrite(const void *buf, size_t size, size_t count, FILE *pf);
50 DllExport  FILE*        win32_fopen(const char *path, const char *mode);
51 DllExport  FILE*        win32_fdopen(int fh, const char *mode);
52 DllExport  FILE*        win32_freopen(const char *path, const char *mode, FILE *pf);
53 DllExport  int          win32_fclose(FILE *pf);
54 DllExport  int          win32_fputs(const char *s,FILE *pf);
55 DllExport  int          win32_fputc(int c,FILE *pf);
56 DllExport  int          win32_ungetc(int c,FILE *pf);
57 DllExport  int          win32_getc(FILE *pf);
58 DllExport  int          win32_fileno(FILE *pf);
59 DllExport  void         win32_clearerr(FILE *pf);
60 DllExport  int          win32_fflush(FILE *pf);
61 DllExport  Off_t        win32_ftell(FILE *pf);
62 DllExport  int          win32_fseek(FILE *pf,Off_t offset,int origin);
63 DllExport  int          win32_fgetpos(FILE *pf,fpos_t *p);
64 DllExport  int          win32_fsetpos(FILE *pf,const fpos_t *p);
65 DllExport  void         win32_rewind(FILE *pf);
66 DllExport  int          win32_tmpfd(void);
67 DllExport  int          win32_tmpfd_mode(int mode);
68 DllExport  FILE*        win32_tmpfile(void);
69 DllExport  void         win32_abort(void);
70 DllExport  int          win32_fstat(int fd,Stat_t *sbufptr);
71 DllExport  int          win32_stat(const char *name,Stat_t *sbufptr);
72 DllExport  int          win32_lstat(const char *name,Stat_t *sbufptr);
73 DllExport  int          win32_pipe( int *phandles, unsigned int psize, int textmode );
74 DllExport  PerlIO*      win32_popen( const char *command, const char *mode );
75 DllExport  PerlIO*      win32_popenlist(const char *mode, IV narg, SV **args);
76 DllExport  int          win32_pclose( PerlIO *pf);
77 DllExport  int          win32_rename( const char *oname, const char *newname);
78 DllExport  int          win32_setmode( int fd, int mode);
79 DllExport  int          win32_chsize(int fd, Off_t size);
80 DllExport  Off_t        win32_lseek( int fd, Off_t offset, int origin);
81 DllExport  Off_t        win32_tell( int fd);
82 DllExport  int          win32_dup( int fd);
83 DllExport  int          win32_dup2(int h1, int h2);
84 DllExport  int          win32_open(const char *path, int oflag,...);
85 DllExport  int          win32_close(int fd);
86 DllExport  int          win32_eof(int fd);
87 DllExport  int          win32_isatty(int fd);
88 DllExport  int          win32_read(int fd, void *buf, unsigned int cnt);
89 DllExport  int          win32_write(int fd, const void *buf, unsigned int cnt);
90 DllExport  int          win32_spawnvp(int mode, const char *cmdname,
91                               const char *const *argv);
92 DllExport  int          win32_mkdir(const char *dir, int mode);
93 DllExport  int          win32_rmdir(const char *dir);
94 DllExport  int          win32_chdir(const char *dir);
95 DllExport  int          win32_flock(int fd, int oper);
96 DllExport  int          win32_execv(const char *cmdname, const char *const *argv);
97 DllExport  int          win32_execvp(const char *cmdname, const char *const *argv);
98 DllExport  void         win32_perror(const char *str);
99 DllExport  void         win32_setbuf(FILE *pf, char *buf);
100 DllExport  int          win32_setvbuf(FILE *pf, char *buf, int type, size_t size);
101 DllExport  int          win32_flushall(void);
102 DllExport  int          win32_fcloseall(void);
103 DllExport  char*        win32_fgets(char *s, int n, FILE *pf);
104 DllExport  char*        win32_gets(char *s);
105 DllExport  int          win32_fgetc(FILE *pf);
106 DllExport  int          win32_putc(int c, FILE *pf);
107 DllExport  int          win32_puts(const char *s);
108 DllExport  int          win32_getchar(void);
109 DllExport  int          win32_putchar(int c);
110 DllExport  void*        win32_malloc(size_t size);
111 DllExport  void*        win32_calloc(size_t numitems, size_t size);
112 DllExport  void*        win32_realloc(void *block, size_t size);
113 DllExport  void         win32_free(void *block);
114
115 DllExport  int          win32_open_osfhandle(intptr_t handle, int flags);
116 DllExport  intptr_t     win32_get_osfhandle(int fd);
117 DllExport  FILE*        win32_fdupopen(FILE *pf);
118
119 DllExport  DIR*         win32_opendir(const char *filename);
120 DllExport  struct direct*       win32_readdir(DIR *dirp);
121 DllExport  long         win32_telldir(DIR *dirp);
122 DllExport  void         win32_seekdir(DIR *dirp, long loc);
123 DllExport  void         win32_rewinddir(DIR *dirp);
124 DllExport  int          win32_closedir(DIR *dirp);
125 DllExport  DIR*         win32_dirp_dup(DIR *const dirp, CLONE_PARAMS *const param);
126
127 DllExport  char*        win32_getenvironmentstrings(void);
128 /* also see win32_freeenvironmentstrings macro */
129 DllExport  char*        win32_getenv(const char *name);
130 DllExport  int          win32_putenv(const char *name);
131
132 DllExport  unsigned     win32_sleep(unsigned int);
133 DllExport  int          win32_pause(void);
134 DllExport  int          win32_times(struct tms *timebuf);
135 DllExport  unsigned     win32_alarm(unsigned int sec);
136 DllExport  char*        win32_longpath(char *path);
137 DllExport  char*        win32_ansipath(const WCHAR *path);
138 DllExport  int          win32_ioctl(int i, unsigned int u, char *data);
139 DllExport  int          win32_link(const char *oldname, const char *newname);
140 DllExport  int          win32_unlink(const char *f);
141 DllExport  int          win32_utime(const char *f, struct utimbuf *t);
142 DllExport  int          win32_gettimeofday(struct timeval *tp, void *not_used);
143 DllExport  int          win32_uname(struct utsname *n);
144 DllExport  int          win32_wait(int *status);
145 DllExport  int          win32_waitpid(int pid, int *status, int flags);
146 DllExport  int          win32_kill(int pid, int sig);
147 DllExport  unsigned long        win32_os_id(void);
148 DllExport  void*        win32_dynaload(const char*filename);
149 DllExport  int          win32_access(const char *path, int mode);
150 DllExport  int          win32_chmod(const char *path, int mode);
151 DllExport  int          win32_getpid(void);
152
153 DllExport char *        win32_crypt(const char *txt, const char *salt);
154
155 DllExport void *        win32_get_childenv(void);
156 DllExport void          win32_free_childenv(void* d);
157 DllExport void          win32_clearenv(void);
158 DllExport char *        win32_get_childdir(void);
159 DllExport void          win32_free_childdir(char* d);
160 DllExport Sighandler_t  win32_signal(int sig, Sighandler_t subcode);
161
162
163 END_EXTERN_C
164
165 /* see comment in win32_getenvironmentstrings */
166 #define win32_freeenvironmentstrings(x) win32_free(x)
167 #undef alarm
168 #define alarm                           win32_alarm
169 #undef strerror
170 #define strerror                        win32_strerror
171
172 /*
173  * the following six(6) is #define in stdio.h
174  */
175 #ifndef WIN32IO_IS_STDIO
176 #undef errno
177 #undef environ
178 #undef stderr
179 #undef stdin
180 #undef stdout
181 #undef ferror
182 #undef feof
183 #undef fclose
184 #undef pipe
185 #undef pause
186 #undef sleep
187 #undef times
188 #undef ioctl
189 #undef unlink
190 #undef utime
191 #undef gettimeofday
192 #undef uname
193 #undef wait
194
195 #if defined(__MINGW32__)
196 #undef fileno
197 #endif
198
199 #define stderr                          win32_stderr()
200 #define stdout                          win32_stdout()
201 #define stdin                           win32_stdin()
202 #define feof(f)                         win32_feof(f)
203 #define ferror(f)                       win32_ferror(f)
204 #define errno                           (*win32_errno())
205 #define environ                         (*win32_environ())
206
207 /*
208  * redirect to our own version
209  */
210 #undef fprintf
211 #define fprintf                 win32_fprintf
212 #define vfprintf                win32_vfprintf
213 #define printf                  win32_printf
214 #define vprintf                 win32_vprintf
215 #define fread(buf,size,count,f) win32_fread(buf,size,count,f)
216 #define fwrite(buf,size,count,f)        win32_fwrite(buf,size,count,f)
217 #define fopen                   win32_fopen
218 #undef fdopen
219 #define fdopen                  win32_fdopen
220 #define freopen                 win32_freopen
221 #define fclose(f)               win32_fclose(f)
222 #define fputs(s,f)              win32_fputs(s,f)
223 #define fputc(c,f)              win32_fputc(c,f)
224 #define ungetc(c,f)             win32_ungetc(c,f)
225 #undef getc
226 #define getc(f)                 win32_getc(f)
227 #define fileno(f)               win32_fileno(f)
228 #define clearerr(f)             win32_clearerr(f)
229 #define fflush(f)               win32_fflush(f)
230 #define ftell(f)                win32_ftell(f)
231 #define fseek(f,o,w)            win32_fseek(f,o,w)
232 #define fgetpos(f,p)            win32_fgetpos(f,p)
233 #define fsetpos(f,p)            win32_fsetpos(f,p)
234 #define rewind(f)               win32_rewind(f)
235 #define tmpfile()               win32_tmpfile()
236 #define abort()                 win32_abort()
237 #ifdef __MINGW32__
238 #  undef fstat
239 #endif
240 #define fstat(fd,bufptr)        win32_fstat(fd,bufptr)
241 #ifdef __MINGW32__
242 #  undef stat
243 #endif
244 #define stat(pth,bufptr)        win32_stat(pth,bufptr)
245 #define lstat(pth,bufptr)       win32_lstat(pth,bufptr)
246 #define longpath(pth)           win32_longpath(pth)
247 #define ansipath(pth)           win32_ansipath(pth)
248 #define rename(old,new)         win32_rename(old,new)
249 #define setmode(fd,mode)        win32_setmode(fd,mode)
250 #define chsize(fd,sz)           win32_chsize(fd,sz)
251 #define lseek(fd,offset,orig)   win32_lseek(fd,offset,orig)
252 #define tell(fd)                win32_tell(fd)
253 #define dup(fd)                 win32_dup(fd)
254 #define dup2(fd1,fd2)           win32_dup2(fd1,fd2)
255 #define open                    win32_open
256 #define close(fd)               win32_close(fd)
257 #define eof(fd)                 win32_eof(fd)
258 #define isatty(fd)              win32_isatty(fd)
259 #define read(fd,b,s)            win32_read(fd,b,s)
260 #define write(fd,b,s)           win32_write(fd,b,s)
261 #define _open_osfhandle         win32_open_osfhandle
262 #define _get_osfhandle          win32_get_osfhandle
263 #define spawnvp                 win32_spawnvp
264 #define mkdir                   win32_mkdir
265 #define rmdir                   win32_rmdir
266 #define chdir                   win32_chdir
267 #define flock(fd,o)             win32_flock(fd,o)
268 #define execv                   win32_execv
269 #define execvp                  win32_execvp
270 #define perror                  win32_perror
271 #define setbuf                  win32_setbuf
272 #define setvbuf                 win32_setvbuf
273 #undef flushall
274 #define flushall                win32_flushall
275 #undef fcloseall
276 #define fcloseall               win32_fcloseall
277 #define fgets                   win32_fgets
278 #define gets                    win32_gets
279 #define fgetc                   win32_fgetc
280 #undef putc
281 #define putc                    win32_putc
282 #define puts                    win32_puts
283 #undef getchar
284 #define getchar                 win32_getchar
285 #undef putchar
286 #define putchar                 win32_putchar
287 #define access(p,m)             win32_access(p,m)
288 #define chmod(p,m)              win32_chmod(p,m)
289
290
291 #if !defined(MYMALLOC) || !defined(PERL_CORE)
292 #undef malloc
293 #undef calloc
294 #undef realloc
295 #undef free
296 #define malloc                  win32_malloc
297 #define calloc                  win32_calloc
298 #define realloc                 win32_realloc
299 #define free                    win32_free
300 #endif
301
302 /* XXX Why are APIs like sleep(), times() etc. inside a block
303  * XXX guarded by "#ifndef WIN32IO_IS_STDIO"?
304  */
305
306 #define pipe(fd)                win32_pipe((fd), 512, O_BINARY)
307 #define pause                   win32_pause
308 #define sleep                   win32_sleep
309 #define times                   win32_times
310 #define ioctl                   win32_ioctl
311 #define link                    win32_link
312 #define unlink                  win32_unlink
313 #define utime                   win32_utime
314 #define gettimeofday            win32_gettimeofday
315 #define uname                   win32_uname
316 #define wait                    win32_wait
317 #define waitpid                 win32_waitpid
318 #define kill                    win32_kill
319 #define killpg(pid, sig)        win32_kill(pid, -(sig))
320
321
322 #define opendir                 win32_opendir
323 #define readdir                 win32_readdir
324 #define telldir                 win32_telldir
325 #define seekdir                 win32_seekdir
326 #define rewinddir               win32_rewinddir
327 #define closedir                win32_closedir
328 #define os_id                   win32_os_id
329 #define getpid                  win32_getpid
330
331 #undef crypt
332 #define crypt(t,s)              win32_crypt(t,s)
333
334 #undef get_childenv
335 #undef free_childenv
336 #undef clearenv
337 #undef get_childdir
338 #undef free_childdir
339 #define get_childenv()          win32_get_childenv()
340 #define free_childenv(d)        win32_free_childenv(d)
341 #define clearenv()              win32_clearenv()
342 #define get_childdir()          win32_get_childdir()
343 #define free_childdir(d)        win32_free_childdir(d)
344
345 #undef getenv
346 #define getenv win32_getenv
347 #undef putenv
348 #define putenv win32_putenv
349
350 #endif /* WIN32IO_IS_STDIO */
351 #endif /* WIN32IOP_H */