2 * Misc. functions for systems that don't have them
4 * Copyright 1996 Alexandre Julliard
11 #include <sys/ioctl.h>
19 unsigned int usleep (unsigned int useconds
) { DosSleep(useconds
); }
21 unsigned int usleep (unsigned int useconds
)
26 delay
.tv_usec
= useconds
;
28 select( 0, 0, 0, 0, &delay
);
32 #endif /* HAVE_USLEEP */
35 void *memmove( void *dest
, const void *src
, unsigned int len
)
37 register char *dst
= dest
;
39 /* Use memcpy if not overlapping */
40 if ((dst
+ len
<= (char *)src
) || ((char *)src
+ len
<= dst
))
42 memcpy( dst
, src
, len
);
44 /* Otherwise do it the hard way (FIXME: could do better than this) */
47 while (len
--) *dst
++ = *((char *)src
)++;
52 src
= (char *)src
+ len
- 1;
53 while (len
--) *dst
-- = *((char *)src
)--;
57 #endif /* HAVE_MEMMOVE */
60 const char *strerror( int err
)
62 /* Let's hope we have sys_errlist then */
63 return sys_errlist
[err
];
65 #endif /* HAVE_STRERROR */
67 #if !defined(HAVE_CLONE) && defined(__linux__)
71 int clone( int (*fn
)(void *), void *stack
, int flags
, void *arg
)
75 void **stack_ptr
= (void **)stack
;
76 *--stack_ptr
= arg
; /* Push argument on stack */
77 *--stack_ptr
= fn
; /* Push function pointer (popped into ebx) */
78 __asm__
__volatile__( "pushl %%ebx\n\t"
81 "popl %%ebx\n\t" /* Contains fn in the child */
82 "testl %%eax,%%eax\n\t"
84 "call *%%ebx\n\t" /* Should never return */
85 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
88 : "0" (SYS_clone
), "g" (flags
), "c" (stack_ptr
) );
89 assert( ret
); /* If ret is 0, we returned from the child function */
90 if (ret
> 0) return ret
;
98 #endif /* !HAVE_CLONE && __linux__ */
102 * It looks like the openpty that comes with glibc in RedHat 5.0
103 * is buggy (second call returns what looks like a dup of 0 and 1
104 * instead of a new pty), this is a generic replacement.
106 /** We will have an autoconf check for this soon... */
108 int wine_openpty(int *master
, int *slave
, char *name
,
109 struct termios
*term
, struct winsize
*winsize
)
114 strcpy (pts_name
, "/dev/ptyXY");
116 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
118 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
121 if ((*master
= open(pts_name
, O_RDWR
)) < 0) {
128 if ((*slave
= open(pts_name
, O_RDWR
)) < 0) {
134 tcsetattr(*slave
, TCSANOW
, term
);
136 ioctl(*slave
, TIOCSWINSZ
, winsize
);
138 strcpy(name
, pts_name
);