From 2d238fd9871687b1557f15b8878a6cf3e9634b57 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 25 Mar 2011 10:34:47 +0100 Subject: Add 'emulator' launcher program. This patch renames the current ARM-specific emulator binary to 'emulator-arm' and introduces a new tiny (less than 20KB) 'emulator' launcher program. The role of 'emulator' is to launch either 'emulator-arm' or 'emulator-x86' based on the target AVD or platform build being used. This program will be replaced in the future by what is currently known as 'emulator-ui', but is a good placeholder until this work is completed. + Move some utility functions from android/avd/info.[hc] to android/avd/util.[hc] so that 'emulator' can use them directly. IMPORTANT: For platform builds, the target architecture is detected automatically by parsing the build.prop file. For SDK AVDs however, there is no easy way to determine the target architecture, so the patch adds a new hw.cpu.arch property which can have value 'arm' or 'x86' Change-Id: I0084c196695a75c8b9230ba716b3cd2e12610ded --- android/utils/path.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++--- android/utils/path.h | 9 ++++++ 2 files changed, 91 insertions(+), 4 deletions(-) (limited to 'android/utils') diff --git a/android/utils/path.c b/android/utils/path.c index e7ef2b0..f64e517 100644 --- a/android/utils/path.c +++ b/android/utils/path.c @@ -265,6 +265,14 @@ path_can_write( const char* path ) return (ret == 0); } +ABool +path_can_exec( const char* path ) +{ + int ret; + CHECKED(ret, access(path, X_OK)); + return (ret == 0); +} + /* try to make a directory. returns 0 on success, -1 on failure * (error code in errno) */ APosixStatus @@ -325,7 +333,7 @@ path_mkdir_recursive( char* path, unsigned len, int mode ) return ret; } -/* ensure that a given directory exists, create it if not, +/* ensure that a given directory exists, create it if not, 0 on success, -1 on failure (error code in errno) */ APosixStatus path_mkdir_if_needed( const char* path, int mode ) @@ -363,9 +371,9 @@ path_get_size( const char* path, uint64_t *psize ) /* result in getting the size of a different file */ LARGE_INTEGER size; HANDLE file = CreateFile( /* lpFilename */ path, - /* dwDesiredAccess */ GENERIC_READ, - /* dwSharedMode */ FILE_SHARE_READ|FILE_SHARE_WRITE, - /* lpSecurityAttributes */ NULL, + /* dwDesiredAccess */ GENERIC_READ, + /* dwSharedMode */ FILE_SHARE_READ|FILE_SHARE_WRITE, + /* lpSecurityAttributes */ NULL, /* dwCreationDisposition */ OPEN_EXISTING, /* dwFlagsAndAttributes */ 0, /* hTemplateFile */ NULL ); @@ -564,3 +572,73 @@ path_load_file(const char *fn, size_t *pSize) return NULL; } +#ifdef _WIN32 +# define DIR_SEP ';' +#else +# define DIR_SEP ':' +#endif + +char* +path_search_exec( const char* filename ) +{ + const char* sysPath = getenv("PATH"); + char temp[PATH_MAX]; + int count; + int slen; + const char* p; + + /* If the file contains a directory separator, don't search */ +#ifdef _WIN32 + if (strchr(filename, '/') != NULL || strchr(filename, '\\') != NULL) { +#else + if (strchr(filename, '/') != NULL) { +#endif + if (path_exists(filename)) { + return strdup(filename); + } else { + return NULL; + } + } + + /* If system path is empty, don't search */ + if (sysPath == NULL || sysPath[0] == '\0') { + return NULL; + } + + /* Count the number of non-empty items in the system path + * Items are separated by DIR_SEP, and two successive separators + * correspond to an empty item that will be ignored. + * Also compute the required string storage length. */ + count = 0; + slen = 0; + p = sysPath; + + while (*p) { + char* p2 = strchr(p, DIR_SEP); + int len; + if (p2 == NULL) { + len = strlen(p); + } else { + len = p2 - p; + } + + do { + if (len <= 0) + break; + + snprintf(temp, sizeof(temp), "%.*s/%s", len, p, filename); + + if (path_exists(temp) && path_can_exec(temp)) { + return strdup(temp); + } + + } while (0); + + p += len; + if (*p == DIR_SEP) + p++; + } + + /* Nothing, really */ + return NULL; +} diff --git a/android/utils/path.h b/android/utils/path.h index e15e6ed..419e6bf 100644 --- a/android/utils/path.h +++ b/android/utils/path.h @@ -64,6 +64,9 @@ extern ABool path_is_absolute( const char* path ); extern ABool path_can_read( const char* path ); extern ABool path_can_write( const char* path ); +/* checks that one can execute a given file */ +extern ABool path_can_exec( const char* path ); + /* try to make a directory */ extern APosixStatus path_mkdir( const char* path, int mode ); @@ -109,6 +112,12 @@ extern char* path_dirname( const char* path ); */ extern char* path_basename( const char* path ); +/* look for a given executable in the system path and return its full path. + * Returns NULL if not found. Note that on Windows this doesn't not append + * an .exe prefix, or other magical thing like Cygwin usually does. + */ +extern char* path_search_exec( const char* filename ); + /** OTHER FILE UTILITIES ** ** path_empty_file() creates an empty file at a given path location. -- cgit v1.1