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 /***********************************************************************
40 unsigned int usleep (unsigned int useconds)
45 #elif defined(__BEOS__)
46 return snooze(useconds);
47 #elif defined(HAVE_SELECT)
51 delay.tv_usec = useconds;
53 select( 0, 0, 0, 0, &delay );
55 #else /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
58 #endif /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
60 #endif /* HAVE_USLEEP */
62 /***********************************************************************
66 void *memmove( void *dest, const void *src, unsigned int len )
68 register char *dst = dest;
70 /* Use memcpy if not overlapping */
71 if ((dst + len <= (char *)src) || ((char *)src + len <= dst))
73 memcpy( dst, src, len );
75 /* Otherwise do it the hard way (FIXME: could do better than this) */
78 while (len--) *dst++ = *((char *)src)++;
83 src = (char *)src + len - 1;
84 while (len--) *dst-- = *((char *)src)--;
88 #endif /* HAVE_MEMMOVE */
90 /***********************************************************************
94 const char *strerror( int err )
96 /* Let's hope we have sys_errlist then */
97 return sys_errlist[err];
99 #endif /* HAVE_STRERROR */
101 /***********************************************************************
104 #if !defined(HAVE_CLONE) && defined(__linux__)
105 int clone( int (*fn)(void *), void *stack, int flags, void *arg )
109 void **stack_ptr = (void **)stack;
110 *--stack_ptr = arg; /* Push argument on stack */
111 *--stack_ptr = fn; /* Push function pointer (popped into ebx) */
112 __asm__ __volatile__( "pushl %%ebx\n\t"
115 "popl %%ebx\n\t" /* Contains fn in the child */
116 "testl %%eax,%%eax\n\t"
118 "call *%%ebx\n\t" /* Should never return */
119 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
122 : "0" (SYS_clone), "r" (flags), "c" (stack_ptr) );
123 assert( ret ); /* If ret is 0, we returned from the child function */
124 if (ret > 0) return ret;
130 #endif /* __i386__ */
132 #endif /* !HAVE_CLONE && __linux__ */
134 /***********************************************************************
137 #ifndef HAVE_STRCASECMP
138 int strcasecmp( const char *str1, const char *str2 )
140 while (*str1 && toupper(*str1) == toupper(*str2)) { str1++; str2++; }
141 return toupper(*str1) - toupper(*str2);
143 #endif /* HAVE_STRCASECMP */
145 /***********************************************************************
148 #ifndef HAVE_STRNCASECMP
149 int strncasecmp( const char *str1, const char *str2, size_t n )
153 while ((--n > 0) && *str1)
154 if ((res = toupper(*str1++) - toupper(*str2++))) return res;
155 return toupper(*str1) - toupper(*str2);
157 #endif /* HAVE_STRNCASECMP */
159 /***********************************************************************
162 * It looks like the openpty that comes with glibc in RedHat 5.0
163 * is buggy (second call returns what looks like a dup of 0 and 1
164 * instead of a new pty), this is a generic replacement.
167 * We should have a autoconf check for this.
169 int wine_openpty(int *master, int *slave, char *name,
170 struct termios *term, struct winsize *winsize)
173 return openpty(master,slave,name,term,winsize);
178 strcpy (pts_name, "/dev/ptyXY");
180 for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
182 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
185 if ((*master = open(pts_name, O_RDWR)) < 0) {
192 if ((*slave = open(pts_name, O_RDWR)) < 0) {
198 tcsetattr(*slave, TCSANOW, term);
200 ioctl(*slave, TIOCSWINSZ, winsize);
202 strcpy(name, pts_name);
210 /***********************************************************************
213 #ifndef HAVE_GETNETBYADDR
214 struct netent *getnetbyaddr(unsigned long net, int type)
219 #endif /* defined(HAVE_GETNETBYNAME) */
221 /***********************************************************************
224 #ifndef HAVE_GETNETBYNAME
225 struct netent *getnetbyname(const char *name)
230 #endif /* defined(HAVE_GETNETBYNAME) */
232 /***********************************************************************
235 #ifndef HAVE_GETPROTOBYNAME
236 struct protoent *getprotobyname(const char *name)
241 #endif /* !defined(HAVE_GETPROTOBYNAME) */
243 /***********************************************************************
246 #ifndef HAVE_GETPROTOBYNUMBER
247 struct protoent *getprotobynumber(int proto)
252 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
254 /***********************************************************************
257 #ifndef HAVE_GETSERVBYPORT
258 struct servent *getservbyport(int port, const char *proto)
263 #endif /* !defined(HAVE_GETSERVBYPORT) */
265 /***********************************************************************
268 #ifndef HAVE_GETSOCKOPT
269 int getsockopt(int socket, int level, int option_name,
270 void *option_value, size_t *option_len)
275 #endif /* !defined(HAVE_GETSOCKOPT) */
277 /***********************************************************************
280 #ifndef HAVE_INET_NETWORK
281 unsigned long inet_network(const char *cp)
286 #endif /* defined(HAVE_INET_NETWORK) */
288 /***********************************************************************
291 #ifndef HAVE_SETTIMEOFDAY
292 int settimeofday(struct timeval *tp, void *reserved)
300 #endif /* HAVE_SETTIMEOFDAY */
302 /***********************************************************************
306 int statfs(const char *name, struct statfs *info)
317 if ((mydev = dev_for_path(name)) < 0) {
322 if (fs_stat_dev(mydev,&fsinfo) < 0) {
327 info->f_bsize = fsinfo.block_size;
328 info->f_blocks = fsinfo.total_blocks;
329 info->f_bfree = fsinfo.free_blocks;
332 #else /* defined(__BEOS__) */
335 #endif /* defined(__BEOS__) */
337 #endif /* !defined(HAVE_STATFS) */