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