blob: 5efdab5ba8554dbd013b66771ce2b4179a3336b6 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* this file contains system-dependent definitions used by ADB
18 * they're related to threads, sockets and file descriptors
19 */
20#ifndef _ADB_SYSDEPS_H
21#define _ADB_SYSDEPS_H
22
23#ifdef __CYGWIN__
24# undef _WIN32
25#endif
26
Dan Albertcc731cc2015-02-24 21:26:58 -080027/*
28 * TEMP_FAILURE_RETRY is defined by some, but not all, versions of
29 * <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's
30 * not already defined, then define it here.
31 */
32#ifndef TEMP_FAILURE_RETRY
33/* Used to retry syscalls that can return EINTR. */
34#define TEMP_FAILURE_RETRY(exp) ({ \
35 typeof (exp) _rc; \
36 do { \
37 _rc = (exp); \
38 } while (_rc == -1 && errno == EINTR); \
39 _rc; })
40#endif
41
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080042#ifdef _WIN32
43
Dan Albert630b9af2014-11-24 23:34:35 -080044#include <ctype.h>
45#include <direct.h>
46#include <errno.h>
47#include <fcntl.h>
48#include <io.h>
49#include <process.h>
50#include <sys/stat.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080051#include <winsock2.h>
Stephen Hines2f431a82014-10-01 17:37:06 -070052#include <windows.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080053#include <ws2tcpip.h>
Dan Albert630b9af2014-11-24 23:34:35 -080054
55#include "fdevent.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080056
57#define OS_PATH_SEPARATOR '\\'
58#define OS_PATH_SEPARATOR_STR "\\"
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070059#define ENV_PATH_SEPARATOR_STR ";"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080060
61typedef CRITICAL_SECTION adb_mutex_t;
62
63#define ADB_MUTEX_DEFINE(x) adb_mutex_t x
64
65/* declare all mutexes */
JP Abgrall408fa572011-03-16 15:57:42 -070066/* For win32, adb_sysdeps_init() will do the mutex runtime initialization. */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080067#define ADB_MUTEX(x) extern adb_mutex_t x;
68#include "mutex_list.h"
69
70extern void adb_sysdeps_init(void);
71
72static __inline__ void adb_mutex_lock( adb_mutex_t* lock )
73{
74 EnterCriticalSection( lock );
75}
76
77static __inline__ void adb_mutex_unlock( adb_mutex_t* lock )
78{
79 LeaveCriticalSection( lock );
80}
81
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080082typedef void* (*adb_thread_func_t)(void* arg);
83
84typedef void (*win_thread_func_t)(void* arg);
85
Elliott Hughes9b0f3542015-05-05 13:41:21 -070086static __inline__ bool adb_thread_create(adb_thread_func_t func, void* arg) {
Elliott Hughes2e4a2ee2015-05-05 14:34:41 -070087 uintptr_t tid = _beginthread((win_thread_func_t)func, 0, arg);
88 return (tid != static_cast<uintptr_t>(-1L));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080089}
90
leozwangcbf02672014-08-15 09:51:27 -070091static __inline__ unsigned long adb_thread_id()
92{
93 return GetCurrentThreadId();
94}
95
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080096static __inline__ void close_on_exec(int fd)
97{
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +020098 /* nothing really */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080099}
100
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800101#define lstat stat /* no symlinks on Win32 */
102
103#define S_ISLNK(m) 0 /* no symlinks on Win32 */
104
105static __inline__ int adb_unlink(const char* path)
106{
107 int rc = unlink(path);
108
109 if (rc == -1 && errno == EACCES) {
110 /* unlink returns EACCES when the file is read-only, so we first */
111 /* try to make it writable, then unlink again... */
112 rc = chmod(path, _S_IREAD|_S_IWRITE );
113 if (rc == 0)
114 rc = unlink(path);
115 }
116 return rc;
117}
118#undef unlink
119#define unlink ___xxx_unlink
120
121static __inline__ int adb_mkdir(const char* path, int mode)
122{
JP Abgrall0e7c4272011-02-23 18:44:39 -0800123 return _mkdir(path);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800124}
125#undef mkdir
126#define mkdir ___xxx_mkdir
127
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700128// See the comments for the !defined(_WIN32) versions of adb_*().
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800129extern int adb_open(const char* path, int options);
130extern int adb_creat(const char* path, int mode);
131extern int adb_read(int fd, void* buf, int len);
132extern int adb_write(int fd, const void* buf, int len);
133extern int adb_lseek(int fd, int pos, int where);
Mike Lockwood8cf0d592009-10-11 23:04:18 -0400134extern int adb_shutdown(int fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800135extern int adb_close(int fd);
136
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700137// See the comments for the !defined(_WIN32) version of unix_close().
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800138static __inline__ int unix_close(int fd)
139{
140 return close(fd);
141}
142#undef close
143#define close ____xxx_close
144
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700145// See the comments for the !defined(_WIN32) version of unix_read().
Spencer Low50184062015-03-01 15:06:21 -0800146extern int unix_read(int fd, void* buf, size_t len);
147
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800148#undef read
149#define read ___xxx_read
150
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700151// See the comments for the !defined(_WIN32) version of unix_write().
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800152static __inline__ int unix_write(int fd, const void* buf, size_t len)
153{
154 return write(fd, buf, len);
155}
156#undef write
157#define write ___xxx_write
158
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700159// See the comments for the !defined(_WIN32) version of adb_open_mode().
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800160static __inline__ int adb_open_mode(const char* path, int options, int mode)
161{
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200162 return adb_open(path, options);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800163}
164
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700165// See the comments for the !defined(_WIN32) version of unix_open().
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800166static __inline__ int unix_open(const char* path, int options,...)
167{
168 if ((options & O_CREAT) == 0)
169 {
170 return open(path, options);
171 }
172 else
173 {
174 int mode;
175 va_list args;
176 va_start( args, options );
177 mode = va_arg( args, int );
178 va_end( args );
179 return open(path, options, mode);
180 }
181}
182#define open ___xxx_unix_open
183
184
185/* normally provided by <cutils/misc.h> */
186extern void* load_file(const char* pathname, unsigned* psize);
187
188/* normally provided by <cutils/sockets.h> */
189extern int socket_loopback_client(int port, int type);
190extern int socket_network_client(const char *host, int port, int type);
Elliott Hughesb911cf02014-05-20 08:51:15 -0700191extern int socket_network_client_timeout(const char *host, int port, int type,
192 int timeout);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800193extern int socket_loopback_server(int port, int type);
194extern int socket_inaddr_any_server(int port, int type);
195
David 'Digit' Turner414ff7d2009-05-18 17:07:46 +0200196/* normally provided by "fdevent.h" */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800197
198#define FDE_READ 0x0001
199#define FDE_WRITE 0x0002
200#define FDE_ERROR 0x0004
201#define FDE_DONT_CLOSE 0x0080
202
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800203typedef void (*fd_func)(int fd, unsigned events, void *userdata);
204
205fdevent *fdevent_create(int fd, fd_func func, void *arg);
206void fdevent_destroy(fdevent *fde);
207void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg);
208void fdevent_remove(fdevent *item);
209void fdevent_set(fdevent *fde, unsigned events);
210void fdevent_add(fdevent *fde, unsigned events);
211void fdevent_del(fdevent *fde, unsigned events);
212void fdevent_loop();
213
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800214static __inline__ void adb_sleep_ms( int mseconds )
215{
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200216 Sleep( mseconds );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800217}
218
219extern int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrlen);
220
221#undef accept
222#define accept ___xxx_accept
223
Spencer Lowf055c192015-01-25 14:40:16 -0800224extern int adb_setsockopt(int fd, int level, int optname, const void* optval, socklen_t optlen);
225
226#undef setsockopt
227#define setsockopt ___xxx_setsockopt
228
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800229static __inline__ int adb_socket_setbufsize( int fd, int bufsize )
230{
231 int opt = bufsize;
Spencer Lowf055c192015-01-25 14:40:16 -0800232 return adb_setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const void*)&opt, sizeof(opt));
233}
234
235static __inline__ void disable_tcp_nagle( int fd )
236{
237 int on = 1;
238 adb_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void*)&on, sizeof(on));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800239}
240
241extern int adb_socketpair( int sv[2] );
242
243static __inline__ char* adb_dirstart( const char* path )
244{
245 char* p = strchr(path, '/');
246 char* p2 = strchr(path, '\\');
247
248 if ( !p )
249 p = p2;
250 else if ( p2 && p2 > p )
251 p = p2;
252
253 return p;
254}
255
256static __inline__ char* adb_dirstop( const char* path )
257{
258 char* p = strrchr(path, '/');
259 char* p2 = strrchr(path, '\\');
260
261 if ( !p )
262 p = p2;
263 else if ( p2 && p2 > p )
264 p = p2;
265
266 return p;
267}
268
269static __inline__ int adb_is_absolute_host_path( const char* path )
270{
271 return isalpha(path[0]) && path[1] == ':' && path[2] == '\\';
272}
273
274#else /* !_WIN32 a.k.a. Unix */
275
David 'Digit' Turner414ff7d2009-05-18 17:07:46 +0200276#include "fdevent.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800277#include <cutils/sockets.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800278#include <cutils/misc.h>
Spencer Low8d8126a2015-07-21 02:06:26 -0700279#include <cutils/threads.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800280#include <signal.h>
281#include <sys/wait.h>
282#include <sys/stat.h>
283#include <fcntl.h>
284
285#include <pthread.h>
286#include <unistd.h>
287#include <fcntl.h>
288#include <stdarg.h>
289#include <netinet/in.h>
290#include <netinet/tcp.h>
291#include <string.h>
Kenny Root73167412012-10-12 15:26:45 -0700292#include <unistd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800293
294#define OS_PATH_SEPARATOR '/'
295#define OS_PATH_SEPARATOR_STR "/"
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700296#define ENV_PATH_SEPARATOR_STR ":"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800297
298typedef pthread_mutex_t adb_mutex_t;
JP Abgrall408fa572011-03-16 15:57:42 -0700299
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800300#define ADB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
301#define adb_mutex_init pthread_mutex_init
302#define adb_mutex_lock pthread_mutex_lock
303#define adb_mutex_unlock pthread_mutex_unlock
304#define adb_mutex_destroy pthread_mutex_destroy
305
JP Abgrall408fa572011-03-16 15:57:42 -0700306#define ADB_MUTEX_DEFINE(m) adb_mutex_t m = PTHREAD_MUTEX_INITIALIZER
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800307
308#define adb_cond_t pthread_cond_t
309#define adb_cond_init pthread_cond_init
310#define adb_cond_wait pthread_cond_wait
311#define adb_cond_broadcast pthread_cond_broadcast
312#define adb_cond_signal pthread_cond_signal
313#define adb_cond_destroy pthread_cond_destroy
314
JP Abgrall408fa572011-03-16 15:57:42 -0700315/* declare all mutexes */
316#define ADB_MUTEX(x) extern adb_mutex_t x;
317#include "mutex_list.h"
318
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800319static __inline__ void close_on_exec(int fd)
320{
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200321 fcntl( fd, F_SETFD, FD_CLOEXEC );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800322}
323
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700324// Open a file and return a file descriptor that may be used with unix_read(),
325// unix_write(), unix_close(), but not adb_read(), adb_write(), adb_close().
326//
327// On Unix, this is based on open(), so the file descriptor is a real OS file
328// descriptor, but the Windows implementation (in sysdeps_win32.cpp) returns a
329// file descriptor that can only be used with C Runtime APIs (which are wrapped
330// by unix_read(), unix_write(), unix_close()). Also, the C Runtime has
331// configurable CR/LF translation which defaults to text mode, but is settable
332// with _setmode().
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800333static __inline__ int unix_open(const char* path, int options,...)
334{
335 if ((options & O_CREAT) == 0)
336 {
Kenny Root73167412012-10-12 15:26:45 -0700337 return TEMP_FAILURE_RETRY( open(path, options) );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800338 }
339 else
340 {
341 int mode;
342 va_list args;
343 va_start( args, options );
344 mode = va_arg( args, int );
345 va_end( args );
Kenny Root73167412012-10-12 15:26:45 -0700346 return TEMP_FAILURE_RETRY( open( path, options, mode ) );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800347 }
348}
349
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700350// Similar to the two-argument adb_open(), but takes a mode parameter for file
351// creation. See adb_open() for more info.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800352static __inline__ int adb_open_mode( const char* pathname, int options, int mode )
353{
Kenny Root73167412012-10-12 15:26:45 -0700354 return TEMP_FAILURE_RETRY( open( pathname, options, mode ) );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800355}
356
357
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700358// Open a file and return a file descriptor that may be used with adb_read(),
359// adb_write(), adb_close(), but not unix_read(), unix_write(), unix_close().
360//
361// On Unix, this is based on open(), but the Windows implementation (in
362// sysdeps_win32.cpp) uses Windows native file I/O and bypasses the C Runtime
363// and its CR/LF translation. The returned file descriptor should be used with
364// adb_read(), adb_write(), adb_close(), etc.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800365static __inline__ int adb_open( const char* pathname, int options )
366{
Kenny Root73167412012-10-12 15:26:45 -0700367 int fd = TEMP_FAILURE_RETRY( open( pathname, options ) );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800368 if (fd < 0)
369 return -1;
370 close_on_exec( fd );
371 return fd;
372}
373#undef open
374#define open ___xxx_open
375
Mike Lockwood8cf0d592009-10-11 23:04:18 -0400376static __inline__ int adb_shutdown(int fd)
377{
378 return shutdown(fd, SHUT_RDWR);
379}
380#undef shutdown
381#define shutdown ____xxx_shutdown
382
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700383// Closes a file descriptor that came from adb_open() or adb_open_mode(), but
384// not designed to take a file descriptor from unix_open(). See the comments
385// for adb_open() for more info.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800386static __inline__ int adb_close(int fd)
387{
388 return close(fd);
389}
390#undef close
391#define close ____xxx_close
392
393
394static __inline__ int adb_read(int fd, void* buf, size_t len)
395{
Kenny Root73167412012-10-12 15:26:45 -0700396 return TEMP_FAILURE_RETRY( read( fd, buf, len ) );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800397}
398
399#undef read
400#define read ___xxx_read
401
402static __inline__ int adb_write(int fd, const void* buf, size_t len)
403{
Kenny Root73167412012-10-12 15:26:45 -0700404 return TEMP_FAILURE_RETRY( write( fd, buf, len ) );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800405}
406#undef write
407#define write ___xxx_write
408
409static __inline__ int adb_lseek(int fd, int pos, int where)
410{
411 return lseek(fd, pos, where);
412}
413#undef lseek
414#define lseek ___xxx_lseek
415
416static __inline__ int adb_unlink(const char* path)
417{
418 return unlink(path);
419}
420#undef unlink
421#define unlink ___xxx_unlink
422
423static __inline__ int adb_creat(const char* path, int mode)
424{
Kenny Root73167412012-10-12 15:26:45 -0700425 int fd = TEMP_FAILURE_RETRY( creat( path, mode ) );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800426
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200427 if ( fd < 0 )
428 return -1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800429
430 close_on_exec(fd);
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200431 return fd;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800432}
433#undef creat
434#define creat ___xxx_creat
435
436static __inline__ int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrlen)
437{
Benoit Goby95ef8282011-02-01 18:57:41 -0800438 int fd;
439
Kenny Root73167412012-10-12 15:26:45 -0700440 fd = TEMP_FAILURE_RETRY( accept( serverfd, addr, addrlen ) );
Benoit Goby95ef8282011-02-01 18:57:41 -0800441 if (fd >= 0)
442 close_on_exec(fd);
443
444 return fd;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800445}
446
447#undef accept
448#define accept ___xxx_accept
449
Spencer Low6ac5d7d2015-05-22 20:09:06 -0700450// Operate on a file descriptor returned from unix_open() or a well-known file
451// descriptor such as STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO.
452//
453// On Unix, unix_read(), unix_write(), unix_close() map to adb_read(),
454// adb_write(), adb_close() (which all map to Unix system calls), but the
455// Windows implementations (in the ifdef above and in sysdeps_win32.cpp) call
456// into the C Runtime and its configurable CR/LF translation (which is settable
457// via _setmode()).
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800458#define unix_read adb_read
459#define unix_write adb_write
460#define unix_close adb_close
461
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800462typedef void* (*adb_thread_func_t)( void* arg );
463
Elliott Hughes9b0f3542015-05-05 13:41:21 -0700464static __inline__ bool adb_thread_create(adb_thread_func_t start, void* arg) {
465 pthread_attr_t attr;
466 pthread_attr_init(&attr);
467 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800468
Elliott Hughes9b0f3542015-05-05 13:41:21 -0700469 pthread_t thread;
470 errno = pthread_create(&thread, &attr, start, arg);
471 return (errno == 0);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800472}
473
474static __inline__ int adb_socket_setbufsize( int fd, int bufsize )
475{
476 int opt = bufsize;
477 return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt));
478}
479
480static __inline__ void disable_tcp_nagle(int fd)
481{
482 int on = 1;
483 setsockopt( fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on) );
484}
485
Spencer Lowf055c192015-01-25 14:40:16 -0800486static __inline__ int adb_setsockopt( int fd, int level, int optname, const void* optval, socklen_t optlen )
487{
488 return setsockopt( fd, level, optname, optval, optlen );
489}
490
491#undef setsockopt
492#define setsockopt ___xxx_setsockopt
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800493
494static __inline__ int unix_socketpair( int d, int type, int protocol, int sv[2] )
495{
496 return socketpair( d, type, protocol, sv );
497}
498
499static __inline__ int adb_socketpair( int sv[2] )
500{
501 int rc;
502
503 rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv );
504 if (rc < 0)
505 return -1;
506
507 close_on_exec( sv[0] );
508 close_on_exec( sv[1] );
509 return 0;
510}
511
512#undef socketpair
513#define socketpair ___xxx_socketpair
514
515static __inline__ void adb_sleep_ms( int mseconds )
516{
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200517 usleep( mseconds*1000 );
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800518}
519
520static __inline__ int adb_mkdir(const char* path, int mode)
521{
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200522 return mkdir(path, mode);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800523}
524#undef mkdir
525#define mkdir ___xxx_mkdir
526
527static __inline__ void adb_sysdeps_init(void)
528{
529}
530
531static __inline__ char* adb_dirstart(const char* path)
532{
533 return strchr(path, '/');
534}
535
536static __inline__ char* adb_dirstop(const char* path)
537{
538 return strrchr(path, '/');
539}
540
541static __inline__ int adb_is_absolute_host_path( const char* path )
542{
543 return path[0] == '/';
544}
545
leozwangcbf02672014-08-15 09:51:27 -0700546static __inline__ unsigned long adb_thread_id()
547{
Spencer Low8d8126a2015-07-21 02:06:26 -0700548 return (unsigned long)gettid();
leozwangcbf02672014-08-15 09:51:27 -0700549}
550
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800551#endif /* !_WIN32 */
552
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800553#endif /* _ADB_SYSDEPS_H */