2 * Misc. functions for systems that don't have them
4 * Copyright 1996 Alexandre Julliard
12 #include <sys/ioctl.h>
22 unsigned int usleep (unsigned int useconds
) { DosSleep(useconds
); }
24 unsigned int usleep (unsigned int useconds
)
29 delay
.tv_usec
= useconds
;
31 select( 0, 0, 0, 0, &delay
);
35 #endif /* HAVE_USLEEP */
38 void *memmove( void *dest
, const void *src
, unsigned int len
)
40 register char *dst
= dest
;
42 /* Use memcpy if not overlapping */
43 if ((dst
+ len
<= (char *)src
) || ((char *)src
+ len
<= dst
))
45 memcpy( dst
, src
, len
);
47 /* Otherwise do it the hard way (FIXME: could do better than this) */
50 while (len
--) *dst
++ = *((char *)src
)++;
55 src
= (char *)src
+ len
- 1;
56 while (len
--) *dst
-- = *((char *)src
)--;
60 #endif /* HAVE_MEMMOVE */
63 const char *strerror( int err
)
65 /* Let's hope we have sys_errlist then */
66 return sys_errlist
[err
];
68 #endif /* HAVE_STRERROR */
70 #if !defined(HAVE_CLONE) && defined(__linux__)
74 int clone( int (*fn
)(void *), void *stack
, int flags
, void *arg
)
78 void **stack_ptr
= (void **)stack
;
79 *--stack_ptr
= arg
; /* Push argument on stack */
80 *--stack_ptr
= fn
; /* Push function pointer (popped into ebx) */
81 __asm__
__volatile__( "pushl %%ebx\n\t"
84 "popl %%ebx\n\t" /* Contains fn in the child */
85 "testl %%eax,%%eax\n\t"
87 "call *%%ebx\n\t" /* Should never return */
88 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
91 : "0" (SYS_clone
), "r" (flags
), "c" (stack_ptr
) );
92 assert( ret
); /* If ret is 0, we returned from the child function */
93 if (ret
> 0) return ret
;
101 #endif /* !HAVE_CLONE && __linux__ */
105 * It looks like the openpty that comes with glibc in RedHat 5.0
106 * is buggy (second call returns what looks like a dup of 0 and 1
107 * instead of a new pty), this is a generic replacement.
109 /** We will have an autoconf check for this soon... */
111 int wine_openpty(int *master
, int *slave
, char *name
,
112 struct termios
*term
, struct winsize
*winsize
)
117 strcpy (pts_name
, "/dev/ptyXY");
119 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
121 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
124 if ((*master
= open(pts_name
, O_RDWR
)) < 0) {
131 if ((*slave
= open(pts_name
, O_RDWR
)) < 0) {
137 tcsetattr(*slave
, TCSANOW
, term
);
139 ioctl(*slave
, TIOCSWINSZ
, winsize
);
141 strcpy(name
, pts_name
);