Initial (untested) merge of all non-ansi changes on ansiperl branch
[p5sagit/p5-mst-13.2.git] / win32 / win32iop.h
1 #ifndef WIN32IOP_H
2 #define WIN32IOP_H
3
4 /*
5  * defines for flock emulation
6  */
7 #define LOCK_SH 1
8 #define LOCK_EX 2
9 #define LOCK_NB 4
10 #define LOCK_UN 8
11
12 #include <win32io.h>    /* pull in the io sub system structure */
13
14 /*
15  * Make this as close to original stdio as possible.
16  */
17
18 /*
19  * function prototypes for our own win32io layer
20  */
21 START_EXTERN_C
22
23 EXT int *       win32_errno(void);
24 EXT char ***    win32_environ(void);
25 EXT FILE*       win32_stdin(void);
26 EXT FILE*       win32_stdout(void);
27 EXT FILE*       win32_stderr(void);
28 EXT int         win32_ferror(FILE *fp);
29 EXT int         win32_feof(FILE *fp);
30 EXT char*       win32_strerror(int e);
31
32 EXT int         win32_fprintf(FILE *pf, const char *format, ...);
33 EXT int         win32_printf(const char *format, ...);
34 EXT int         win32_vfprintf(FILE *pf, const char *format, va_list arg);
35 EXT int         win32_vprintf(const char *format, va_list arg);
36 EXT size_t      win32_fread(void *buf, size_t size, size_t count, FILE *pf);
37 EXT size_t      win32_fwrite(const void *buf, size_t size, size_t count, FILE *pf);
38 EXT FILE*       win32_fopen(const char *path, const char *mode);
39 EXT FILE*       win32_fdopen(int fh, const char *mode);
40 EXT FILE*       win32_freopen(const char *path, const char *mode, FILE *pf);
41 EXT int         win32_fclose(FILE *pf);
42 EXT int         win32_fputs(const char *s,FILE *pf);
43 EXT int         win32_fputc(int c,FILE *pf);
44 EXT int         win32_ungetc(int c,FILE *pf);
45 EXT int         win32_getc(FILE *pf);
46 EXT int         win32_fileno(FILE *pf);
47 EXT void        win32_clearerr(FILE *pf);
48 EXT int         win32_fflush(FILE *pf);
49 EXT long        win32_ftell(FILE *pf);
50 EXT int         win32_fseek(FILE *pf,long offset,int origin);
51 EXT int         win32_fgetpos(FILE *pf,fpos_t *p);
52 EXT int         win32_fsetpos(FILE *pf,const fpos_t *p);
53 EXT void        win32_rewind(FILE *pf);
54 EXT FILE*       win32_tmpfile(void);
55 EXT void        win32_abort(void);
56 EXT int         win32_fstat(int fd,struct stat *bufptr);
57 EXT int         win32_stat(const char *name,struct stat *bufptr);
58 EXT int         win32_pipe( int *phandles, unsigned int psize, int textmode );
59 EXT FILE*       win32_popen( const char *command, const char *mode );
60 EXT int         win32_pclose( FILE *pf);
61 EXT int         win32_setmode( int fd, int mode);
62 EXT long        win32_lseek( int fd, long offset, int origin);
63 EXT long        win32_tell( int fd);
64 EXT int         win32_dup( int fd);
65 EXT int         win32_dup2(int h1, int h2);
66 EXT int         win32_open(const char *path, int oflag,...);
67 EXT int         win32_close(int fd);
68 EXT int         win32_eof(int fd);
69 EXT int         win32_read(int fd, void *buf, unsigned int cnt);
70 EXT int         win32_write(int fd, const void *buf, unsigned int cnt);
71 EXT int         win32_spawnvp(int mode, const char *cmdname,
72                               const char *const *argv);
73 EXT int         win32_mkdir(const char *dir, int mode);
74 EXT int         win32_rmdir(const char *dir);
75 EXT int         win32_chdir(const char *dir);
76 EXT int         win32_flock(int fd, int oper);
77 EXT int         win32_execvp(const char *cmdname, const char *const *argv);
78 EXT void        win32_perror(const char *str);
79 EXT void        win32_setbuf(FILE *pf, char *buf);
80 EXT int         win32_setvbuf(FILE *pf, char *buf, int type, size_t size);
81 EXT int         win32_flushall(void);
82 EXT int         win32_fcloseall(void);
83 EXT char*       win32_fgets(char *s, int n, FILE *pf);
84 EXT char*       win32_gets(char *s);
85 EXT int         win32_fgetc(FILE *pf);
86 EXT int         win32_putc(int c, FILE *pf);
87 EXT int         win32_puts(const char *s);
88 EXT int         win32_getchar(void);
89 EXT int         win32_putchar(int c);
90 EXT void*       win32_malloc(size_t size);
91 EXT void*       win32_calloc(size_t numitems, size_t size);
92 EXT void*       win32_realloc(void *block, size_t size);
93 EXT void        win32_free(void *block);
94
95
96
97 /*
98  * these two are win32 specific but still io related
99  */
100 int             stolen_open_osfhandle(long handle, int flags);
101 long            stolen_get_osfhandle(int fd);
102
103
104 EXT PWIN32_IOSUBSYSTEM  SetIOSubSystem(void     *piosubsystem);
105 EXT PWIN32_IOSUBSYSTEM  GetIOSubSystem(void);
106
107 END_EXTERN_C
108
109 /*
110  * the following six(6) is #define in stdio.h
111  */
112 #ifndef WIN32IO_IS_STDIO
113 #undef errno
114 #undef environ
115 #undef stderr
116 #undef stdin
117 #undef stdout
118 #undef ferror
119 #undef feof
120
121 #ifdef __BORLANDC__
122 #undef ungetc
123 #undef getc
124 #undef putc
125 #undef getchar
126 #undef putchar
127 #undef fileno
128 #endif
129
130 #define stderr                          win32_stderr()
131 #define stdout                          win32_stdout()
132 #define stdin                           win32_stdin()
133 #define feof(f)                         win32_feof(f)
134 #define ferror(f)                       win32_ferror(f)
135 #define errno                           (*win32_errno())
136 #define environ                         (*win32_environ())
137 #define strerror                        win32_strerror
138
139 /*
140  * redirect to our own version
141  */
142 #define fprintf                 win32_fprintf
143 #define vfprintf                win32_vfprintf
144 #define printf                  win32_printf
145 #define vprintf                 win32_vprintf
146 #define fread(buf,size,count,f) win32_fread(buf,size,count,f)
147 #define fwrite(buf,size,count,f)        win32_fwrite(buf,size,count,f)
148 #define fopen                   win32_fopen
149 #define fdopen                  win32_fdopen
150 #define freopen                 win32_freopen
151 #define fclose(f)               win32_fclose(f)
152 #define fputs(s,f)              win32_fputs(s,f)
153 #define fputc(c,f)              win32_fputc(c,f)
154 #define ungetc(c,f)             win32_ungetc(c,f)
155 #define getc(f)                 win32_getc(f)
156 #define fileno(f)               win32_fileno(f)
157 #define clearerr(f)             win32_clearerr(f)
158 #define fflush(f)               win32_fflush(f)
159 #define ftell(f)                win32_ftell(f)
160 #define fseek(f,o,w)            win32_fseek(f,o,w)
161 #define fgetpos(f,p)            win32_fgetpos(f,p)
162 #define fsetpos(f,p)            win32_fsetpos(f,p)
163 #define rewind(f)               win32_rewind(f)
164 #define tmpfile()               win32_tmpfile()
165 #define abort()                 win32_abort()
166 #define fstat(fd,bufptr)        win32_fstat(fd,bufptr)
167 #define stat(pth,bufptr)        win32_stat(pth,bufptr)
168 #define setmode(fd,mode)        win32_setmode(fd,mode)
169 #define lseek(fd,offset,orig)   win32_lseek(fd,offset,orig)
170 #define tell(fd)                win32_tell(fd)
171 #define dup(fd)                 win32_dup(fd)
172 #define dup2(fd1,fd2)           win32_dup2(fd1,fd2)
173 #define open                    win32_open
174 #define close(fd)               win32_close(fd)
175 #define eof(fd)                 win32_eof(fd)
176 #define read(fd,b,s)            win32_read(fd,b,s)
177 #define write(fd,b,s)           win32_write(fd,b,s)
178 #define _open_osfhandle         stolen_open_osfhandle
179 #define _get_osfhandle          stolen_get_osfhandle
180 #define spawnvp                 win32_spawnvp
181 #define mkdir                   win32_mkdir
182 #define rmdir                   win32_rmdir
183 #define chdir                   win32_chdir
184 #define flock(fd,o)             win32_flock(fd,o)
185 #define execvp                  win32_execvp
186 #define perror                  win32_perror
187 #define setbuf                  win32_setbuf
188 #define setvbuf                 win32_setvbuf
189 #define flushall                win32_flushall
190 #define fcloseall               win32_fcloseall
191 #define fgets                   win32_fgets
192 #define gets                    win32_gets
193 #define fgetc                   win32_fgetc
194 #define putc                    win32_putc
195 #define puts                    win32_puts
196 #define getchar                 win32_getchar
197 #define putchar                 win32_putchar
198 #define fscanf                  (GetIOSubSystem()->pfnfscanf)
199 #define scanf                   (GetIOSubSystem()->pfnscanf)
200 #define malloc                  win32_malloc
201 #define calloc                  win32_calloc
202 #define realloc                 win32_realloc
203 #define free                    win32_free
204 #endif /* WIN32IO_IS_STDIO */
205
206 #endif /* WIN32IOP_H */