2 * Misc. functions for systems that don't have them
4 * Copyright 1996 Alexandre Julliard
13 #include <sys/types.h>
16 #include <sys/ioctl.h>
26 unsigned int usleep (unsigned int useconds) { DosSleep(useconds); }
28 unsigned int usleep (unsigned int useconds)
33 delay.tv_usec = useconds;
35 select( 0, 0, 0, 0, &delay );
39 #endif /* HAVE_USLEEP */
42 void *memmove( void *dest, const void *src, unsigned int len )
44 register char *dst = dest;
46 /* Use memcpy if not overlapping */
47 if ((dst + len <= (char *)src) || ((char *)src + len <= dst))
49 memcpy( dst, src, len );
51 /* Otherwise do it the hard way (FIXME: could do better than this) */
54 while (len--) *dst++ = *((char *)src)++;
59 src = (char *)src + len - 1;
60 while (len--) *dst-- = *((char *)src)--;
64 #endif /* HAVE_MEMMOVE */
67 const char *strerror( int err )
69 /* Let's hope we have sys_errlist then */
70 return sys_errlist[err];
72 #endif /* HAVE_STRERROR */
74 #if !defined(HAVE_CLONE) && defined(__linux__)
78 int clone( int (*fn)(void *), void *stack, int flags, void *arg )
82 void **stack_ptr = (void **)stack;
83 *--stack_ptr = arg; /* Push argument on stack */
84 *--stack_ptr = fn; /* Push function pointer (popped into ebx) */
85 __asm__ __volatile__( "pushl %%ebx\n\t"
88 "popl %%ebx\n\t" /* Contains fn in the child */
89 "testl %%eax,%%eax\n\t"
91 "call *%%ebx\n\t" /* Should never return */
92 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
95 : "0" (SYS_clone), "r" (flags), "c" (stack_ptr) );
96 assert( ret ); /* If ret is 0, we returned from the child function */
97 if (ret > 0) return ret;
103 #endif /* __i386__ */
105 #endif /* !HAVE_CLONE && __linux__ */
108 #ifndef HAVE_STRCASECMP
109 int strcasecmp( const char *str1, const char *str2 )
111 while (*str1 && toupper(*str1) == toupper(*str2)) { str1++; str2++; }
112 return toupper(*str1) - toupper(*str2);
114 #endif /* HAVE_STRCASECMP */
116 #ifndef HAVE_STRNCASECMP
117 int strncasecmp( const char *str1, const char *str2, size_t n )
121 while ((--n > 0) && *str1)
122 if ((res = toupper(*str1++) - toupper(*str2++))) return res;
123 return toupper(*str1) - toupper(*str2);
125 #endif /* HAVE_STRNCASECMP */
128 * It looks like the openpty that comes with glibc in RedHat 5.0
129 * is buggy (second call returns what looks like a dup of 0 and 1
130 * instead of a new pty), this is a generic replacement.
132 /** We will have an autoconf check for this soon... */
134 int wine_openpty(int *master, int *slave, char *name,
135 struct termios *term, struct winsize *winsize)
140 strcpy (pts_name, "/dev/ptyXY");
142 for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
144 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
147 if ((*master = open(pts_name, O_RDWR)) < 0) {
154 if ((*slave = open(pts_name, O_RDWR)) < 0) {
160 tcsetattr(*slave, TCSANOW, term);
162 ioctl(*slave, TIOCSWINSZ, winsize);
164 strcpy(name, pts_name);