sysdeps.h revision 79d8f07a6f97511397d96dbb0676d710ce604f8c
1/*
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
27#include <errno.h>
28
29#include <string>
30
31// Include this before open/unlink are defined as macros below.
32#include <android-base/utf8.h>
33
34/*
35 * TEMP_FAILURE_RETRY is defined by some, but not all, versions of
36 * <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's
37 * not already defined, then define it here.
38 */
39#ifndef TEMP_FAILURE_RETRY
40/* Used to retry syscalls that can return EINTR. */
41#define TEMP_FAILURE_RETRY(exp) ({         \
42    typeof (exp) _rc;                      \
43    do {                                   \
44        _rc = (exp);                       \
45    } while (_rc == -1 && errno == EINTR); \
46    _rc; })
47#endif
48
49// Some printf-like functions are implemented in terms of
50// android::base::StringAppendV, so they should use the same attribute for
51// compile-time format string checking. On Windows, if the mingw version of
52// vsnprintf is used in StringAppendV, use `gnu_printf' which allows z in %zd
53// and PRIu64 (and related) to be recognized by the compile-time checking.
54#define ADB_FORMAT_ARCHETYPE __printf__
55#ifdef __USE_MINGW_ANSI_STDIO
56#if __USE_MINGW_ANSI_STDIO
57#undef ADB_FORMAT_ARCHETYPE
58#define ADB_FORMAT_ARCHETYPE gnu_printf
59#endif
60#endif
61
62#ifdef _WIN32
63
64// Clang-only nullability specifiers
65#define _Nonnull
66#define _Nullable
67
68#include <ctype.h>
69#include <direct.h>
70#include <dirent.h>
71#include <errno.h>
72#include <fcntl.h>
73#include <io.h>
74#include <process.h>
75#include <sys/stat.h>
76#include <utime.h>
77#include <winsock2.h>
78#include <windows.h>
79#include <ws2tcpip.h>
80
81#include <memory>   // unique_ptr
82#include <string>
83
84#include "fdevent.h"
85
86#define OS_PATH_SEPARATORS "\\/"
87#define OS_PATH_SEPARATOR '\\'
88#define OS_PATH_SEPARATOR_STR "\\"
89#define ENV_PATH_SEPARATOR_STR ";"
90
91static __inline__ bool adb_is_separator(char c) {
92    return c == '\\' || c == '/';
93}
94
95typedef CRITICAL_SECTION          adb_mutex_t;
96
97#define  ADB_MUTEX_DEFINE(x)     adb_mutex_t   x
98
99/* declare all mutexes */
100/* For win32, adb_sysdeps_init() will do the mutex runtime initialization. */
101#define  ADB_MUTEX(x)   extern adb_mutex_t  x;
102#include "mutex_list.h"
103
104extern void  adb_sysdeps_init(void);
105
106static __inline__ void adb_mutex_lock( adb_mutex_t*  lock )
107{
108    EnterCriticalSection( lock );
109}
110
111static __inline__ void  adb_mutex_unlock( adb_mutex_t*  lock )
112{
113    LeaveCriticalSection( lock );
114}
115
116typedef  void*  (*adb_thread_func_t)(void*  arg);
117
118typedef  void (*win_thread_func_t)(void*  arg);
119
120static __inline__ bool adb_thread_create(adb_thread_func_t func, void* arg) {
121    uintptr_t tid = _beginthread((win_thread_func_t)func, 0, arg);
122    return (tid != static_cast<uintptr_t>(-1L));
123}
124
125static __inline__ int adb_thread_setname(const std::string& name) {
126    // TODO: See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx for how to set
127    // the thread name in Windows. Unfortunately, it only works during debugging, but
128    // our build process doesn't generate PDB files needed for debugging.
129    return 0;
130}
131
132static __inline__  unsigned long adb_thread_id()
133{
134    return GetCurrentThreadId();
135}
136
137static __inline__ void  close_on_exec(int  fd)
138{
139    /* nothing really */
140}
141
142#define  lstat    stat   /* no symlinks on Win32 */
143
144#define  S_ISLNK(m)   0   /* no symlinks on Win32 */
145
146extern int  adb_unlink(const char*  path);
147#undef  unlink
148#define unlink  ___xxx_unlink
149
150extern int adb_mkdir(const std::string& path, int mode);
151#undef   mkdir
152#define  mkdir  ___xxx_mkdir
153
154// See the comments for the !defined(_WIN32) versions of adb_*().
155extern int  adb_open(const char*  path, int  options);
156extern int  adb_creat(const char*  path, int  mode);
157extern int  adb_read(int  fd, void* buf, int len);
158extern int  adb_write(int  fd, const void*  buf, int  len);
159extern int  adb_lseek(int  fd, int  pos, int  where);
160extern int  adb_shutdown(int  fd);
161extern int  adb_close(int  fd);
162
163// See the comments for the !defined(_WIN32) version of unix_close().
164static __inline__ int  unix_close(int fd)
165{
166    return close(fd);
167}
168#undef   close
169#define  close   ____xxx_close
170
171// Like unix_read(), but may return EINTR.
172extern int  unix_read_interruptible(int  fd, void*  buf, size_t  len);
173
174// See the comments for the !defined(_WIN32) version of unix_read().
175static __inline__ int unix_read(int fd, void* buf, size_t len) {
176    return TEMP_FAILURE_RETRY(unix_read_interruptible(fd, buf, len));
177}
178
179#undef   read
180#define  read  ___xxx_read
181
182// See the comments for the !defined(_WIN32) version of unix_write().
183static __inline__  int  unix_write(int  fd, const void*  buf, size_t  len)
184{
185    return write(fd, buf, len);
186}
187#undef   write
188#define  write  ___xxx_write
189
190// See the comments for the !defined(_WIN32) version of adb_open_mode().
191static __inline__ int  adb_open_mode(const char* path, int options, int mode)
192{
193    return adb_open(path, options);
194}
195
196// See the comments for the !defined(_WIN32) version of unix_open().
197extern int unix_open(const char* path, int options, ...);
198#define  open    ___xxx_unix_open
199
200// Checks if |fd| corresponds to a console.
201// Standard Windows isatty() returns 1 for both console FDs and character
202// devices like NUL. unix_isatty() performs some extra checking to only match
203// console FDs.
204// |fd| must be a real file descriptor, meaning STDxx_FILENO or unix_open() FDs
205// will work but adb_open() FDs will not. Additionally the OS handle associated
206// with |fd| must have GENERIC_READ access (which console FDs have by default).
207// Returns 1 if |fd| is a console FD, 0 otherwise. The value of errno after
208// calling this function is unreliable and should not be used.
209int unix_isatty(int fd);
210#define  isatty  ___xxx_isatty
211
212/* normally provided by <cutils/misc.h> */
213extern void*  load_file(const char*  pathname, unsigned*  psize);
214
215/* normally provided by "fdevent.h" */
216
217#define FDE_READ              0x0001
218#define FDE_WRITE             0x0002
219#define FDE_ERROR             0x0004
220#define FDE_DONT_CLOSE        0x0080
221
222typedef void (*fd_func)(int fd, unsigned events, void *userdata);
223
224fdevent *fdevent_create(int fd, fd_func func, void *arg);
225void     fdevent_destroy(fdevent *fde);
226void     fdevent_install(fdevent *fde, int fd, fd_func func, void *arg);
227void     fdevent_remove(fdevent *item);
228void     fdevent_set(fdevent *fde, unsigned events);
229void     fdevent_add(fdevent *fde, unsigned events);
230void     fdevent_del(fdevent *fde, unsigned events);
231void     fdevent_loop();
232
233static __inline__ void  adb_sleep_ms( int  mseconds )
234{
235    Sleep( mseconds );
236}
237
238int network_loopback_client(int port, int type, std::string* error);
239int network_loopback_server(int port, int type, std::string* error);
240int network_inaddr_any_server(int port, int type, std::string* error);
241int network_connect(const std::string& host, int port, int type, int timeout,
242                    std::string* error);
243
244extern int  adb_socket_accept(int  serverfd, struct sockaddr*  addr, socklen_t  *addrlen);
245
246#undef   accept
247#define  accept  ___xxx_accept
248
249extern int  adb_setsockopt(int  fd, int  level, int  optname, const void*  optval, socklen_t  optlen);
250
251#undef   setsockopt
252#define  setsockopt  ___xxx_setsockopt
253
254extern int  adb_socketpair( int  sv[2] );
255
256static __inline__ int adb_is_absolute_host_path(const char* path) {
257    return isalpha(path[0]) && path[1] == ':' && path[2] == '\\';
258}
259
260// We later define a macro mapping 'stat' to 'adb_stat'. This causes:
261//   struct stat s;
262//   stat(filename, &s);
263// To turn into the following:
264//   struct adb_stat s;
265//   adb_stat(filename, &s);
266// To get this to work, we need to make 'struct adb_stat' the same as
267// 'struct stat'. Note that this definition of 'struct adb_stat' uses the
268// *current* macro definition of stat, so it may actually be inheriting from
269// struct _stat32i64 (or some other remapping).
270struct adb_stat : public stat {};
271
272static_assert(sizeof(struct adb_stat) == sizeof(struct stat),
273    "structures should be the same");
274
275extern int adb_stat(const char* f, struct adb_stat* s);
276
277// stat is already a macro, undefine it so we can redefine it.
278#undef stat
279#define stat adb_stat
280
281// UTF-8 versions of POSIX APIs.
282extern DIR* adb_opendir(const char* dirname);
283extern struct dirent* adb_readdir(DIR* dir);
284extern int adb_closedir(DIR* dir);
285
286extern int adb_utime(const char *, struct utimbuf *);
287extern int adb_chmod(const char *, int);
288
289extern int adb_vfprintf(FILE *stream, const char *format, va_list ap)
290    __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 0)));
291extern int adb_fprintf(FILE *stream, const char *format, ...)
292    __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3)));
293extern int adb_printf(const char *format, ...)
294    __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 1, 2)));
295
296extern int adb_fputs(const char* buf, FILE* stream);
297extern int adb_fputc(int ch, FILE* stream);
298extern size_t adb_fwrite(const void* ptr, size_t size, size_t nmemb,
299                         FILE* stream);
300
301extern FILE* adb_fopen(const char* f, const char* m);
302
303extern char* adb_getenv(const char* name);
304
305extern char* adb_getcwd(char* buf, int size);
306
307// Remap calls to POSIX APIs to our UTF-8 versions.
308#define opendir adb_opendir
309#define readdir adb_readdir
310#define closedir adb_closedir
311#define rewinddir rewinddir_utf8_not_yet_implemented
312#define telldir telldir_utf8_not_yet_implemented
313// Some compiler's C++ headers have members named seekdir, so we can't do the
314// macro technique and instead cause a link error if seekdir is called.
315inline void seekdir(DIR*, long) {
316    extern int seekdir_utf8_not_yet_implemented;
317    seekdir_utf8_not_yet_implemented = 1;
318}
319
320#define utime adb_utime
321#define chmod adb_chmod
322
323#define vfprintf adb_vfprintf
324#define fprintf adb_fprintf
325#define printf adb_printf
326#define fputs adb_fputs
327#define fputc adb_fputc
328#define fwrite adb_fwrite
329
330#define fopen adb_fopen
331
332#define getenv adb_getenv
333#define putenv putenv_utf8_not_yet_implemented
334#define setenv setenv_utf8_not_yet_implemented
335#define unsetenv unsetenv_utf8_not_yet_implemented
336
337#define getcwd adb_getcwd
338
339char* adb_strerror(int err);
340#define strerror adb_strerror
341
342// Helper class to convert UTF-16 argv from wmain() to UTF-8 args that can be
343// passed to main().
344class NarrowArgs {
345public:
346    NarrowArgs(int argc, wchar_t** argv);
347    ~NarrowArgs();
348
349    inline char** data() {
350        return narrow_args;
351    }
352
353private:
354    char** narrow_args;
355};
356
357// Windows HANDLE values only use 32-bits of the type, even on 64-bit machines,
358// so they can fit in an int. To convert back, we just need to sign-extend.
359// https://msdn.microsoft.com/en-us/library/windows/desktop/aa384203%28v=vs.85%29.aspx
360// Note that this does not make a HANDLE value work with APIs like open(), nor
361// does this make a value from open() passable to APIs taking a HANDLE. This
362// just lets you take a HANDLE, pass it around as an int, and then use it again
363// as a HANDLE.
364inline int cast_handle_to_int(const HANDLE h) {
365    // truncate
366    return static_cast<int>(reinterpret_cast<INT_PTR>(h));
367}
368
369inline HANDLE cast_int_to_handle(const int fd) {
370    // sign-extend
371    return reinterpret_cast<HANDLE>(static_cast<INT_PTR>(fd));
372}
373
374// Deleter for unique_handle. Adapted from many sources, including:
375// http://stackoverflow.com/questions/14841396/stdunique-ptr-deleters-and-the-win32-api
376// https://visualstudiomagazine.com/articles/2013/09/01/get-a-handle-on-the-windows-api.aspx
377class handle_deleter {
378public:
379    typedef HANDLE pointer;
380
381    void operator()(HANDLE h);
382};
383
384// Like std::unique_ptr, but for Windows HANDLE objects that should be
385// CloseHandle()'d. Operator bool() only checks if the handle != nullptr,
386// but does not check if the handle != INVALID_HANDLE_VALUE.
387typedef std::unique_ptr<HANDLE, handle_deleter> unique_handle;
388
389#else /* !_WIN32 a.k.a. Unix */
390
391#include "fdevent.h"
392#include <cutils/misc.h>
393#include <cutils/sockets.h>
394#include <cutils/threads.h>
395#include <signal.h>
396#include <sys/wait.h>
397#include <sys/stat.h>
398#include <fcntl.h>
399
400#include <pthread.h>
401#include <unistd.h>
402#include <fcntl.h>
403#include <stdarg.h>
404#include <netdb.h>
405#include <netinet/in.h>
406#include <netinet/tcp.h>
407#include <string.h>
408#include <unistd.h>
409
410#include <string>
411
412#define OS_PATH_SEPARATORS "/"
413#define OS_PATH_SEPARATOR '/'
414#define OS_PATH_SEPARATOR_STR "/"
415#define ENV_PATH_SEPARATOR_STR ":"
416
417static __inline__ bool adb_is_separator(char c) {
418    return c == '/';
419}
420
421typedef  pthread_mutex_t          adb_mutex_t;
422
423#define  ADB_MUTEX_INITIALIZER    PTHREAD_MUTEX_INITIALIZER
424#define  adb_mutex_init           pthread_mutex_init
425#define  adb_mutex_lock           pthread_mutex_lock
426#define  adb_mutex_unlock         pthread_mutex_unlock
427#define  adb_mutex_destroy        pthread_mutex_destroy
428
429#define  ADB_MUTEX_DEFINE(m)      adb_mutex_t   m = PTHREAD_MUTEX_INITIALIZER
430
431#define  adb_cond_t               pthread_cond_t
432#define  adb_cond_init            pthread_cond_init
433#define  adb_cond_wait            pthread_cond_wait
434#define  adb_cond_broadcast       pthread_cond_broadcast
435#define  adb_cond_signal          pthread_cond_signal
436#define  adb_cond_destroy         pthread_cond_destroy
437
438/* declare all mutexes */
439#define  ADB_MUTEX(x)   extern adb_mutex_t  x;
440#include "mutex_list.h"
441
442static __inline__ void  close_on_exec(int  fd)
443{
444    fcntl( fd, F_SETFD, FD_CLOEXEC );
445}
446
447// Open a file and return a file descriptor that may be used with unix_read(),
448// unix_write(), unix_close(), but not adb_read(), adb_write(), adb_close().
449//
450// On Unix, this is based on open(), so the file descriptor is a real OS file
451// descriptor, but the Windows implementation (in sysdeps_win32.cpp) returns a
452// file descriptor that can only be used with C Runtime APIs (which are wrapped
453// by unix_read(), unix_write(), unix_close()). Also, the C Runtime has
454// configurable CR/LF translation which defaults to text mode, but is settable
455// with _setmode().
456static __inline__ int  unix_open(const char*  path, int options,...)
457{
458    if ((options & O_CREAT) == 0)
459    {
460        return  TEMP_FAILURE_RETRY( open(path, options) );
461    }
462    else
463    {
464        int      mode;
465        va_list  args;
466        va_start( args, options );
467        mode = va_arg( args, int );
468        va_end( args );
469        return TEMP_FAILURE_RETRY( open( path, options, mode ) );
470    }
471}
472
473// Similar to the two-argument adb_open(), but takes a mode parameter for file
474// creation. See adb_open() for more info.
475static __inline__ int  adb_open_mode( const char*  pathname, int  options, int  mode )
476{
477    return TEMP_FAILURE_RETRY( open( pathname, options, mode ) );
478}
479
480
481// Open a file and return a file descriptor that may be used with adb_read(),
482// adb_write(), adb_close(), but not unix_read(), unix_write(), unix_close().
483//
484// On Unix, this is based on open(), but the Windows implementation (in
485// sysdeps_win32.cpp) uses Windows native file I/O and bypasses the C Runtime
486// and its CR/LF translation. The returned file descriptor should be used with
487// adb_read(), adb_write(), adb_close(), etc.
488static __inline__ int  adb_open( const char*  pathname, int  options )
489{
490    int  fd = TEMP_FAILURE_RETRY( open( pathname, options ) );
491    if (fd < 0)
492        return -1;
493    close_on_exec( fd );
494    return fd;
495}
496#undef   open
497#define  open    ___xxx_open
498
499static __inline__ int  adb_shutdown(int fd)
500{
501    return shutdown(fd, SHUT_RDWR);
502}
503static __inline__ int  adb_shutdown(int fd, int direction)
504{
505    return shutdown(fd, direction);
506}
507#undef   shutdown
508#define  shutdown   ____xxx_shutdown
509
510// Closes a file descriptor that came from adb_open() or adb_open_mode(), but
511// not designed to take a file descriptor from unix_open(). See the comments
512// for adb_open() for more info.
513static __inline__ int  adb_close(int fd)
514{
515    return close(fd);
516}
517#undef   close
518#define  close   ____xxx_close
519
520
521static __inline__  int  adb_read(int  fd, void*  buf, size_t  len)
522{
523    return TEMP_FAILURE_RETRY( read( fd, buf, len ) );
524}
525
526// Like unix_read(), but does not handle EINTR.
527static __inline__ int unix_read_interruptible(int fd, void* buf, size_t len) {
528    return read(fd, buf, len);
529}
530
531#undef   read
532#define  read  ___xxx_read
533
534static __inline__  int  adb_write(int  fd, const void*  buf, size_t  len)
535{
536    return TEMP_FAILURE_RETRY( write( fd, buf, len ) );
537}
538#undef   write
539#define  write  ___xxx_write
540
541static __inline__ int   adb_lseek(int  fd, int  pos, int  where)
542{
543    return lseek(fd, pos, where);
544}
545#undef   lseek
546#define  lseek   ___xxx_lseek
547
548static __inline__  int    adb_unlink(const char*  path)
549{
550    return  unlink(path);
551}
552#undef  unlink
553#define unlink  ___xxx_unlink
554
555static __inline__  int  adb_creat(const char*  path, int  mode)
556{
557    int  fd = TEMP_FAILURE_RETRY( creat( path, mode ) );
558
559    if ( fd < 0 )
560        return -1;
561
562    close_on_exec(fd);
563    return fd;
564}
565#undef   creat
566#define  creat  ___xxx_creat
567
568static __inline__ int unix_isatty(int fd) {
569    return isatty(fd);
570}
571#define  isatty  ___xxx_isatty
572
573// Helper for network_* functions.
574inline int _fd_set_error_str(int fd, std::string* error) {
575  if (fd == -1) {
576    *error = strerror(errno);
577  }
578  return fd;
579}
580
581inline int network_loopback_client(int port, int type, std::string* error) {
582  return _fd_set_error_str(socket_loopback_client(port, type), error);
583}
584
585inline int network_loopback_server(int port, int type, std::string* error) {
586  return _fd_set_error_str(socket_loopback_server(port, type), error);
587}
588
589inline int network_inaddr_any_server(int port, int type, std::string* error) {
590  return _fd_set_error_str(socket_inaddr_any_server(port, type), error);
591}
592
593inline int network_local_server(const char *name, int namespace_id, int type,
594                                std::string* error) {
595  return _fd_set_error_str(socket_local_server(name, namespace_id, type),
596                           error);
597}
598
599inline int network_connect(const std::string& host, int port, int type,
600                           int timeout, std::string* error) {
601  int getaddrinfo_error = 0;
602  int fd = socket_network_client_timeout(host.c_str(), port, type, timeout,
603                                         &getaddrinfo_error);
604  if (fd != -1) {
605    return fd;
606  }
607  if (getaddrinfo_error != 0) {
608    *error = gai_strerror(getaddrinfo_error);
609  } else {
610    *error = strerror(errno);
611  }
612  return -1;
613}
614
615static __inline__ int  adb_socket_accept(int  serverfd, struct sockaddr*  addr, socklen_t  *addrlen)
616{
617    int fd;
618
619    fd = TEMP_FAILURE_RETRY( accept( serverfd, addr, addrlen ) );
620    if (fd >= 0)
621        close_on_exec(fd);
622
623    return fd;
624}
625
626#undef   accept
627#define  accept  ___xxx_accept
628
629// Operate on a file descriptor returned from unix_open() or a well-known file
630// descriptor such as STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO.
631//
632// On Unix, unix_read(), unix_write(), unix_close() map to adb_read(),
633// adb_write(), adb_close() (which all map to Unix system calls), but the
634// Windows implementations (in the ifdef above and in sysdeps_win32.cpp) call
635// into the C Runtime and its configurable CR/LF translation (which is settable
636// via _setmode()).
637#define  unix_read   adb_read
638#define  unix_write  adb_write
639#define  unix_close  adb_close
640
641typedef void*  (*adb_thread_func_t)( void*  arg );
642
643static __inline__ bool adb_thread_create(adb_thread_func_t start, void* arg) {
644    pthread_attr_t attr;
645    pthread_attr_init(&attr);
646    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
647
648    pthread_t thread;
649    errno = pthread_create(&thread, &attr, start, arg);
650    return (errno == 0);
651}
652
653static __inline__ int adb_thread_setname(const std::string& name) {
654#ifdef __APPLE__
655    return pthread_setname_np(name.c_str());
656#else
657    const char *s = name.c_str();
658
659    // pthread_setname_np fails rather than truncating long strings.
660    const int max_task_comm_len = 16; // including the null terminator
661    if (name.length() > (max_task_comm_len - 1)) {
662        char buf[max_task_comm_len];
663        strncpy(buf, name.c_str(), sizeof(buf) - 1);
664        buf[sizeof(buf) - 1] = '\0';
665        s = buf;
666    }
667
668    return pthread_setname_np(pthread_self(), s) ;
669#endif
670}
671
672static __inline__ int  adb_setsockopt( int  fd, int  level, int  optname, const void*  optval, socklen_t  optlen )
673{
674    return setsockopt( fd, level, optname, optval, optlen );
675}
676
677#undef   setsockopt
678#define  setsockopt  ___xxx_setsockopt
679
680static __inline__ int  unix_socketpair( int  d, int  type, int  protocol, int sv[2] )
681{
682    return socketpair( d, type, protocol, sv );
683}
684
685static __inline__ int  adb_socketpair( int  sv[2] )
686{
687    int  rc;
688
689    rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv );
690    if (rc < 0)
691        return -1;
692
693    close_on_exec( sv[0] );
694    close_on_exec( sv[1] );
695    return 0;
696}
697
698#undef   socketpair
699#define  socketpair   ___xxx_socketpair
700
701static __inline__ void  adb_sleep_ms( int  mseconds )
702{
703    usleep( mseconds*1000 );
704}
705
706static __inline__ int  adb_mkdir(const std::string& path, int mode)
707{
708    return mkdir(path.c_str(), mode);
709}
710
711#undef   mkdir
712#define  mkdir  ___xxx_mkdir
713
714static __inline__ void  adb_sysdeps_init(void)
715{
716}
717
718static __inline__ int adb_is_absolute_host_path(const char* path) {
719    return path[0] == '/';
720}
721
722static __inline__ unsigned long adb_thread_id()
723{
724    return (unsigned long)gettid();
725}
726
727#endif /* !_WIN32 */
728
729static inline void disable_tcp_nagle(int fd) {
730    int off = 1;
731    adb_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &off, sizeof(off));
732}
733
734#endif /* _ADB_SYSDEPS_H */
735