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