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>
33 /***********************************************************************
37 unsigned int usleep (unsigned int useconds
)
42 #elif defined(__BEOS__)
43 return snooze(useconds
);
44 #elif defined(HAVE_SELECT)
48 delay
.tv_usec
= useconds
;
50 select( 0, 0, 0, 0, &delay
);
52 #else /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
55 #endif /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
57 #endif /* HAVE_USLEEP */
59 /***********************************************************************
63 void *memmove( void *dest
, const void *src
, unsigned int len
)
65 register char *dst
= dest
;
67 /* Use memcpy if not overlapping */
68 if ((dst
+ len
<= (char *)src
) || ((char *)src
+ len
<= dst
))
70 memcpy( dst
, src
, len
);
72 /* Otherwise do it the hard way (FIXME: could do better than this) */
75 while (len
--) *dst
++ = *((char *)src
)++;
80 src
= (char *)src
+ len
- 1;
81 while (len
--) *dst
-- = *((char *)src
)--;
85 #endif /* HAVE_MEMMOVE */
87 /***********************************************************************
91 const char *strerror( int err
)
93 /* Let's hope we have sys_errlist then */
94 return sys_errlist
[err
];
96 #endif /* HAVE_STRERROR */
98 /***********************************************************************
101 #if !defined(HAVE_CLONE) && defined(__linux__)
102 int clone( int (*fn
)(void *), void *stack
, int flags
, void *arg
)
106 void **stack_ptr
= (void **)stack
;
107 *--stack_ptr
= arg
; /* Push argument on stack */
108 *--stack_ptr
= fn
; /* Push function pointer (popped into ebx) */
109 __asm__
__volatile__( "pushl %%ebx\n\t"
112 "popl %%ebx\n\t" /* Contains fn in the child */
113 "testl %%eax,%%eax\n\t"
115 "call *%%ebx\n\t" /* Should never return */
116 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
119 : "0" (SYS_clone
), "r" (flags
), "c" (stack_ptr
) );
120 assert( ret
); /* If ret is 0, we returned from the child function */
121 if (ret
> 0) return ret
;
127 #endif /* __i386__ */
129 #endif /* !HAVE_CLONE && __linux__ */
131 /***********************************************************************
134 #ifndef HAVE_STRCASECMP
135 int strcasecmp( const char *str1
, const char *str2
)
137 while (*str1
&& toupper(*str1
) == toupper(*str2
)) { str1
++; str2
++; }
138 return toupper(*str1
) - toupper(*str2
);
140 #endif /* HAVE_STRCASECMP */
142 /***********************************************************************
145 #ifndef HAVE_STRNCASECMP
146 int strncasecmp( const char *str1
, const char *str2
, size_t n
)
150 while ((--n
> 0) && *str1
)
151 if ((res
= toupper(*str1
++) - toupper(*str2
++))) return res
;
152 return toupper(*str1
) - toupper(*str2
);
154 #endif /* HAVE_STRNCASECMP */
156 /***********************************************************************
159 * It looks like the openpty that comes with glibc in RedHat 5.0
160 * is buggy (second call returns what looks like a dup of 0 and 1
161 * instead of a new pty), this is a generic replacement.
164 * We should have a autoconf check for this.
166 int wine_openpty(int *master
, int *slave
, char *name
,
167 struct termios
*term
, struct winsize
*winsize
)
172 strcpy (pts_name
, "/dev/ptyXY");
174 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
176 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
179 if ((*master
= open(pts_name
, O_RDWR
)) < 0) {
186 if ((*slave
= open(pts_name
, O_RDWR
)) < 0) {
192 tcsetattr(*slave
, TCSANOW
, term
);
194 ioctl(*slave
, TIOCSWINSZ
, winsize
);
196 strcpy(name
, pts_name
);
203 /***********************************************************************
206 #ifndef HAVE_GETNETBYADDR
207 struct netent
*getnetbyaddr(unsigned long net
, int type
)
212 #endif /* defined(HAVE_GETNETBYNAME) */
214 /***********************************************************************
217 #ifndef HAVE_GETNETBYNAME
218 struct netent
*getnetbyname(const char *name
)
223 #endif /* defined(HAVE_GETNETBYNAME) */
225 /***********************************************************************
228 #ifndef HAVE_GETPROTOBYNAME
229 struct protoent
*getprotobyname(const char *name
)
234 #endif /* !defined(HAVE_GETPROTOBYNAME) */
236 /***********************************************************************
239 #ifndef HAVE_GETPROTOBYNUMBER
240 struct protoent
*getprotobynumber(int proto
)
245 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
247 /***********************************************************************
250 #ifndef HAVE_GETSERVBYPORT
251 struct servent
*getservbyport(int port
, const char *proto
)
256 #endif /* !defined(HAVE_GETSERVBYPORT) */
258 /***********************************************************************
261 #ifndef HAVE_GETSOCKOPT
262 int getsockopt(int socket
, int level
, int option_name
,
263 void *option_value
, size_t *option_len
)
268 #endif /* !defined(HAVE_GETSOCKOPT) */
270 /***********************************************************************
273 #ifndef HAVE_INET_NETWORK
274 unsigned long inet_network(const char *cp
)
279 #endif /* defined(HAVE_INET_NETWORK) */
281 /***********************************************************************
284 #ifndef HAVE_SETTIMEOFDAY
285 int settimeofday(struct timeval
*tp
, void *reserved
)
293 #endif /* HAVE_SETTIMEOFDAY */
295 /***********************************************************************
299 int statfs(const char *name
, struct statfs
*info
)
310 if ((mydev
= dev_for_path(name
)) < 0) {
315 if (fs_stat_dev(mydev
,&fsinfo
) < 0) {
320 info
->f_bsize
= fsinfo
.block_size
;
321 info
->f_blocks
= fsinfo
.total_blocks
;
322 info
->f_bfree
= fsinfo
.free_blocks
;
325 #else /* defined(__BEOS__) */
328 #endif /* defined(__BEOS__) */
330 #endif /* !defined(HAVE_STATFS) */