More cleanups of win32/win32*.[ch] files. win32/win32iop.h now
[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 struct tms {
34         long    tms_utime;
35         long    tms_stime;
36         long    tms_cutime;
37         long    tms_cstime;
38 };
39
40 EXT int *       win32_errno(void);
41 EXT char ***    win32_environ(void);
42 EXT FILE*       win32_stdin(void);
43 EXT FILE*       win32_stdout(void);
44 EXT FILE*       win32_stderr(void);
45 EXT int         win32_ferror(FILE *fp);
46 EXT int         win32_feof(FILE *fp);
47 EXT char*       win32_strerror(int e);
48
49 EXT int         win32_fprintf(FILE *pf, const char *format, ...);
50 EXT int         win32_printf(const char *format, ...);
51 EXT int         win32_vfprintf(FILE *pf, const char *format, va_list arg);
52 EXT int         win32_vprintf(const char *format, va_list arg);
53 EXT size_t      win32_fread(void *buf, size_t size, size_t count, FILE *pf);
54 EXT size_t      win32_fwrite(const void *buf, size_t size, size_t count, FILE *pf);
55 EXT FILE*       win32_fopen(const char *path, const char *mode);
56 EXT FILE*       win32_fdopen(int fh, const char *mode);
57 EXT FILE*       win32_freopen(const char *path, const char *mode, FILE *pf);
58 EXT int         win32_fclose(FILE *pf);
59 EXT int         win32_fputs(const char *s,FILE *pf);
60 EXT int         win32_fputc(int c,FILE *pf);
61 EXT int         win32_ungetc(int c,FILE *pf);
62 EXT int         win32_getc(FILE *pf);
63 EXT int         win32_fileno(FILE *pf);
64 EXT void        win32_clearerr(FILE *pf);
65 EXT int         win32_fflush(FILE *pf);
66 EXT long        win32_ftell(FILE *pf);
67 EXT int         win32_fseek(FILE *pf,long offset,int origin);
68 EXT int         win32_fgetpos(FILE *pf,fpos_t *p);
69 EXT int         win32_fsetpos(FILE *pf,const fpos_t *p);
70 EXT void        win32_rewind(FILE *pf);
71 EXT FILE*       win32_tmpfile(void);
72 EXT void        win32_abort(void);
73 EXT int         win32_fstat(int fd,struct stat *bufptr);
74 EXT int         win32_stat(const char *name,struct stat *bufptr);
75 EXT int         win32_pipe( int *phandles, unsigned int psize, int textmode );
76 EXT FILE*       win32_popen( const char *command, const char *mode );
77 EXT int         win32_pclose( FILE *pf);
78 EXT int         win32_setmode( int fd, int mode);
79 EXT long        win32_lseek( int fd, long offset, int origin);
80 EXT long        win32_tell( int fd);
81 EXT int         win32_dup( int fd);
82 EXT int         win32_dup2(int h1, int h2);
83 EXT int         win32_open(const char *path, int oflag,...);
84 EXT int         win32_close(int fd);
85 EXT int         win32_eof(int fd);
86 EXT int         win32_read(int fd, void *buf, unsigned int cnt);
87 EXT int         win32_write(int fd, const void *buf, unsigned int cnt);
88 EXT int         win32_spawnvp(int mode, const char *cmdname,
89                               const char *const *argv);
90 EXT int         win32_mkdir(const char *dir, int mode);
91 EXT int         win32_rmdir(const char *dir);
92 EXT int         win32_chdir(const char *dir);
93 EXT int         win32_flock(int fd, int oper);
94 EXT int         win32_execvp(const char *cmdname, const char *const *argv);
95 EXT void        win32_perror(const char *str);
96 EXT void        win32_setbuf(FILE *pf, char *buf);
97 EXT int         win32_setvbuf(FILE *pf, char *buf, int type, size_t size);
98 EXT int         win32_flushall(void);
99 EXT int         win32_fcloseall(void);
100 EXT char*       win32_fgets(char *s, int n, FILE *pf);
101 EXT char*       win32_gets(char *s);
102 EXT int         win32_fgetc(FILE *pf);
103 EXT int         win32_putc(int c, FILE *pf);
104 EXT int         win32_puts(const char *s);
105 EXT int         win32_getchar(void);
106 EXT int         win32_putchar(int c);
107 EXT void*       win32_malloc(size_t size);
108 EXT void*       win32_calloc(size_t numitems, size_t size);
109 EXT void*       win32_realloc(void *block, size_t size);
110 EXT void        win32_free(void *block);
111
112 EXT int         win32_open_osfhandle(long handle, int flags);
113 EXT long        win32_get_osfhandle(int fd);
114
115 #ifndef USE_WIN32_RTL_ENV
116 EXT char*       win32_getenv(const char *name);
117 #endif
118
119 EXT unsigned int        win32_sleep(unsigned int);
120 EXT int                 win32_times(struct tms *timebuf);
121 EXT unsigned int        win32_alarm(unsigned int sec);
122 EXT int                 win32_flock(int fd, int oper);
123 EXT int                 win32_stat(const char *path, struct stat *buf);
124
125 END_EXTERN_C
126
127 /*
128  * the following six(6) is #define in stdio.h
129  */
130 #ifndef WIN32IO_IS_STDIO
131 #undef errno
132 #undef environ
133 #undef stderr
134 #undef stdin
135 #undef stdout
136 #undef ferror
137 #undef feof
138 #undef fclose
139 #undef pipe
140 #undef pause
141 #undef sleep
142 #undef times
143 #undef alarm
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 #define fdopen                  win32_fdopen
174 #define freopen                 win32_freopen
175 #define fclose(f)               win32_fclose(f)
176 #define fputs(s,f)              win32_fputs(s,f)
177 #define fputc(c,f)              win32_fputc(c,f)
178 #define ungetc(c,f)             win32_ungetc(c,f)
179 #define getc(f)                 win32_getc(f)
180 #define fileno(f)               win32_fileno(f)
181 #define clearerr(f)             win32_clearerr(f)
182 #define fflush(f)               win32_fflush(f)
183 #define ftell(f)                win32_ftell(f)
184 #define fseek(f,o,w)            win32_fseek(f,o,w)
185 #define fgetpos(f,p)            win32_fgetpos(f,p)
186 #define fsetpos(f,p)            win32_fsetpos(f,p)
187 #define rewind(f)               win32_rewind(f)
188 #define tmpfile()               win32_tmpfile()
189 #define abort()                 win32_abort()
190 #define fstat(fd,bufptr)        win32_fstat(fd,bufptr)
191 #define stat(pth,bufptr)        win32_stat(pth,bufptr)
192 #define setmode(fd,mode)        win32_setmode(fd,mode)
193 #define lseek(fd,offset,orig)   win32_lseek(fd,offset,orig)
194 #define tell(fd)                win32_tell(fd)
195 #define dup(fd)                 win32_dup(fd)
196 #define dup2(fd1,fd2)           win32_dup2(fd1,fd2)
197 #define open                    win32_open
198 #define close(fd)               win32_close(fd)
199 #define eof(fd)                 win32_eof(fd)
200 #define read(fd,b,s)            win32_read(fd,b,s)
201 #define write(fd,b,s)           win32_write(fd,b,s)
202 #define _open_osfhandle         win32_open_osfhandle
203 #define _get_osfhandle          win32_get_osfhandle
204 #define spawnvp                 win32_spawnvp
205 #define mkdir                   win32_mkdir
206 #define rmdir                   win32_rmdir
207 #define chdir                   win32_chdir
208 #define flock(fd,o)             win32_flock(fd,o)
209 #define execvp                  win32_execvp
210 #define perror                  win32_perror
211 #define setbuf                  win32_setbuf
212 #define setvbuf                 win32_setvbuf
213 #define flushall                win32_flushall
214 #define fcloseall               win32_fcloseall
215 #define fgets                   win32_fgets
216 #define gets                    win32_gets
217 #define fgetc                   win32_fgetc
218 #define putc                    win32_putc
219 #define puts                    win32_puts
220 #define getchar                 win32_getchar
221 #define putchar                 win32_putchar
222 #define malloc                  win32_malloc
223 #define calloc                  win32_calloc
224 #define realloc                 win32_realloc
225 #define free                    win32_free
226
227 #define pipe(fd)                win32_pipe((fd), 512, O_BINARY)
228 #define pause()                 win32_sleep((32767L << 16) + 32767)
229 #define sleep                   win32_sleep
230 #define times                   win32_times
231 #define alarm                   win32_alarm
232
233 #ifndef USE_WIN32_RTL_ENV
234 #undef getenv
235 #define getenv win32_getenv
236 #endif
237
238 #endif /* WIN32IO_IS_STDIO */
239 #endif /* WIN32IOP_H */