2 * Misc. functions for systems that don't have them
4 * Copyright 1996 Alexandre Julliard
10 #include <be/kernel/fs_info.h>
11 #include <be/kernel/OS.h>
19 #include <sys/types.h>
22 #include <sys/ioctl.h>
36 #include "wine/port.h"
38 /***********************************************************************
42 unsigned int usleep (unsigned int useconds)
47 #elif defined(__BEOS__)
48 return snooze(useconds);
49 #elif defined(HAVE_SELECT)
53 delay.tv_usec = useconds;
55 select( 0, 0, 0, 0, &delay );
57 #else /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
60 #endif /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
62 #endif /* HAVE_USLEEP */
64 /***********************************************************************
68 void *memmove( void *dest, const void *src, unsigned int len )
70 register char *dst = dest;
72 /* Use memcpy if not overlapping */
73 if ((dst + len <= (char *)src) || ((char *)src + len <= dst))
75 memcpy( dst, src, len );
77 /* Otherwise do it the hard way (FIXME: could do better than this) */
80 while (len--) *dst++ = *((char *)src)++;
85 src = (char *)src + len - 1;
86 while (len--) *dst-- = *((char *)src)--;
90 #endif /* HAVE_MEMMOVE */
92 /***********************************************************************
96 const char *strerror( int err )
98 /* Let's hope we have sys_errlist then */
99 return sys_errlist[err];
101 #endif /* HAVE_STRERROR */
103 /***********************************************************************
106 #if !defined(HAVE_CLONE) && defined(__linux__)
107 int clone( int (*fn)(void *), void *stack, int flags, void *arg )
111 void **stack_ptr = (void **)stack;
112 *--stack_ptr = arg; /* Push argument on stack */
113 *--stack_ptr = fn; /* Push function pointer (popped into ebx) */
114 __asm__ __volatile__( "pushl %%ebx\n\t"
117 "popl %%ebx\n\t" /* Contains fn in the child */
118 "testl %%eax,%%eax\n\t"
120 "call *%%ebx\n\t" /* Should never return */
121 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
124 : "0" (SYS_clone), "r" (flags), "c" (stack_ptr) );
125 assert( ret ); /* If ret is 0, we returned from the child function */
126 if (ret > 0) return ret;
132 #endif /* __i386__ */
134 #endif /* !HAVE_CLONE && __linux__ */
136 /***********************************************************************
139 #ifndef HAVE_STRCASECMP
140 int strcasecmp( const char *str1, const char *str2 )
142 while (*str1 && toupper(*str1) == toupper(*str2)) { str1++; str2++; }
143 return toupper(*str1) - toupper(*str2);
145 #endif /* HAVE_STRCASECMP */
147 /***********************************************************************
150 #ifndef HAVE_STRNCASECMP
151 int strncasecmp( const char *str1, const char *str2, size_t n )
155 while ((--n > 0) && *str1)
156 if ((res = toupper(*str1++) - toupper(*str2++))) return res;
157 return toupper(*str1) - toupper(*str2);
159 #endif /* HAVE_STRNCASECMP */
161 /***********************************************************************
164 * It looks like the openpty that comes with glibc in RedHat 5.0
165 * is buggy (second call returns what looks like a dup of 0 and 1
166 * instead of a new pty), this is a generic replacement.
169 * We should have a autoconf check for this.
171 int wine_openpty(int *master, int *slave, char *name,
172 struct termios *term, struct winsize *winsize)
175 return openpty(master,slave,name,term,winsize);
180 strcpy (pts_name, "/dev/ptyXY");
182 for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
184 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
187 if ((*master = open(pts_name, O_RDWR)) < 0) {
194 if ((*slave = open(pts_name, O_RDWR)) < 0) {
200 tcsetattr(*slave, TCSANOW, term);
202 ioctl(*slave, TIOCSWINSZ, winsize);
204 strcpy(name, pts_name);
212 /***********************************************************************
215 #ifndef HAVE_GETNETBYADDR
216 struct netent *getnetbyaddr(unsigned long net, int type)
221 #endif /* defined(HAVE_GETNETBYNAME) */
223 /***********************************************************************
226 #ifndef HAVE_GETNETBYNAME
227 struct netent *getnetbyname(const char *name)
232 #endif /* defined(HAVE_GETNETBYNAME) */
234 /***********************************************************************
237 #ifndef HAVE_GETPROTOBYNAME
238 struct protoent *getprotobyname(const char *name)
243 #endif /* !defined(HAVE_GETPROTOBYNAME) */
245 /***********************************************************************
248 #ifndef HAVE_GETPROTOBYNUMBER
249 struct protoent *getprotobynumber(int proto)
254 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
256 /***********************************************************************
259 #ifndef HAVE_GETSERVBYPORT
260 struct servent *getservbyport(int port, const char *proto)
265 #endif /* !defined(HAVE_GETSERVBYPORT) */
267 /***********************************************************************
270 #ifndef HAVE_GETSOCKOPT
271 int getsockopt(int socket, int level, int option_name,
272 void *option_value, size_t *option_len)
277 #endif /* !defined(HAVE_GETSOCKOPT) */
279 /***********************************************************************
282 #ifndef HAVE_INET_NETWORK
283 unsigned long inet_network(const char *cp)
288 #endif /* defined(HAVE_INET_NETWORK) */
290 /***********************************************************************
293 #ifndef HAVE_SETTIMEOFDAY
294 int settimeofday(struct timeval *tp, void *reserved)
302 #endif /* HAVE_SETTIMEOFDAY */
304 /***********************************************************************
308 int statfs(const char *name, struct statfs *info)
319 if ((mydev = dev_for_path(name)) < 0) {
324 if (fs_stat_dev(mydev,&fsinfo) < 0) {
329 info->f_bsize = fsinfo.block_size;
330 info->f_blocks = fsinfo.total_blocks;
331 info->f_bfree = fsinfo.free_blocks;
334 #else /* defined(__BEOS__) */
337 #endif /* defined(__BEOS__) */
339 #endif /* !defined(HAVE_STATFS) */