2 * Misc. functions for systems that don't have them
4 * Copyright 1996 Alexandre Julliard
12 #include <sys/types.h>
15 #include <sys/ioctl.h>
25 unsigned int usleep (unsigned int useconds
) { DosSleep(useconds
); }
27 unsigned int usleep (unsigned int useconds
)
32 delay
.tv_usec
= useconds
;
34 select( 0, 0, 0, 0, &delay
);
38 #endif /* HAVE_USLEEP */
41 void *memmove( void *dest
, const void *src
, unsigned int len
)
43 register char *dst
= dest
;
45 /* Use memcpy if not overlapping */
46 if ((dst
+ len
<= (char *)src
) || ((char *)src
+ len
<= dst
))
48 memcpy( dst
, src
, len
);
50 /* Otherwise do it the hard way (FIXME: could do better than this) */
53 while (len
--) *dst
++ = *((char *)src
)++;
58 src
= (char *)src
+ len
- 1;
59 while (len
--) *dst
-- = *((char *)src
)--;
63 #endif /* HAVE_MEMMOVE */
66 const char *strerror( int err
)
68 /* Let's hope we have sys_errlist then */
69 return sys_errlist
[err
];
71 #endif /* HAVE_STRERROR */
73 #if !defined(HAVE_CLONE) && defined(__linux__)
77 int clone( int (*fn
)(void *), void *stack
, int flags
, void *arg
)
81 void **stack_ptr
= (void **)stack
;
82 *--stack_ptr
= arg
; /* Push argument on stack */
83 *--stack_ptr
= fn
; /* Push function pointer (popped into ebx) */
84 __asm__
__volatile__( "pushl %%ebx\n\t"
87 "popl %%ebx\n\t" /* Contains fn in the child */
88 "testl %%eax,%%eax\n\t"
90 "call *%%ebx\n\t" /* Should never return */
91 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
94 : "0" (SYS_clone
), "r" (flags
), "c" (stack_ptr
) );
95 assert( ret
); /* If ret is 0, we returned from the child function */
96 if (ret
> 0) return ret
;
102 #endif /* __i386__ */
104 #endif /* !HAVE_CLONE && __linux__ */
108 * It looks like the openpty that comes with glibc in RedHat 5.0
109 * is buggy (second call returns what looks like a dup of 0 and 1
110 * instead of a new pty), this is a generic replacement.
112 /** We will have an autoconf check for this soon... */
114 int wine_openpty(int *master
, int *slave
, char *name
,
115 struct termios
*term
, struct winsize
*winsize
)
120 strcpy (pts_name
, "/dev/ptyXY");
122 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
124 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
127 if ((*master
= open(pts_name
, O_RDWR
)) < 0) {
134 if ((*slave
= open(pts_name
, O_RDWR
)) < 0) {
140 tcsetattr(*slave
, TCSANOW
, term
);
142 ioctl(*slave
, TIOCSWINSZ
, winsize
);
144 strcpy(name
, pts_name
);