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 FILE* win32_tmpfile(void); 68 DllExport void win32_abort(void); 69 DllExport int win32_fstat(int fd,Stat_t *sbufptr); 70 DllExport int win32_stat(const char *name,Stat_t *sbufptr); 71 DllExport int win32_pipe( int *phandles, unsigned int psize, int textmode ); 72 DllExport PerlIO* win32_popen( const char *command, const char *mode ); 73 DllExport PerlIO* win32_popenlist(const char *mode, IV narg, SV **args); 74 DllExport int win32_pclose( PerlIO *pf); 75 DllExport int win32_rename( const char *oname, const char *newname); 76 DllExport int win32_setmode( int fd, int mode); 77 DllExport int win32_chsize(int fd, Off_t size); 78 DllExport Off_t win32_lseek( int fd, Off_t offset, int origin); 79 DllExport Off_t win32_tell( int fd); 80 DllExport int win32_dup( int fd); 81 DllExport int win32_dup2(int h1, int h2); 82 DllExport int win32_open(const char *path, int oflag,...); 83 DllExport int win32_close(int fd); 84 DllExport int win32_eof(int fd); 85 DllExport int win32_isatty(int fd); 86 DllExport int win32_read(int fd, void *buf, unsigned int cnt); 87 DllExport int win32_write(int fd, const void *buf, unsigned int cnt); 88 DllExport int win32_spawnvp(int mode, const char *cmdname, 89 const char *const *argv); 90 DllExport int win32_mkdir(const char *dir, int mode); 91 DllExport int win32_rmdir(const char *dir); 92 DllExport int win32_chdir(const char *dir); 93 DllExport int win32_flock(int fd, int oper); 94 DllExport int win32_execv(const char *cmdname, const char *const *argv); 95 DllExport int win32_execvp(const char *cmdname, const char *const *argv); 96 DllExport void win32_perror(const char *str); 97 DllExport void win32_setbuf(FILE *pf, char *buf); 98 DllExport int win32_setvbuf(FILE *pf, char *buf, int type, size_t size); 99 DllExport int win32_flushall(void); 100 DllExport int win32_fcloseall(void); 101 DllExport char* win32_fgets(char *s, int n, FILE *pf); 102 DllExport char* win32_gets(char *s); 103 DllExport int win32_fgetc(FILE *pf); 104 DllExport int win32_putc(int c, FILE *pf); 105 DllExport int win32_puts(const char *s); 106 DllExport int win32_getchar(void); 107 DllExport int win32_putchar(int c); 108 DllExport void* win32_malloc(size_t size); 109 DllExport void* win32_calloc(size_t numitems, size_t size); 110 DllExport void* win32_realloc(void *block, size_t size); 111 DllExport void win32_free(void *block); 112 113 DllExport int win32_open_osfhandle(intptr_t handle, int flags); 114 DllExport intptr_t win32_get_osfhandle(int fd); 115 DllExport FILE* win32_fdupopen(FILE *pf); 116 117 DllExport DIR* win32_opendir(const char *filename); 118 DllExport struct direct* win32_readdir(DIR *dirp); 119 DllExport long win32_telldir(DIR *dirp); 120 DllExport void win32_seekdir(DIR *dirp, long loc); 121 DllExport void win32_rewinddir(DIR *dirp); 122 DllExport int win32_closedir(DIR *dirp); 123 DllExport DIR* win32_dirp_dup(DIR *const dirp, CLONE_PARAMS *const param); 124 125 DllExport char* win32_getenvironmentstrings(void); 126 /* also see win32_freeenvironmentstrings macro */ 127 DllExport char* win32_getenv(const char *name); 128 DllExport int win32_putenv(const char *name); 129 130 DllExport unsigned win32_sleep(unsigned int); 131 DllExport int win32_pause(void); 132 DllExport int win32_times(struct tms *timebuf); 133 DllExport unsigned win32_alarm(unsigned int sec); 134 DllExport char* win32_longpath(char *path); 135 DllExport char* win32_ansipath(const WCHAR *path); 136 DllExport int win32_ioctl(int i, unsigned int u, char *data); 137 DllExport int win32_link(const char *oldname, const char *newname); 138 DllExport int win32_unlink(const char *f); 139 DllExport int win32_utime(const char *f, struct utimbuf *t); 140 DllExport int win32_gettimeofday(struct timeval *tp, void *not_used); 141 DllExport int win32_uname(struct utsname *n); 142 DllExport int win32_wait(int *status); 143 DllExport int win32_waitpid(int pid, int *status, int flags); 144 DllExport int win32_kill(int pid, int sig); 145 DllExport unsigned long win32_os_id(void); 146 DllExport void* win32_dynaload(const char*filename); 147 DllExport int win32_access(const char *path, int mode); 148 DllExport int win32_chmod(const char *path, int mode); 149 DllExport int win32_getpid(void); 150 151 DllExport char * win32_crypt(const char *txt, const char *salt); 152 153 DllExport void * win32_get_childenv(void); 154 DllExport void win32_free_childenv(void* d); 155 DllExport void win32_clearenv(void); 156 DllExport char * win32_get_childdir(void); 157 DllExport void win32_free_childdir(char* d); 158 DllExport Sighandler_t win32_signal(int sig, Sighandler_t subcode); 159 160 161 END_EXTERN_C 162 163 /* see comment in win32_getenvironmentstrings */ 164 #define win32_freeenvironmentstrings(x) win32_free(x) 165 #undef alarm 166 #define alarm win32_alarm 167 #undef strerror 168 #define strerror win32_strerror 169 170 /* 171 * the following six(6) is #define in stdio.h 172 */ 173 #ifndef WIN32IO_IS_STDIO 174 #undef errno 175 #undef environ 176 #undef stderr 177 #undef stdin 178 #undef stdout 179 #undef ferror 180 #undef feof 181 #undef fclose 182 #undef pipe 183 #undef pause 184 #undef sleep 185 #undef times 186 #undef ioctl 187 #undef unlink 188 #undef utime 189 #undef gettimeofday 190 #undef uname 191 #undef wait 192 193 #if defined(__MINGW32__) 194 #undef fileno 195 #endif 196 197 #define stderr win32_stderr() 198 #define stdout win32_stdout() 199 #define stdin win32_stdin() 200 #define feof(f) win32_feof(f) 201 #define ferror(f) win32_ferror(f) 202 #define errno (*win32_errno()) 203 #define environ (*win32_environ()) 204 205 /* 206 * redirect to our own version 207 */ 208 #undef fprintf 209 #define fprintf win32_fprintf 210 #ifdef UNDER_CE /* celib also makes these be macros to celib's x* symbols */ 211 # undef vfprintf 212 #endif 213 #define vfprintf win32_vfprintf 214 #ifdef UNDER_CE 215 # undef printf 216 #endif 217 #define printf win32_printf 218 #ifdef UNDER_CE 219 # undef vprintf 220 #endif 221 #define vprintf win32_vprintf 222 #ifdef UNDER_CE 223 # undef fread 224 #endif 225 #define fread(buf,size,count,f) win32_fread(buf,size,count,f) 226 #ifdef UNDER_CE 227 # undef fwrite 228 #endif 229 #define fwrite(buf,size,count,f) win32_fwrite(buf,size,count,f) 230 #ifdef UNDER_CE 231 # undef fopen 232 #endif 233 #define fopen win32_fopen 234 #undef fdopen 235 #define fdopen win32_fdopen 236 #ifdef UNDER_CE 237 # undef freopen 238 #endif 239 #define freopen win32_freopen 240 #define fclose(f) win32_fclose(f) 241 #ifdef UNDER_CE 242 # undef fputs 243 #endif 244 #define fputs(s,f) win32_fputs(s,f) 245 #ifdef UNDER_CE 246 # undef fputc 247 #endif 248 #define fputc(c,f) win32_fputc(c,f) 249 #ifdef UNDER_CE 250 # undef ungetc 251 #endif 252 #define ungetc(c,f) win32_ungetc(c,f) 253 #undef getc 254 #define getc(f) win32_getc(f) 255 #ifdef UNDER_CE 256 # undef fileno 257 #endif 258 #define fileno(f) win32_fileno(f) 259 #ifdef UNDER_CE 260 # undef clearerr 261 #endif 262 #define clearerr(f) win32_clearerr(f) 263 #ifdef UNDER_CE 264 # undef fflush 265 #endif 266 #define fflush(f) win32_fflush(f) 267 #ifdef UNDER_CE 268 # undef ftell 269 #endif 270 #define ftell(f) win32_ftell(f) 271 #ifdef UNDER_CE 272 # undef fseek 273 #endif 274 #define fseek(f,o,w) win32_fseek(f,o,w) 275 #ifdef UNDER_CE 276 # undef fgetpos 277 #endif 278 #define fgetpos(f,p) win32_fgetpos(f,p) 279 #ifdef UNDER_CE 280 # undef fsetpos 281 #endif 282 #define fsetpos(f,p) win32_fsetpos(f,p) 283 #ifdef UNDER_CE 284 # undef rewind 285 #endif 286 #define rewind(f) win32_rewind(f) 287 #define tmpfile() win32_tmpfile() 288 #ifdef UNDER_CE 289 # undef abort 290 #endif 291 #define abort() win32_abort() 292 #if defined(UNDER_CE) || defined(__MINGW32__) 293 # undef fstat 294 #endif 295 #define fstat(fd,bufptr) win32_fstat(fd,bufptr) 296 #if defined(UNDER_CE) || defined(__MINGW32__) 297 # undef stat 298 #endif 299 #define stat(pth,bufptr) win32_stat(pth,bufptr) 300 #define longpath(pth) win32_longpath(pth) 301 #define ansipath(pth) win32_ansipath(pth) 302 #ifdef UNDER_CE 303 # undef rename 304 #endif 305 #define rename(old,new) win32_rename(old,new) 306 #ifdef UNDER_CE 307 # undef setmode 308 #endif 309 #define setmode(fd,mode) win32_setmode(fd,mode) 310 #define chsize(fd,sz) win32_chsize(fd,sz) 311 #ifdef UNDER_CE 312 # undef lseek 313 #endif 314 #define lseek(fd,offset,orig) win32_lseek(fd,offset,orig) 315 #define tell(fd) win32_tell(fd) 316 #ifdef UNDER_CE 317 # undef dup 318 #endif 319 #define dup(fd) win32_dup(fd) 320 #ifdef UNDER_CE 321 # undef dup2 322 #endif 323 #define dup2(fd1,fd2) win32_dup2(fd1,fd2) 324 #ifdef UNDER_CE 325 # undef open 326 #endif 327 #define open win32_open 328 #ifdef UNDER_CE 329 # undef close 330 #endif 331 #define close(fd) win32_close(fd) 332 #define eof(fd) win32_eof(fd) 333 #ifdef UNDER_CE 334 # undef isatty 335 #endif 336 #define isatty(fd) win32_isatty(fd) 337 #ifdef UNDER_CE 338 # undef read 339 #endif 340 #define read(fd,b,s) win32_read(fd,b,s) 341 #ifdef UNDER_CE 342 # undef write 343 #endif 344 #define write(fd,b,s) win32_write(fd,b,s) 345 #define _open_osfhandle win32_open_osfhandle 346 #ifdef UNDER_CE 347 # undef _get_osfhandle 348 #endif 349 #define _get_osfhandle win32_get_osfhandle 350 #define spawnvp win32_spawnvp 351 #ifdef UNDER_CE 352 # undef mkdir 353 #endif 354 #define mkdir win32_mkdir 355 #ifdef UNDER_CE 356 # undef rmdir 357 #endif 358 #define rmdir win32_rmdir 359 #ifdef UNDER_CE 360 # undef chdir 361 #endif 362 #define chdir win32_chdir 363 #define flock(fd,o) win32_flock(fd,o) 364 #ifdef UNDER_CE 365 # undef execv 366 #endif 367 #define execv win32_execv 368 #ifdef UNDER_CE 369 # undef execvp 370 #endif 371 #define execvp win32_execvp 372 #ifdef UNDER_CE 373 # undef perror 374 #endif 375 #define perror win32_perror 376 #define setbuf win32_setbuf 377 #ifdef UNDER_CE 378 # undef setvbuf 379 #endif 380 #define setvbuf win32_setvbuf 381 #undef flushall 382 #define flushall win32_flushall 383 #undef fcloseall 384 #define fcloseall win32_fcloseall 385 #ifdef UNDER_CE 386 # undef fgets 387 #endif 388 #define fgets win32_fgets 389 #ifdef UNDER_CE 390 # undef gets 391 #endif 392 #define gets win32_gets 393 #ifdef UNDER_CE 394 # undef fgetc 395 #endif 396 #define fgetc win32_fgetc 397 #undef putc 398 #define putc win32_putc 399 #ifdef UNDER_CE 400 # undef puts 401 #endif 402 #define puts win32_puts 403 #undef getchar 404 #define getchar win32_getchar 405 #undef putchar 406 #define putchar win32_putchar 407 #ifdef UNDER_CE 408 # undef access 409 #endif 410 #define access(p,m) win32_access(p,m) 411 #ifdef UNDER_CE 412 # undef chmod 413 #endif 414 #define chmod(p,m) win32_chmod(p,m) 415 416 417 #if !defined(MYMALLOC) || !defined(PERL_CORE) 418 #undef malloc 419 #undef calloc 420 #undef realloc 421 #undef free 422 #define malloc win32_malloc 423 #define calloc win32_calloc 424 #define realloc win32_realloc 425 #define free win32_free 426 #endif 427 428 /* XXX Why are APIs like sleep(), times() etc. inside a block 429 * XXX guarded by "#ifndef WIN32IO_IS_STDIO"? 430 */ 431 432 #define pipe(fd) win32_pipe((fd), 512, O_BINARY) 433 #define pause win32_pause 434 #define sleep win32_sleep 435 #define times win32_times 436 #define ioctl win32_ioctl 437 #define link win32_link 438 #define unlink win32_unlink 439 #define utime win32_utime 440 #ifdef UNDER_CE 441 # undef gettimeofday 442 #endif 443 #define gettimeofday win32_gettimeofday 444 #define uname win32_uname 445 #define wait win32_wait 446 #define waitpid win32_waitpid 447 #ifdef UNDER_CE 448 # undef kill 449 #endif 450 #define kill win32_kill 451 #ifdef UNDER_CE 452 # undef killpg 453 #endif 454 #define killpg(pid, sig) win32_kill(pid, -(sig)) 455 456 457 #ifdef UNDER_CE 458 # undef opendir 459 #endif 460 #define opendir win32_opendir 461 #ifdef UNDER_CE 462 # undef readdir 463 #endif 464 #define readdir win32_readdir 465 #define telldir win32_telldir 466 #define seekdir win32_seekdir 467 #define rewinddir win32_rewinddir 468 #ifdef UNDER_CE 469 # undef closedir 470 #endif 471 #define closedir win32_closedir 472 #define os_id win32_os_id 473 #ifdef UNDER_CE 474 # undef getpid 475 #endif 476 #define getpid win32_getpid 477 478 #undef crypt 479 #define crypt(t,s) win32_crypt(t,s) 480 481 #undef get_childenv 482 #undef free_childenv 483 #undef clearenv 484 #undef get_childdir 485 #undef free_childdir 486 #define get_childenv() win32_get_childenv() 487 #define free_childenv(d) win32_free_childenv(d) 488 #define clearenv() win32_clearenv() 489 #define get_childdir() win32_get_childdir() 490 #define free_childdir(d) win32_free_childdir(d) 491 492 #undef getenv 493 #define getenv win32_getenv 494 #undef putenv 495 #define putenv win32_putenv 496 497 #endif /* WIN32IO_IS_STDIO */ 498 #endif /* WIN32IOP_H */ 499