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>
39 #include "wine/port.h"
41 /***********************************************************************
45 unsigned int usleep (unsigned int useconds
)
50 #elif defined(__BEOS__)
51 return snooze(useconds
);
52 #elif defined(HAVE_SELECT)
56 delay
.tv_usec
= useconds
;
58 select( 0, 0, 0, 0, &delay
);
60 #else /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
63 #endif /* defined(__EMX__) || defined(__BEOS__) || defined(HAVE_SELECT) */
65 #endif /* HAVE_USLEEP */
67 /***********************************************************************
71 void *memmove( void *dest
, const void *src
, unsigned int len
)
73 register char *dst
= dest
;
75 /* Use memcpy if not overlapping */
76 if ((dst
+ len
<= (char *)src
) || ((char *)src
+ len
<= dst
))
78 memcpy( dst
, src
, len
);
80 /* Otherwise do it the hard way (FIXME: could do better than this) */
83 while (len
--) *dst
++ = *((char *)src
)++;
88 src
= (char *)src
+ len
- 1;
89 while (len
--) *dst
-- = *((char *)src
)--;
93 #endif /* HAVE_MEMMOVE */
95 /***********************************************************************
99 const char *strerror( int err
)
101 /* Let's hope we have sys_errlist then */
102 return sys_errlist
[err
];
104 #endif /* HAVE_STRERROR */
106 /***********************************************************************
109 #if !defined(HAVE_CLONE) && defined(__linux__)
110 int clone( int (*fn
)(void *), void *stack
, int flags
, void *arg
)
114 void **stack_ptr
= (void **)stack
;
115 *--stack_ptr
= arg
; /* Push argument on stack */
116 *--stack_ptr
= fn
; /* Push function pointer (popped into ebx) */
117 __asm__
__volatile__( "pushl %%ebx\n\t"
120 "popl %%ebx\n\t" /* Contains fn in the child */
121 "testl %%eax,%%eax\n\t"
123 "call *%%ebx\n\t" /* Should never return */
124 "xorl %%eax,%%eax\n\t" /* Just in case it does*/
127 : "0" (SYS_clone
), "r" (flags
), "c" (stack_ptr
) );
128 assert( ret
); /* If ret is 0, we returned from the child function */
129 if (ret
> 0) return ret
;
135 #endif /* __i386__ */
137 #endif /* !HAVE_CLONE && __linux__ */
139 /***********************************************************************
142 #ifndef HAVE_STRCASECMP
143 int strcasecmp( const char *str1
, const char *str2
)
145 while (*str1
&& toupper(*str1
) == toupper(*str2
)) { str1
++; str2
++; }
146 return toupper(*str1
) - toupper(*str2
);
148 #endif /* HAVE_STRCASECMP */
150 /***********************************************************************
153 #ifndef HAVE_STRNCASECMP
154 int strncasecmp( const char *str1
, const char *str2
, size_t n
)
158 while ((--n
> 0) && *str1
)
159 if ((res
= toupper(*str1
++) - toupper(*str2
++))) return res
;
160 return toupper(*str1
) - toupper(*str2
);
162 #endif /* HAVE_STRNCASECMP */
164 /***********************************************************************
167 * It looks like the openpty that comes with glibc in RedHat 5.0
168 * is buggy (second call returns what looks like a dup of 0 and 1
169 * instead of a new pty), this is a generic replacement.
172 * We should have a autoconf check for this.
174 int wine_openpty(int *master
, int *slave
, char *name
,
175 struct termios
*term
, struct winsize
*winsize
)
178 return openpty(master
,slave
,name
,term
,winsize
);
183 strcpy (pts_name
, "/dev/ptyXY");
185 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
187 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
190 if ((*master
= open(pts_name
, O_RDWR
)) < 0) {
197 if ((*slave
= open(pts_name
, O_RDWR
)) < 0) {
203 tcsetattr(*slave
, TCSANOW
, term
);
205 ioctl(*slave
, TIOCSWINSZ
, winsize
);
207 strcpy(name
, pts_name
);
215 /***********************************************************************
218 #ifndef HAVE_GETNETBYADDR
219 struct netent
*getnetbyaddr(unsigned long net
, int type
)
224 #endif /* defined(HAVE_GETNETBYNAME) */
226 /***********************************************************************
229 #ifndef HAVE_GETNETBYNAME
230 struct netent
*getnetbyname(const char *name
)
235 #endif /* defined(HAVE_GETNETBYNAME) */
237 /***********************************************************************
240 #ifndef HAVE_GETPROTOBYNAME
241 struct protoent
*getprotobyname(const char *name
)
246 #endif /* !defined(HAVE_GETPROTOBYNAME) */
248 /***********************************************************************
251 #ifndef HAVE_GETPROTOBYNUMBER
252 struct protoent
*getprotobynumber(int proto
)
257 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
259 /***********************************************************************
262 #ifndef HAVE_GETSERVBYPORT
263 struct servent
*getservbyport(int port
, const char *proto
)
268 #endif /* !defined(HAVE_GETSERVBYPORT) */
270 /***********************************************************************
273 #ifndef HAVE_GETSOCKOPT
274 int getsockopt(int socket
, int level
, int option_name
,
275 void *option_value
, size_t *option_len
)
280 #endif /* !defined(HAVE_GETSOCKOPT) */
282 /***********************************************************************
285 #ifndef HAVE_INET_NETWORK
286 unsigned long inet_network(const char *cp
)
291 #endif /* defined(HAVE_INET_NETWORK) */
293 /***********************************************************************
296 #ifndef HAVE_SETTIMEOFDAY
297 int settimeofday(struct timeval
*tp
, void *reserved
)
305 #endif /* HAVE_SETTIMEOFDAY */
307 /***********************************************************************
311 int statfs(const char *name
, struct statfs
*info
)
322 if ((mydev
= dev_for_path(name
)) < 0) {
327 if (fs_stat_dev(mydev
,&fsinfo
) < 0) {
332 info
->f_bsize
= fsinfo
.block_size
;
333 info
->f_blocks
= fsinfo
.total_blocks
;
334 info
->f_bfree
= fsinfo
.free_blocks
;
337 #else /* defined(__BEOS__) */
340 #endif /* defined(__BEOS__) */
342 #endif /* !defined(HAVE_STATFS) */