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>
26 #ifdef HAVE_SYS_MMAN_H
42 #include "wine/port.h"
44 /***********************************************************************
48 unsigned int usleep (unsigned int useconds)
53 #elif defined(__BEOS__)
54 return snooze(useconds);
55 #elif defined(HAVE_SELECT)
58 delay.tv_sec = useconds / 1000000;
59 delay.tv_usec = useconds % 1000000;
61 select( 0, 0, 0, 0, &delay );
63 #else /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
66 #endif /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
68 #endif /* HAVE_USLEEP */
70 /***********************************************************************
74 void *memmove( void *dest, const void *src, unsigned int len )
76 register char *dst = dest;
78 /* Use memcpy if not overlapping */
79 if ((dst + len <= (char *)src) || ((char *)src + len <= dst))
81 memcpy( dst, src, len );
83 /* Otherwise do it the hard way (FIXME: could do better than this) */
86 while (len--) *dst++ = *((char *)src)++;
91 src = (char *)src + len - 1;
92 while (len--) *dst-- = *((char *)src)--;
96 #endif /* HAVE_MEMMOVE */
98 /***********************************************************************
101 #ifndef HAVE_STRERROR
102 const char *strerror( int err )
104 /* Let's hope we have sys_errlist then */
105 return sys_errlist[err];
107 #endif /* HAVE_STRERROR */
110 /***********************************************************************
113 #ifndef HAVE_GETPAGESIZE
114 size_t getpagesize(void)
117 return sysconf(_SC_PAGESIZE);
119 # error Cannot get the page size on this platform
122 #endif /* HAVE_GETPAGESIZE */
125 /***********************************************************************
128 #if !defined(HAVE_CLONE) && defined(__linux__)
129 int clone( int (*fn)(void *), void *stack, int flags, void *arg )
133 void **stack_ptr = (void **)stack;
134 *--stack_ptr = arg; /* Push argument on stack */
135 *--stack_ptr = fn; /* Push function pointer (popped into ebx) */
136 __asm__ __volatile__( "pushl %%ebx\n\t"
139 "popl %%ebx\n\t" /* Contains fn in the child */
140 "testl %%eax,%%eax\n\t"
142 "call *%%ebx\n\t" /* Should never return */
143 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
146 : "0" (SYS_clone), "r" (flags), "c" (stack_ptr) );
147 assert( ret ); /* If ret is 0, we returned from the child function */
148 if (ret > 0) return ret;
154 #endif /* __i386__ */
156 #endif /* !HAVE_CLONE && __linux__ */
158 /***********************************************************************
161 #ifndef HAVE_STRCASECMP
162 int strcasecmp( const char *str1, const char *str2 )
164 while (*str1 && toupper(*str1) == toupper(*str2)) { str1++; str2++; }
165 return toupper(*str1) - toupper(*str2);
167 #endif /* HAVE_STRCASECMP */
169 /***********************************************************************
172 #ifndef HAVE_STRNCASECMP
173 int strncasecmp( const char *str1, const char *str2, size_t n )
177 while ((--n > 0) && *str1)
178 if ((res = toupper(*str1++) - toupper(*str2++))) return res;
179 return toupper(*str1) - toupper(*str2);
181 #endif /* HAVE_STRNCASECMP */
183 /***********************************************************************
186 * It looks like the openpty that comes with glibc in RedHat 5.0
187 * is buggy (second call returns what looks like a dup of 0 and 1
188 * instead of a new pty), this is a generic replacement.
191 * We should have a autoconf check for this.
193 int wine_openpty(int *master, int *slave, char *name,
194 struct termios *term, struct winsize *winsize)
197 return openpty(master,slave,name,term,winsize);
202 strcpy (pts_name, "/dev/ptyXY");
204 for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
206 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
209 if ((*master = open(pts_name, O_RDWR)) < 0) {
216 if ((*slave = open(pts_name, O_RDWR)) < 0) {
222 tcsetattr(*slave, TCSANOW, term);
224 ioctl(*slave, TIOCSWINSZ, winsize);
226 strcpy(name, pts_name);
234 /***********************************************************************
237 #ifndef HAVE_GETNETBYADDR
238 struct netent *getnetbyaddr(unsigned long net, int type)
243 #endif /* defined(HAVE_GETNETBYNAME) */
245 /***********************************************************************
248 #ifndef HAVE_GETNETBYNAME
249 struct netent *getnetbyname(const char *name)
254 #endif /* defined(HAVE_GETNETBYNAME) */
256 /***********************************************************************
259 #ifndef HAVE_GETPROTOBYNAME
260 struct protoent *getprotobyname(const char *name)
265 #endif /* !defined(HAVE_GETPROTOBYNAME) */
267 /***********************************************************************
270 #ifndef HAVE_GETPROTOBYNUMBER
271 struct protoent *getprotobynumber(int proto)
276 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
278 /***********************************************************************
281 #ifndef HAVE_GETSERVBYPORT
282 struct servent *getservbyport(int port, const char *proto)
287 #endif /* !defined(HAVE_GETSERVBYPORT) */
289 /***********************************************************************
292 #ifndef HAVE_GETSOCKOPT
293 int getsockopt(int socket, int level, int option_name,
294 void *option_value, size_t *option_len)
299 #endif /* !defined(HAVE_GETSOCKOPT) */
301 /***********************************************************************
304 #ifndef HAVE_INET_NETWORK
305 unsigned long inet_network(const char *cp)
310 #endif /* defined(HAVE_INET_NETWORK) */
312 /***********************************************************************
315 #ifndef HAVE_SETTIMEOFDAY
316 int settimeofday(struct timeval *tp, void *reserved)
324 #endif /* HAVE_SETTIMEOFDAY */
326 /***********************************************************************
330 int statfs(const char *name, struct statfs *info)
341 if ((mydev = dev_for_path(name)) < 0) {
346 if (fs_stat_dev(mydev,&fsinfo) < 0) {
351 info->f_bsize = fsinfo.block_size;
352 info->f_blocks = fsinfo.total_blocks;
353 info->f_bfree = fsinfo.free_blocks;
355 #else /* defined(__BEOS__) */
358 #endif /* defined(__BEOS__) */
360 #endif /* !defined(HAVE_STATFS) */
363 /***********************************************************************
367 int lstat(const char *file_name, struct stat *buf)
369 return stat( file_name, buf );
371 #endif /* HAVE_LSTAT */
374 /***********************************************************************
377 * Portable wrapper for anonymous mmaps
379 void *wine_anon_mmap( void *start, size_t size, int prot, int flags )
381 static int fdzero = -1;
388 if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
390 perror( "/dev/zero: open" );
394 #endif /* MAP_ANON */
395 /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
397 flags &= ~MAP_SHARED;
400 flags |= MAP_PRIVATE;
402 return mmap( start, size, prot, flags, fdzero, 0 );