PageRenderTime 204ms CodeModel.GetById 177ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/i386-mingw32/win32/win32.h

http://github.com/agross/netopenspace
C Header | 626 lines | 513 code | 76 blank | 37 comment | 21 complexity | 9aab4c77e6ac66ba004888efa335edae MD5 | raw file
  1#ifndef RUBY_WIN32_H
  2#define RUBY_WIN32_H
  3
  4/*
  5 *  Copyright (c) 1993, Intergraph Corporation
  6 *
  7 *  You may distribute under the terms of either the GNU General Public
  8 *  License or the Artistic License, as specified in the perl README file.
  9 *
 10 */
 11
 12//
 13// Definitions for NT port of Perl
 14//
 15
 16
 17//
 18// Ok now we can include the normal include files.
 19//
 20
 21// #include <stdarg.h> conflict with varargs.h?
 22#if !defined(IN) && !defined(FLOAT)
 23#ifdef __BORLANDC__
 24#define USE_WINSOCK2
 25#endif
 26#ifdef USE_WINSOCK2
 27#include <winsock2.h>
 28#include <ws2tcpip.h>
 29#include <windows.h>
 30#else
 31#include <windows.h>
 32#include <winsock.h>
 33#endif
 34#endif
 35
 36#define NT 1			/* deprecated */
 37
 38#ifdef _WIN32_WCE
 39#undef CharNext
 40#define CharNext CharNextA
 41#endif
 42
 43//
 44// We're not using Microsoft's "extensions" to C for
 45// Structured Exception Handling (SEH) so we can nuke these
 46//
 47#undef try
 48#undef except
 49#undef finally
 50#undef leave
 51
 52#include <stdio.h>
 53#include <stdlib.h>
 54#include <string.h>
 55#include <direct.h>
 56#include <process.h>
 57#include <time.h>
 58#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
 59extern "C++" {			/* template without extern "C++" */
 60#endif
 61#include <math.h>
 62#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
 63}
 64#endif
 65#include <signal.h>
 66#include <sys/stat.h>
 67#include <sys/types.h>
 68#if !defined(__BORLANDC__)
 69# include <sys/utime.h>
 70#else
 71# include <utime.h>
 72#endif
 73#include <io.h>
 74#include <malloc.h>
 75
 76#ifdef _M_IX86
 77# define WIN95 1
 78#else
 79# undef  WIN95
 80#endif
 81
 82#ifdef WIN95
 83extern DWORD rb_w32_osid(void);
 84#define rb_w32_iswinnt()  (rb_w32_osid() == VER_PLATFORM_WIN32_NT)
 85#define rb_w32_iswin95()  (rb_w32_osid() == VER_PLATFORM_WIN32_WINDOWS)
 86#else
 87#define rb_w32_iswinnt()  TRUE
 88#define rb_w32_iswin95()  FALSE
 89#endif
 90
 91#define WNOHANG -1
 92
 93#undef getc
 94#undef putc
 95#undef fgetc
 96#undef fputc
 97#undef getchar
 98#undef putchar
 99#undef fgetchar
100#undef fputchar
101#undef utime
102#define getc(_stream)		rb_w32_getc(_stream)
103#define putc(_c, _stream)	rb_w32_putc(_c, _stream)
104#define fgetc(_stream)		getc(_stream)
105#define fputc(_c, _stream)	putc(_c, _stream)
106#define getchar()		rb_w32_getc(stdin)
107#define putchar(_c)		rb_w32_putc(_c, stdout)
108#define fgetchar()		getchar()
109#define fputchar(_c)		putchar(_c)
110#define utime(_p, _t)		rb_w32_utime(_p, _t)
111
112#define strcasecmp(s1, s2)	stricmp(s1, s2)
113#define strncasecmp(s1, s2, n)	strnicmp(s1, s2, n)
114
115#define close(h)		rb_w32_close(h)
116#define fclose(f)		rb_w32_fclose(f)
117#define read(f, b, s)		rb_w32_read(f, b, s)
118#define write(f, b, s)		rb_w32_write(f, b, s)
119#define getpid()		rb_w32_getpid()
120#define sleep(x)		rb_w32_sleep((x)*1000)
121#ifdef __BORLANDC__
122#define creat(p, m)		_creat(p, m)
123#define eof()			_eof()
124#define filelength(h)		_filelength(h)
125#define mktemp(t)		_mktemp(t)
126#define tell(h)			_tell(h)
127#define unlink(p)		_unlink(p)
128#define _open			_sopen
129#define sopen			_sopen
130#undef fopen
131#define fopen(p, m)		rb_w32_fopen(p, m)
132#undef fdopen
133#define fdopen(h, m)		rb_w32_fdopen(h, m)
134#undef fsopen
135#define fsopen(p, m, sh)	rb_w32_fsopen(p, m, sh)
136#endif
137#define fsync(h)		_commit(h)
138#undef stat
139#define stat(path,st)		rb_w32_stat(path,st)
140#undef execv
141#define execv(path,argv)	do_aspawn(P_OVERLAY,path,argv)
142#if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
143#undef isatty
144#define isatty(h)		rb_w32_isatty(h)
145#endif
146#undef mkdir
147#define mkdir(p, m)		rb_w32_mkdir(p, m)
148#undef rmdir
149#define rmdir(p)		rb_w32_rmdir(p)
150#undef unlink
151#define unlink(p)		rb_w32_unlink(p)
152
153struct timezone;
154
155#ifdef __MINGW32__
156#undef isascii
157#define isascii __isascii
158#endif
159extern void   NtInitialize(int *, char ***);
160extern int    rb_w32_cmdvector(const char *, char ***);
161extern rb_pid_t pipe_exec(const char *, int, FILE **, FILE **);
162extern int    flock(int fd, int oper);
163extern int    rb_w32_accept(int, struct sockaddr *, int *);
164extern int    rb_w32_bind(int, struct sockaddr *, int);
165extern int    rb_w32_connect(int, struct sockaddr *, int);
166extern void   rb_w32_fdset(int, fd_set*);
167extern void   rb_w32_fdclr(int, fd_set*);
168extern int    rb_w32_fdisset(int, fd_set*);
169extern long   rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
170extern int    rb_w32_getpeername(int, struct sockaddr *, int *);
171extern int    rb_w32_getsockname(int, struct sockaddr *, int *);
172extern int    rb_w32_getsockopt(int, int, int, char *, int *);
173extern int    rb_w32_ioctlsocket(int, long, u_long *);
174extern int    rb_w32_listen(int, int);
175extern int    rb_w32_recv(int, char *, int, int);
176extern int    rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
177extern int    rb_w32_send(int, const char *, int, int);
178extern int    rb_w32_sendto(int, const char *, int, int, struct sockaddr *, int);
179extern int    rb_w32_setsockopt(int, int, int, char *, int);
180extern int    rb_w32_shutdown(int, int);
181extern int    rb_w32_socket(int, int, int);
182extern SOCKET rb_w32_get_osfhandle(int);
183extern struct hostent * rb_w32_gethostbyaddr(char *, int, int);
184extern struct hostent * rb_w32_gethostbyname(char *);
185extern int    rb_w32_gethostname(char *, int);
186extern struct protoent * rb_w32_getprotobyname(char *);
187extern struct protoent * rb_w32_getprotobynumber(int);
188extern struct servent  * rb_w32_getservbyname(char *, char *);
189extern struct servent  * rb_w32_getservbyport(int, char *);
190extern char * rb_w32_getcwd(char *, int);
191extern char * rb_w32_getenv(const char *);
192extern int    rb_w32_rename(const char *, const char *);
193extern int    rb_w32_stat(const char *, struct stat *);
194extern char **rb_w32_get_environ(void);
195extern void   rb_w32_free_environ(char **);
196extern int    rb_w32_map_errno(DWORD);
197
198#define vsnprintf(s,n,f,l) rb_w32_vsnprintf(s,n,f,l)
199#define snprintf   rb_w32_snprintf
200extern int rb_w32_vsnprintf(char *, size_t, const char *, va_list);
201extern int rb_w32_snprintf(char *, size_t, const char *, ...);
202
203extern int chown(const char *, int, int);
204extern int link(char *, char *);
205extern int gettimeofday(struct timeval *, struct timezone *);
206extern rb_pid_t waitpid (rb_pid_t, int *, int);
207extern int do_spawn(int, const char *);
208extern int do_aspawn(int, const char *, char **);
209extern int kill(int, int);
210extern int fcntl(int, int, ...);
211extern rb_pid_t rb_w32_getpid(void);
212
213#if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
214extern int rb_w32_isatty(int);
215#endif
216extern int rb_w32_mkdir(const char *, int);
217extern int rb_w32_rmdir(const char *);
218extern int rb_w32_unlink(const char*);
219
220#ifdef __BORLANDC__
221extern FILE *rb_w32_fopen(const char *, const char *);
222extern FILE *rb_w32_fdopen(int, const char *);
223extern FILE *rb_w32_fsopen(const char *, const char *, int);
224#endif
225
226#include <float.h>
227#if !defined __MINGW32__ || defined __NO_ISOCEXT
228#ifndef isnan
229#define isnan(x) _isnan(x)
230#endif
231#ifndef finite
232#define finite(x) _finite(x)
233#endif
234#ifndef copysign
235#define copysign(a, b) _copysign(a, b)
236#endif
237#ifndef scalb
238#define scalb(a, b) _scalb(a, b)
239#endif
240#endif
241
242#if !defined S_IFIFO && defined _S_IFIFO
243#define S_IFIFO _S_IFIFO
244#endif
245
246#ifdef __BORLANDC__
247#undef S_ISDIR
248#undef S_ISFIFO
249#undef S_ISBLK
250#undef S_ISCHR
251#undef S_ISREG
252#define S_ISDIR(m)  (((unsigned short)(m) & S_IFMT) == S_IFDIR)
253#define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
254#define S_ISBLK(m)  (((unsigned short)(m) & S_IFMT) == S_IFBLK)
255#define S_ISCHR(m)  (((unsigned short)(m) & S_IFMT) == S_IFCHR)
256#define S_ISREG(m)  (((unsigned short)(m) & S_IFMT) == S_IFREG)
257#endif
258
259#if !defined S_IRUSR && !defined __MINGW32__
260#define S_IRUSR 0400
261#endif
262#ifndef S_IRGRP
263#define S_IRGRP 0040
264#endif
265#ifndef S_IROTH
266#define S_IROTH 0004
267#endif
268
269#if !defined S_IWUSR && !defined __MINGW32__
270#define S_IWUSR 0200
271#endif
272#ifndef S_IWGRP
273#define S_IWGRP 0020
274#endif
275#ifndef S_IWOTH
276#define S_IWOTH 0002
277#endif
278
279#if !defined S_IXUSR && !defined __MINGW32__
280#define S_IXUSR 0100
281#endif
282#ifndef S_IXGRP
283#define S_IXGRP 0010
284#endif
285#ifndef S_IXOTH
286#define S_IXOTH 0001
287#endif
288
289//
290// define this so we can do inplace editing
291//
292
293#define SUFFIX
294
295//
296// stubs
297//
298#if !defined(__BORLANDC__)
299extern int       ioctl (int, unsigned int, long);
300#endif
301extern rb_uid_t  getuid (void);
302extern rb_uid_t  geteuid (void);
303extern rb_gid_t  getgid (void);
304extern rb_gid_t  getegid (void);
305extern int       setuid (rb_uid_t);
306extern int       setgid (rb_gid_t);
307
308extern char *rb_w32_strerror(int);
309
310#define strerror(e) rb_w32_strerror(e)
311
312#define PIPE_BUF 1024
313
314#define LOCK_SH 1
315#define LOCK_EX 2
316#define LOCK_NB 4
317#define LOCK_UN 8
318
319
320#ifndef SIGINT
321#define SIGINT 2
322#endif
323#ifndef SIGKILL
324#define SIGKILL	9
325#endif
326
327
328/* #undef va_start */
329/* #undef va_end */
330
331/* winsock error map */
332#include <errno.h>
333
334#ifndef EWOULDBLOCK
335# define EWOULDBLOCK		WSAEWOULDBLOCK
336#endif
337#ifndef EINPROGRESS
338# define EINPROGRESS		WSAEINPROGRESS
339#endif
340#ifndef EALREADY
341# define EALREADY		WSAEALREADY
342#endif
343#ifndef ENOTSOCK
344# define ENOTSOCK		WSAENOTSOCK
345#endif
346#ifndef EDESTADDRREQ
347# define EDESTADDRREQ		WSAEDESTADDRREQ
348#endif
349#ifndef EMSGSIZE
350# define EMSGSIZE		WSAEMSGSIZE
351#endif
352#ifndef EPROTOTYPE
353# define EPROTOTYPE		WSAEPROTOTYPE
354#endif
355#ifndef ENOPROTOOPT
356# define ENOPROTOOPT		WSAENOPROTOOPT
357#endif
358#ifndef EPROTONOSUPPORT
359# define EPROTONOSUPPORT	WSAEPROTONOSUPPORT
360#endif
361#ifndef ESOCKTNOSUPPORT
362# define ESOCKTNOSUPPORT	WSAESOCKTNOSUPPORT
363#endif
364#ifndef EOPNOTSUPP
365# define EOPNOTSUPP		WSAEOPNOTSUPP
366#endif
367#ifndef EPFNOSUPPORT
368# define EPFNOSUPPORT		WSAEPFNOSUPPORT
369#endif
370#ifndef EAFNOSUPPORT
371# define EAFNOSUPPORT		WSAEAFNOSUPPORT
372#endif
373#ifndef EADDRINUSE
374# define EADDRINUSE		WSAEADDRINUSE
375#endif
376#ifndef EADDRNOTAVAIL
377# define EADDRNOTAVAIL		WSAEADDRNOTAVAIL
378#endif
379#ifndef ENETDOWN
380# define ENETDOWN		WSAENETDOWN
381#endif
382#ifndef ENETUNREACH
383# define ENETUNREACH		WSAENETUNREACH
384#endif
385#ifndef ENETRESET
386# define ENETRESET		WSAENETRESET
387#endif
388#ifndef ECONNABORTED
389# define ECONNABORTED		WSAECONNABORTED
390#endif
391#ifndef ECONNRESET
392# define ECONNRESET		WSAECONNRESET
393#endif
394#ifndef ENOBUFS
395# define ENOBUFS		WSAENOBUFS
396#endif
397#ifndef EISCONN
398# define EISCONN		WSAEISCONN
399#endif
400#ifndef ENOTCONN
401# define ENOTCONN		WSAENOTCONN
402#endif
403#ifndef ESHUTDOWN
404# define ESHUTDOWN		WSAESHUTDOWN
405#endif
406#ifndef ETOOMANYREFS
407# define ETOOMANYREFS		WSAETOOMANYREFS
408#endif
409#ifndef ETIMEDOUT
410# define ETIMEDOUT		WSAETIMEDOUT
411#endif
412#ifndef ECONNREFUSED
413# define ECONNREFUSED		WSAECONNREFUSED
414#endif
415#ifndef ELOOP
416# define ELOOP			WSAELOOP
417#endif
418/*#define ENAMETOOLONG	WSAENAMETOOLONG*/
419#ifndef EHOSTDOWN
420# define EHOSTDOWN		WSAEHOSTDOWN
421#endif
422#ifndef EHOSTUNREACH
423# define EHOSTUNREACH		WSAEHOSTUNREACH
424#endif
425/*#define ENOTEMPTY	WSAENOTEMPTY*/
426#ifndef EPROCLIM
427# define EPROCLIM		WSAEPROCLIM
428#endif
429#ifndef EUSERS
430# define EUSERS			WSAEUSERS
431#endif
432#ifndef EDQUOT
433# define EDQUOT			WSAEDQUOT
434#endif
435#ifndef ESTALE
436# define ESTALE			WSAESTALE
437#endif
438#ifndef EREMOTE
439# define EREMOTE		WSAEREMOTE
440#endif
441
442#define F_SETFL 1
443#define O_NONBLOCK 1
444
445#ifdef accept
446#undef accept
447#endif
448#define accept(s, a, l)		rb_w32_accept(s, a, l)
449
450#ifdef bind
451#undef bind
452#endif
453#define bind(s, a, l)		rb_w32_bind(s, a, l)
454
455#ifdef connect
456#undef connect
457#endif
458#define connect(s, a, l)	rb_w32_connect(s, a, l)
459
460#undef FD_SET
461#define FD_SET(f, s)		rb_w32_fdset(f, s)
462
463#undef FD_CLR
464#define FD_CLR(f, s)		rb_w32_fdclr(f, s)
465
466#undef FD_ISSET
467#define FD_ISSET(f, s)		rb_w32_fdisset(f, s)
468
469#undef select
470#define select(n, r, w, e, t)	rb_w32_select(n, r, w, e, t)
471
472#ifdef getpeername
473#undef getpeername
474#endif
475#define getpeername(s, a, l)	rb_w32_getpeername(s, a, l)
476
477#ifdef getsockname
478#undef getsockname
479#endif
480#define getsockname(s, a, l)	rb_w32_getsockname(s, a, l)
481
482#ifdef getsockopt
483#undef getsockopt
484#endif
485#define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
486
487#ifdef ioctlsocket
488#undef ioctlsocket
489#endif
490#define ioctlsocket(s, c, a)	rb_w32_ioctlsocket(s, c, a)
491
492#ifdef listen
493#undef listen
494#endif
495#define listen(s, b)		rb_w32_listen(s, b)
496
497#ifdef recv
498#undef recv
499#endif
500#define recv(s, b, l, f)	rb_w32_recv(s, b, l, f)
501
502#ifdef recvfrom
503#undef recvfrom
504#endif
505#define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
506
507#ifdef send
508#undef send
509#endif
510#define send(s, b, l, f)	rb_w32_send(s, b, l, f)
511
512#ifdef sendto
513#undef sendto
514#endif
515#define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
516
517#ifdef setsockopt
518#undef setsockopt
519#endif
520#define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
521
522#ifdef shutdown
523#undef shutdown
524#endif
525#define shutdown(s, h)		rb_w32_shutdown(s, h)
526
527#ifdef socket
528#undef socket
529#endif
530#define socket(s, t, p)		rb_w32_socket(s, t, p)
531
532#ifdef gethostbyaddr
533#undef gethostbyaddr
534#endif
535#define gethostbyaddr(a, l, t)	rb_w32_gethostbyaddr(a, l, t)
536
537#ifdef gethostbyname
538#undef gethostbyname
539#endif
540#define gethostbyname(n)	rb_w32_gethostbyname(n)
541
542#ifdef gethostname
543#undef gethostname
544#endif
545#define gethostname(n, l)	rb_w32_gethostname(n, l)
546
547#ifdef getprotobyname
548#undef getprotobyname
549#endif
550#define getprotobyname(n)	rb_w32_getprotobyname(n)
551
552#ifdef getprotobynumber
553#undef getprotobynumber
554#endif
555#define getprotobynumber(n)	rb_w32_getprotobynumber(n)
556
557#ifdef getservbyname
558#undef getservbyname
559#endif
560#define getservbyname(n, p)	rb_w32_getservbyname(n, p)
561
562#ifdef getservbyport
563#undef getservbyport
564#endif
565#define getservbyport(p, pr)	rb_w32_getservbyport(p, pr)
566
567#ifdef get_osfhandle
568#undef get_osfhandle
569#endif
570#define get_osfhandle(h)	rb_w32_get_osfhandle(h)
571
572#ifdef getcwd
573#undef getcwd
574#endif
575#define getcwd(b, s)		rb_w32_getcwd(b, s)
576
577#ifdef getenv
578#undef getenv
579#endif
580#define getenv(n)		rb_w32_getenv(n)
581
582#ifdef rename
583#undef rename
584#endif
585#define rename(o, n)		rb_w32_rename(o, n)
586
587struct tms {
588	long	tms_utime;
589	long	tms_stime;
590	long	tms_cutime;
591	long	tms_cstime;
592};
593
594#ifdef times
595#undef times
596#endif
597#define times(t) rb_w32_times(t)
598int rb_w32_times(struct tms *);
599
600/* thread stuff */
601HANDLE GetCurrentThreadHandle(void);
602void rb_w32_interrupted(void);
603int  rb_w32_main_context(int arg, void (*handler)(int));
604int  rb_w32_sleep(unsigned long msec);
605void rb_w32_enter_critical(void);
606void rb_w32_leave_critical(void);
607int  rb_w32_putc(int, FILE*);
608int  rb_w32_getc(FILE*);
609int  rb_w32_close(int);
610int  rb_w32_fclose(FILE*);
611size_t rb_w32_read(int, void *, size_t);
612size_t rb_w32_write(int, const void *, size_t);
613int  rb_w32_utime(const char *, struct utimbuf *);
614#define Sleep(msec) (void)rb_w32_sleep(msec)
615
616/*
617== ***CAUTION***
618Since this function is very dangerous, ((*NEVER*))
619* lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
620* use anything like TRAP_BEG...TRAP_END block structure,
621in asynchronous_func_t.
622*/
623typedef DWORD (*asynchronous_func_t)(DWORD self, int argc, DWORD* argv);
624DWORD rb_w32_asynchronize(asynchronous_func_t func, DWORD self, int argc, DWORD* argv, DWORD intrval);
625
626#endif