2 * Misc. functions for systems that don't have them
4 * Copyright 1996 Alexandre Julliard
10 #include <sys/types.h>
13 #include <sys/ioctl.h>
23 unsigned int usleep (unsigned int useconds) { DosSleep(useconds); }
25 unsigned int usleep (unsigned int useconds)
30 delay.tv_usec = useconds;
32 select( 0, 0, 0, 0, &delay );
36 #endif /* HAVE_USLEEP */
39 void *memmove( void *dest, const void *src, unsigned int len )
41 register char *dst = dest;
43 /* Use memcpy if not overlapping */
44 if ((dst + len <= (char *)src) || ((char *)src + len <= dst))
46 memcpy( dst, src, len );
48 /* Otherwise do it the hard way (FIXME: could do better than this) */
51 while (len--) *dst++ = *((char *)src)++;
56 src = (char *)src + len - 1;
57 while (len--) *dst-- = *((char *)src)--;
61 #endif /* HAVE_MEMMOVE */
64 const char *strerror( int err )
66 /* Let's hope we have sys_errlist then */
67 return sys_errlist[err];
69 #endif /* HAVE_STRERROR */
71 #if !defined(HAVE_CLONE) && defined(__linux__)
75 int clone( int (*fn)(void *), void *stack, int flags, void *arg )
79 void **stack_ptr = (void **)stack;
80 *--stack_ptr = arg; /* Push argument on stack */
81 *--stack_ptr = fn; /* Push function pointer (popped into ebx) */
82 __asm__ __volatile__( "pushl %%ebx\n\t"
85 "popl %%ebx\n\t" /* Contains fn in the child */
86 "testl %%eax,%%eax\n\t"
88 "call *%%ebx\n\t" /* Should never return */
89 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
92 : "0" (SYS_clone), "r" (flags), "c" (stack_ptr) );
93 assert( ret ); /* If ret is 0, we returned from the child function */
94 if (ret > 0) return ret;
100 #endif /* __i386__ */
102 #endif /* !HAVE_CLONE && __linux__ */
106 * It looks like the openpty that comes with glibc in RedHat 5.0
107 * is buggy (second call returns what looks like a dup of 0 and 1
108 * instead of a new pty), this is a generic replacement.
110 /** We will have an autoconf check for this soon... */
112 int wine_openpty(int *master, int *slave, char *name,
113 struct termios *term, struct winsize *winsize)
118 strcpy (pts_name, "/dev/ptyXY");
120 for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
122 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
125 if ((*master = open(pts_name, O_RDWR)) < 0) {
132 if ((*slave = open(pts_name, O_RDWR)) < 0) {
138 tcsetattr(*slave, TCSANOW, term);
140 ioctl(*slave, TIOCSWINSZ, winsize);
142 strcpy(name, pts_name);