]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Allow certain libraries compile on Android & iOS.
authorVMware, Inc <>
Tue, 13 Mar 2012 19:58:31 +0000 (12:58 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Tue, 13 Mar 2012 22:42:50 +0000 (15:42 -0700)
Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
19 files changed:
open-vm-tools/lib/err/errPosix.c
open-vm-tools/lib/file/fileIOPosix.c
open-vm-tools/lib/file/fileInt.h
open-vm-tools/lib/file/filePosix.c
open-vm-tools/lib/include/memaligned.h
open-vm-tools/lib/include/posix.h
open-vm-tools/lib/include/sigPosixRegs.h
open-vm-tools/lib/misc/codesetOld.c
open-vm-tools/lib/misc/hostinfoPosix.c
open-vm-tools/lib/misc/idLinux.c
open-vm-tools/lib/misc/machineID.c
open-vm-tools/lib/misc/msgfmt.c
open-vm-tools/lib/misc/posixPosix.c
open-vm-tools/lib/misc/utilMem.c
open-vm-tools/lib/misc/util_misc.c
open-vm-tools/lib/misc/vthreadBase.c
open-vm-tools/lib/string/bsd_output_shared.c
open-vm-tools/lib/string/bsd_vsnprintf.c
open-vm-tools/lib/user/util.c

index 73302a8cb6784269c62eb29c980f14d1b5f71044..fde8ff6f1e39b519472951e45ccb8ab8ff92b294 100644 (file)
@@ -63,7 +63,7 @@ ErrErrno2String(Err_Number errorNumber, // IN
 {
    char *p;
 
-#if defined(linux)
+#if defined(linux) && !defined(N_PLAT_NLM) && !defined(__ANDROID__)
    p = strerror_r(errorNumber, buf, bufSize);
 #else
    p = strerror(errorNumber);
index 9b2ba5d2b63329205beb7e544e7334802bb1141c..98270648123d02f255c9572af72ad61d4b48014d 100644 (file)
  * These headers are needed to get __USE_LARGEFILE, __USE_LARGEFILE64,
  * and SYS__llseek.
  */
+#   ifdef ANDROID_X86
+#      undef _GNU_SOURCE
+#   endif
 #   include <features.h>
+#   ifndef _GNU_SOURCE
+#      define _GNU_SOURCE
+#   endif
 #   include <linux/unistd.h>
+#ifdef ANDROID_X86
+#   include <sys/syscall.h>
+#else
 #   include <syscall.h>
 #endif
+#endif
+#if defined __ANDROID__
+#   include <sys/syscall.h>
+#endif
 #include <sys/stat.h>
 #include "su.h"
 
@@ -1856,8 +1869,15 @@ FileIO_Pwritev(FileIODescriptor *fd,   // IN: File descriptor
             goto exit;
          }
          if (retval < leftToWrite) {
-            LOG_ONCE((LGPFX" %s wrote %"FMTSZ"d out of %"FMTSZ"u bytes.\n",
-                      __FUNCTION__, retval, leftToWrite));
+            /*
+             * Using %zd on Android generated a warning about
+             * expecting a "signed size_t" argument; casting retval to
+             * "signed size_t" generated an error, though. We've
+             * already checked for retval == -1 above, so the cast
+             * below should be OK. Refer to bug 817761.
+             */
+            LOG_ONCE((LGPFX" %s wrote %"FMTSZ"u out of %"FMTSZ"u bytes.\n",
+                      __FUNCTION__, (size_t)retval, leftToWrite));
          }
 
          buf += retval;
index 37809f0691f231f983ca532c18dcdb04cb391528..16c2dabb57cf4ced880c4c45ad8bbd5d26160368 100644 (file)
@@ -42,7 +42,7 @@
  * think once more.
  */
 
-#define ADFS_SUPER_MAGIC      0xADF5
+#define ADFS_SUPER_MAGIC      0xadf5
 #define AFFS_SUPER_MAGIC      0xADFF
 #define EXT_SUPER_MAGIC       0x137D
 #define EXT2_OLD_SUPER_MAGIC  0xEF51
 #define NFS_SUPER_MAGIC       0x6969
 #define SMB_SUPER_MAGIC       0x517B
 #define ISOFS_SUPER_MAGIC     0x9660
-#define JFFS2_SUPER_MAGIC     0x72B6
-#define PROC_SUPER_MAGIC      0x9FA0
-#define OPENPROM_SUPER_MAGIC  0x9FA1
-#define USBDEVICE_SUPER_MAGIC 0x9FA2
+#define JFFS2_SUPER_MAGIC     0x72b6
+#define PROC_SUPER_MAGIC      0x9fa0
+#define OPENPROM_SUPER_MAGIC  0x9fa1
+#define USBDEVICE_SUPER_MAGIC 0x9fa2
 #define AUTOFS_SUPER_MAGIC    0x0187
 
 #if !defined(MSDOS_SUPER_MAGIC)
@@ -71,7 +71,7 @@
 #define XFS_SUPER_MAGIC       0x58465342
 #define VMFS_SUPER_MAGIC      0x2fABF15E
 #define TMPFS_SUPER_MAGIC     0x01021994
-#define JFS_SUPER_MAGIC       0x3153464A
+#define JFS_SUPER_MAGIC       0x3153464a
 #define AFS_SUPER_MAGIC       0x5346414F
 #define CIFS_SUPER_MAGIC      0xFF534D42
 
index 6c28288671f5ad776bf1c6ef81d711231edb7049..31a77e9faf136bb5a922be924803ca5585c079ad 100644 (file)
@@ -39,9 +39,6 @@
 #  include <sys/mount.h>
 # else
 #  include <mntent.h>
-#  if defined __ANDROID__
-#   include <paths.h> /* for _PATH_MOUNTED */
-#  endif
 # endif
 #include <signal.h>
 #endif
@@ -99,7 +96,7 @@ static char *FilePosixNearestExistingAncestor(char const *path);
  * happens the prosix version should be updated to use the generic code.
  */
 
-#if defined(__USE_FILE_OFFSET64) || defined(sun)
+#if defined(__USE_FILE_OFFSET64) || defined(sun) || defined(__ANDROID__)
 # define CAN_USE_FTS 0
 #else
 # define CAN_USE_FTS 1
@@ -120,6 +117,14 @@ struct WalkDirContextImpl
 /* A string for VMFS on ESX file system type */
 #define FS_VMFS_ON_ESX "VMFS"
 
+#if defined __ANDROID__
+/*
+ * Android doesn't support setmntent(), endmntent() or MOUNTED.
+ */
+#define NO_SETMNTENT
+#define NO_ENDMNTENT
+#endif
+
 
 /*
  *-----------------------------------------------------------------------------
@@ -726,6 +731,23 @@ File_GetTimes(ConstUnicode pathName,       // IN:
       timeBuf.tv_nsec = statBuf.__unused3;
       *attrChangeTime = TimeUtil_UnixTimeToNtTime(timeBuf);
    }
+#   elif defined(ANDROID_X86)
+   {
+      struct timespec timeBuf;
+
+      timeBuf.tv_sec  = statBuf.st_atime;
+      timeBuf.tv_nsec = statBuf.st_atime_nsec;
+      *accessTime     = TimeUtil_UnixTimeToNtTime(timeBuf);
+
+
+      timeBuf.tv_sec  = statBuf.st_mtime;
+      timeBuf.tv_nsec = statBuf.st_mtime_nsec;
+      *writeTime      = TimeUtil_UnixTimeToNtTime(timeBuf);
+
+      timeBuf.tv_sec  = statBuf.st_ctime;
+      timeBuf.tv_nsec = statBuf.st_ctime_nsec;
+      *attrChangeTime = TimeUtil_UnixTimeToNtTime(timeBuf);
+   }
 #   else
    *accessTime     = TimeUtil_UnixTimeToNtTime(statBuf.st_atim);
    *writeTime      = TimeUtil_UnixTimeToNtTime(statBuf.st_mtim);
@@ -1494,6 +1516,11 @@ static char *
 FilePosixLookupMountPoint(char const *canPath,  // IN: Canonical file path
                           Bool *bind)           // OUT: Mounted with --[r]bind?
 {
+#if defined NO_SETMNTENT || defined NO_ENDMNTENT
+   NOT_IMPLEMENTED();
+   errno = ENOSYS;
+   return NULL;
+#else
    FILE *f;
    struct mntent mnt;
    char *buf;
@@ -1507,16 +1534,7 @@ FilePosixLookupMountPoint(char const *canPath,  // IN: Canonical file path
    size = 4 * FILE_MAXPATH;  // Should suffice for most locales
 
 retry:
-#if defined __ANDROID__
-   /*
-    * Android supports neither setmntent() nor MOUNTED.
-    * The code below is a workaround.
-    */
-   NOT_TESTED();
-   f = fopen(_PATH_MOUNTED, "r");
-#else
    f = setmntent(MOUNTED, "r");
-#endif
    if (f == NULL) {
       return NULL;
    }
@@ -1569,7 +1587,7 @@ retry:
 
       if (strcmp(mnt.mnt_dir, canPath) == 0) {
          /*
-          * The --bind and --rbind options behave differently. See 
+          * The --bind and --rbind options behave differently. See
           * FilePosixGetBlockDevice() for details.
           *
           * Sadly (I blame a bug in 'mount'), there is no way to tell them
@@ -1591,6 +1609,7 @@ retry:
    free(buf);
 
    return ret;
+#endif
 }
 #endif
 
index a784e56dffb5836e10ce461b70ff75e8e0f1e972..0044f3259e9b0a552bda6c945ca675f2e08bd6ae 100644 (file)
@@ -75,6 +75,7 @@ AlignedMallocImpl(size_t size) // IN
    void **buf;
    void **alignedResult;
 
+#undef PAGE_MASK
 #define PAGE_MASK (PAGE_SIZE - 1)
 #define PAGE_ROUND_DOWN(_value) ((uintptr_t)(_value) & ~PAGE_MASK)
 #define PAGE_ROUND_UP(_value) PAGE_ROUND_DOWN((uintptr_t)(_value) + PAGE_MASK)
index 13b7fa18314cd69768fbf4a06c3b33edba46cdc1..dd3d7b4490f36aee50ae14cfd3b2ce388753381c 100644 (file)
@@ -43,7 +43,7 @@
  * leading to a (potentially undetected) mismatch.
  */
 
-#if defined(linux) && \
+#if defined(linux) && !defined(ANDROID_X86) && \
     (!defined(_LARGEFILE64_SOURCE) || _FILE_OFFSET_BITS != 64)
 #error LFS support is not enabled!
 #endif
index 29cf1fe80dc26d61064d54930f771f0aee226b2f..81d7352b469f183c78a2ba8c39a001b52b8332df 100644 (file)
@@ -69,7 +69,9 @@
 #endif
 
 #include <signal.h>
+#ifndef __ANDROID__
 #include <sys/ucontext.h>
+#endif
 
 #if __linux__
 #  if defined(__x86_64__)
 #define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[ESP])
 #define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[EIP])
 #endif
+#elif defined(ANDROID_X86)
+#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.eax)
+#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.ebx)
+#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.ecx)
+#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.edx)
+#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.edi)
+#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.esi)
+#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.ebp)
+#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.esp)
+#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.eip)
 #else
 #ifdef __x86_64__
 #define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RAX])
index b56614a7f76a401c6254b7f7221daefdbc9ff5fa..dc05e17444ac2e44021c2a17762be40a25f50b5b 100644 (file)
@@ -81,6 +81,25 @@ static Bool CodeSetOldIso88591ToUtf8Db(char const *bufIn, size_t sizeIn,
                                        unsigned int flags, DynBuf *db);
 #endif
 
+#if defined __ANDROID__
+#include "vm_basic_asm.h"
+/*
+ * Android doesn't have swab().
+ */
+void
+swab(const void *__restrict src,  // IN/OUT
+     void *__restrict dest,       // IN/OUT
+     ssize_t nbytes)              // IN
+{
+   const uint16 *p = src;
+   uint16 *q = dest;
+   ssize_t i;
+
+   for (i = 0; i < nbytes / sizeof(*p); i++) {
+      q[i] = Bswap16(p[i]);
+   }
+}
+#endif
 
 #if defined(CURRENT_IS_UTF8) || defined(_WIN32)
 /*
index 3a81092a601aa4472c8bed75e278cadbfa9cad72..f8e97d53fb1b974ac87dc1c4784c345456887004 100644 (file)
 #if !defined(USING_AUTOCONF) || defined(HAVE_SYS_VFS_H)
 #include <sys/vfs.h>
 #endif
-#if !defined(sun) && (!defined(USING_AUTOCONF) || (defined(HAVE_SYS_IO_H) && defined(HAVE_SYS_SYSINFO_H)))
-# ifndef __ANDROID__
-# include <sys/io.h>
-# endif
+#if !defined(sun) && !defined __ANDROID__ && (!defined(USING_AUTOCONF) || (defined(HAVE_SYS_IO_H) && defined(HAVE_SYS_SYSINFO_H)))
+#include <sys/io.h>
 #include <sys/sysinfo.h>
 #ifndef HAVE_SYSINFO
 #define HAVE_SYSINFO 1
@@ -204,6 +202,14 @@ static const DistroInfo distroArray[] = {
    {NULL, NULL},
 };
 
+#if defined __ANDROID__
+/*
+ * Android doesn't support getloadavg() or iopl().
+ */
+#define NO_GETLOADAVG
+#define NO_IOPL
+#endif
+
 
 /*
  *----------------------------------------------------------------------
@@ -1417,7 +1423,7 @@ HostinfoGetLoadAverage(float *avg0,  // IN/OUT:
                        float *avg1,  // IN/OUT:
                        float *avg2)  // IN/OUT:
 {
-#if (defined(__linux__) && !defined(__UCLIBC__)) || defined(__APPLE__)
+#if !defined(NO_GETLOADAVG) && (defined(__linux__) && !defined(__UCLIBC__)) || defined(__APPLE__)
    double avg[3];
    int res;
 
@@ -1871,7 +1877,12 @@ Hostinfo_ResetProcessState(const int *keepFds, // IN:
          privileges --hpreg */
       ASSERT(euid != 0 || getuid() == 0);
       Id_SetEUid(0);
+#if defined NO_IOPL
+      NOT_IMPLEMENTED();
+      errno = ENOSYS;
+#else
       err = iopl(0);
+#endif
       Id_SetEUid(euid);
       ASSERT_NOT_IMPLEMENTED(err == 0);
    }
index a4e09070d94e3dd08b29207855c89cddcd8bb660..f6e93ead8c296a33bebf68a71be5680a7e6eca34 100644 (file)
 #include <unistd.h>
 #ifdef __APPLE__
 #include <sys/socket.h>
+#include <TargetConditionals.h>
+#if !defined TARGET_OS_IPHONE
+#define TARGET_OS_IPHONE 0
+#endif
+#if !TARGET_OS_IPHONE
 #include <Security/Authorization.h>
 #include <Security/AuthorizationTags.h>
 #endif
+#endif
 #if defined __ANDROID__
 #include <syscall-android.h>
 #endif
@@ -74,7 +80,7 @@ static int uid32 = 1;
 #endif
 #endif // __linux__
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !TARGET_OS_IPHONE
 #include <sys/kauth.h>
 
 static AuthorizationRef IdAuthCreate(void);
@@ -338,7 +344,7 @@ Id_SetREGid(gid_t gid,              // IN: new gid
 #endif
 
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !TARGET_OS_IPHONE
 /*
  *----------------------------------------------------------------------------
  *
@@ -842,7 +848,11 @@ Id_BeginSuperUser(void)
       uid = (uid_t) -1; // already root; nothing to do
    } else {
 #if defined(__APPLE__)
+#if TARGET_OS_IPHONE
+      Warning("XXXIOS: implement %s\n", __func__);
+#else
       syscall(SYS_settid, KAUTH_UID_NONE, KAUTH_GID_NONE /* Ignored. */);
+#endif
 #else
       Id_SetRESUid((uid_t) -1, (uid_t) 0, (uid_t) -1); // effectively root
 #endif
index a51e64ef2ab9c896c12be8e8347b20ba437126c1..392a51221ff9ca003eceffb37c45a2023dba335b 100644 (file)
@@ -361,11 +361,14 @@ ObtainHardwareID(uint64 *hardwareID)  // OUT:
 
    return 0;
 }
-#elif defined(linux)           // Linux
+#elif defined(linux) || defined __ANDROID__
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <net/if.h>
 #include <sys/time.h>
+#if defined __ANDROID__
+#include <sys/socket.h>  // For SOCK_DGRAM etc.
+#endif
 
 
 /*
index 885f66a77fe3073d9611e9835460a814ec2a8f0c..3681b2d096b7098475d632a2d0b1ea8b8504be16 100644 (file)
@@ -175,6 +175,13 @@ memchr(const void *s, int c, size_t n)
 
 #endif // }
 
+#if defined __ANDROID__
+/*
+ * Android doesn't support dtoa().
+ */
+#define NO_DTOA
+#endif
+
 
 /*
  * Local data
@@ -1965,7 +1972,7 @@ MsgFmtSnprintfWork(char **outbuf, size_t bufSize, const char *fmt0,
     */
    char *decimal_point;   /* locale specific decimal point */
 #if defined __ANDROID__
-   static const char dp = '.';
+   static char dp = '.';
 #endif
    int signflag;      /* true if float is negative */
    union {         /* floating point arguments %[aAeEfFgG] */
@@ -2396,9 +2403,17 @@ MsgFmtSnprintfWork(char **outbuf, size_t bufSize, const char *fmt0,
            goto error;
         }
         fparg.dbl = a->v.float64;
+#if defined NO_DTOA
+         NOT_TESTED();
+         dtoaresult = NULL;
+         sbuf.error = TRUE;
+
+         goto error;
+#else
         dtoaresult = cp =
            dtoa(fparg.dbl, expchar ? 2 : 3, prec,
                 &expt, &signflag, &dtoaend);
+#endif
         if (expt == 9999)
            expt = INT_MAX;
          if (signflag)
index 6c0df44f53c2e9ebc96ea0d3bdfe171376487131..b4e3ba5763d6ac2e71c4680b51175175d0cd6820 100644 (file)
@@ -65,7 +65,7 @@
 #include <mntent.h>
 #endif
 
-#if !defined(__FreeBSD__) || __FreeBSD_release >= 503001
+#if (!defined(__FreeBSD__) || __FreeBSD_release >= 503001) && !defined __ANDROID__
 #define VM_SYSTEM_HAS_GETPWNAM_R 1
 #define VM_SYSTEM_HAS_GETPWUID_R 1
 #define VM_SYSTEM_HAS_GETGRNAM_R 1
@@ -89,6 +89,17 @@ static struct passwd *GetpwInternal(struct passwd *pw);
 static int GetpwInternal_r(struct passwd *pw, char *buf, size_t size,
                            struct passwd **ppw);
 
+#if defined __ANDROID__
+/*
+ * Android doesn't support getmntent_r(), getpwent() or setmntent().
+ */
+#define NO_GETMNTENT_R
+#define NO_GETPWENT
+#define NO_SETMNTENT
+
+EXTERN int truncate(const char *, off_t);
+#endif
+
 
 /*
  *----------------------------------------------------------------------
@@ -1911,9 +1922,15 @@ Posix_Unsetenv(ConstUnicode name)  // IN:
 struct passwd *
 Posix_Getpwent(void)
 {
+#if defined NO_GETPWENT
+   NOT_IMPLEMENTED();
+   errno = ENOSYS;
+   return NULL;
+#else
    struct passwd *pw = getpwent();
 
    return GetpwInternal(pw);
+#endif
 }
 
 #if !defined(VM_SYSTEM_HAS_GETPWNAM_R) || \
@@ -2893,6 +2910,11 @@ FILE *
 Posix_Setmntent(ConstUnicode pathName,  // IN:
                 const char *mode)       // IN:
 {
+#if defined NO_SETMNTENT
+   NOT_IMPLEMENTED();
+   errno = ENOSYS;
+   return NULL;
+#else
    char *path;
    FILE *stream;
 
@@ -2901,19 +2923,11 @@ Posix_Setmntent(ConstUnicode pathName,  // IN:
    if (!PosixConvertToCurrent(pathName, &path)) {
       return NULL;
    }
-#if defined __ANDROID__
-   /*
-    * Android doesn't support setmntent().
-    */
-   NOT_TESTED();
-   errno = ENOSYS;
-   return NULL;
-#else
    stream = setmntent(path, mode);
-#endif
    free(path);
 
    return stream;
+#endif
 }
 
 
@@ -3014,11 +3028,8 @@ Posix_Getmntent_r(FILE *fp,          // IN:
                   char *buf,         // IN:
                   int size)          // IN:
 {
-#if defined __ANDROID__
-   /*
-    * Android doesn't support getmntent_r();
-    * using getmntent() will break thread safety.
-    */
+#if defined NO_GETMNTENT_R
+   NOT_IMPLEMENTED();
    errno = ENOSYS;
    return NULL;
 #else
index 5b3410b3233db92ddfd1c84d0b22be714301ffda..d5714ea87150aca22c8f788376ae79f1218302af 100644 (file)
 
 #include "vm_assert.h"
 
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#if !defined TARGET_OS_IPHONE
+#define TARGET_OS_IPHONE 0
+#endif
+#endif
+
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -242,6 +250,7 @@ Util_Memcpy(void *dest,
             const void *src,
             size_t count)
 {
+#if !defined(__ANDROID__) && !defined(TARGET_OS_IPHONE)
    uintptr_t align = ((uintptr_t)dest | (uintptr_t)src | count);
 
 #if defined __GNUC__
@@ -313,6 +322,7 @@ Util_Memcpy(void *dest,
    #endif
 
 
+#endif
 #endif
 
    memcpy(dest, src, count);
index 3a67f341a09f56bd61e2dc061ff2fad72f71eaaf..ecdb885b766726250a24a8852432eb55d623df91 100644 (file)
@@ -400,7 +400,12 @@ Util_GetPrime(unsigned n0)  // IN:
 }
 
 
-#if defined(linux)
+#if defined(linux) && !defined(ANDROID_X86)
+/*
+ * Android x86 has its own gettid. gettid has been declared on
+ * <sys/linux-unistd.h> and defined as an extern function on <unistd.h>.
+ */
+
 /*
  *-----------------------------------------------------------------------------
  *
index 28b23ad3bf2eedaa0fcee2389ea68af539a0d6e2..e938f2ddc73f3cc93394b34953f652773861f4aa 100644 (file)
@@ -119,8 +119,13 @@ typedef DWORD VThreadBaseKeyType;
 #define VTHREADBASE_INVALID_KEY (VThreadBaseKeyType)(TLS_OUT_OF_INDEXES)
 #else
 typedef pthread_key_t VThreadBaseKeyType;
+/* PTHREAD_KEYS_MAX not defined on Android. */
+#if defined __linux__ && !defined PTHREAD_KEYS_MAX
+#define VTHREADBASE_INVALID_KEY (VThreadBaseKeyType)(1024)
+#else
 #define VTHREADBASE_INVALID_KEY (VThreadBaseKeyType)(PTHREAD_KEYS_MAX)
 #endif
+#endif
 
 static void VThreadBaseSimpleNoID(void);
 static void VThreadBaseSimpleFreeID(void *tlsData);
index 1c49262f1453f87e1233cdb878ddb1e69844d424..e0a310be2438222fef13f45c05e2732d50ff9274 100644 (file)
@@ -40,7 +40,7 @@
 
 //#include <sys/cdefs.h>
 
-#if !defined(STR_NO_WIN32_LIBS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
+#if !defined(STR_NO_WIN32_LIBS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__ANDROID__)
 
 #include <stdio.h>
 #include <stdlib.h>
index e3e2ad2e23ec2e3f844d8e281e43589704007b47..9b88f580571810af9b731225de26c1119511b1bc 100644 (file)
 #include "convertutf.h"
 #include "str.h"
 
+
+#if defined __ANDROID__
+/*
+ * Android doesn't support dtoa() or ldtoa().
+ */
+#define NO_DTOA
+#define NO_LDTOA
+#endif
+
 static char   *__ultoa(u_long, char *, int, int, const char *, int, char,
                        const char *);
 static void   __find_arguments(const char *, va_list, union arg **);
@@ -453,6 +462,9 @@ bsd_vsnprintf_core(char **outbuf,
     * D:   expchar holds this character; '\0' if no exponent, e.g. %f
     * F:   at least two digits for decimal, at least one digit for hex
     */
+#if defined __ANDROID__
+   static char dp = '.';
+#endif
    int signflag;      /* true if float is negative */
    union {         /* floating point arguments %[aAeEfFgG] */
       double dbl;
@@ -615,6 +627,15 @@ bsd_vsnprintf_core(char **outbuf,
    convbuf = NULL;
 #if !defined(NO_FLOATING_POINT)
    dtoaresult = NULL;
+#if !defined __ANDROID__
+   decimal_point = localeconv()->decimal_point;
+#else
+   /*
+    * Struct lconv is not working! For decimal_point,
+    * using '.' instead is a workaround.
+    */
+   decimal_point = &dp;
+#endif
 #endif
 
    fmt = (char *)fmt0;
@@ -733,9 +754,15 @@ bsd_vsnprintf_core(char **outbuf,
          goto rflag;
       case '\'':
          flags |= GROUPING;
+#if !defined __ANDROID__
          thousands_sep = thousands_sepIn;
          grouping = groupingIn;
-
+#else
+         /*
+          * Struct lconv is not working! The code below is a workaround.
+          */
+         thousands_sep = ',';
+#endif
         /*
          * Grouping should not begin with 0, but it nevertheless does (see
           * bug 281072) and makes the formatting code behave badly, so we
@@ -901,12 +928,32 @@ bsd_vsnprintf_core(char **outbuf,
          }
          if (flags & LLONGINT) {
             fparg.ldbl = GETARG(long double);
+#if defined NO_LDTOA
+            dtoaresult = NULL;
+            /*
+             * Below is to keep compiler happy
+             */
+            signflag = -1;
+            expt = 0;
+            dtoaend = NULL;
+#else
             dtoaresult = cp = ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec,
                                      &expt, &signflag, &dtoaend);
+#endif
          } else {
             fparg.dbl = GETARG(double);
+#if defined NO_DTOA
+            dtoaresult = NULL;
+            /*
+             * Below is to keep compiler happy
+             */
+            signflag = -1;
+            expt = 0;
+            dtoaend = NULL;
+#else
             dtoaresult = cp = dtoa(fparg.dbl, expchar ? 2 : 3, prec,
                                    &expt, &signflag, &dtoaend);
+#endif
          }
 
          /* Our dtoa / ldtoa call strdup(), which can fail. PR319844 */
index 9ee44f6b726f9dde9cffb34e4a834718a3cf5344..96bc09ff41e845a5782d52bbeddfaa410b48cc0a 100644 (file)
@@ -54,7 +54,7 @@
 #  include <dlfcn.h>
 #endif
 
-#if defined(__linux__) && !defined(VMX86_TOOLS)
+#if defined(__linux__) && !defined(VMX86_TOOLS) && !defined(__ANDROID__)
 #  include <link.h>
 #endif
 
@@ -428,7 +428,7 @@ UtilBacktraceFromPointerCallback(struct _Unwind_Context *ctx, // IN: Unwind cont
    return _URC_END_OF_STACK;
 }
 
-#if !defined(_WIN32) && !defined(VMX86_TOOLS)
+#if !defined(_WIN32) && !defined(VMX86_TOOLS) && !defined(__ANDROID__)
 /*
  *-----------------------------------------------------------------------------
  *
@@ -575,7 +575,7 @@ Util_BacktraceFromPointerWithFunc(uintptr_t *basePtr,
 #elif !defined(VM_X86_64)
    uintptr_t *x = basePtr;
    int i;
-#if !defined(_WIN32) && !defined(VMX86_TOOLS)
+#if !defined(_WIN32) && !defined(VMX86_TOOLS) && !defined(__ANDROID__)
    Dl_info dli;
 #endif
 
@@ -588,7 +588,7 @@ Util_BacktraceFromPointerWithFunc(uintptr_t *basePtr,
       x = (uintptr_t *) x[0];
    }
 
-#if !defined(_WIN32) && !defined(VMX86_TOOLS)
+#if !defined(_WIN32) && !defined(VMX86_TOOLS) && !defined(__ANDROID__)
    /* 
     * We do a separate pass here that includes symbols in order to
     * make sure the base backtrace that does not call dladdr() etc.