From 3e7048c027ffa081d2fea84b661a6da895a9f1fb Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 27 Jul 2015 21:21:39 -0700 Subject: [PATCH] Fix const-ness of strrchr callers. This causes build failures in google3 where they use GCC. glibc only provides const-correct overloads for string functions for GCC >= 4.4, but clang -- which is what we use -- pretends to be GCC 4.2. Change-Id: I2a054823ea6201ebcea46d5e77b80a975eefc622 --- adb/adb_utils.cpp | 11 ++++++----- adb/adb_utils.h | 2 +- adb/commandline.cpp | 8 ++++---- adb/file_sync_service.cpp | 2 +- adb/sysdeps.h | 10 +++++----- adb/usb_linux.cpp | 6 ++---- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp index cd3c7bc6b..6fa6c2e81 100644 --- a/adb/adb_utils.cpp +++ b/adb/adb_utils.cpp @@ -72,16 +72,17 @@ std::string escape_arg(const std::string& s) { return result; } -int mkdirs(const char *path) -{ +int mkdirs(const std::string& path) { + // TODO: rewrite this function and merge it with the *other* mkdirs in adb. + std::unique_ptr path_rw(strdup(path.c_str())); int ret; - char *x = (char *)path + 1; + char* x = path_rw.get() + 1; for(;;) { - x = adb_dirstart(x); + x = const_cast(adb_dirstart(x)); if(x == 0) return 0; *x = 0; - ret = adb_mkdir(path, 0775); + ret = adb_mkdir(path_rw.get(), 0775); *x = OS_PATH_SEPARATOR; if((ret < 0) && (errno != EEXIST)) { return ret; diff --git a/adb/adb_utils.h b/adb/adb_utils.h index d1a3f5f8f..673aaac39 100644 --- a/adb/adb_utils.h +++ b/adb/adb_utils.h @@ -22,7 +22,7 @@ bool getcwd(std::string* cwd); bool directory_exists(const std::string& path); -int mkdirs(const char *path); +int mkdirs(const std::string& path); std::string escape_arg(const std::string& s); diff --git a/adb/commandline.cpp b/adb/commandline.cpp index f19033607..d54faec58 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -487,8 +487,8 @@ static int adb_download_buffer(const char *service, const char *fn, const void* const uint8_t* ptr = reinterpret_cast(data); if (show_progress) { - char *x = strrchr(service, ':'); - if(x) service = x + 1; + const char* x = strrchr(service, ':'); + if (x) service = x + 1; } while (sz > 0) { @@ -1496,7 +1496,7 @@ static int install_app(TransportType transport, const char* serial, int argc, co int last_apk = -1; for (i = argc - 1; i >= 0; i--) { const char* file = argv[i]; - char* dot = strrchr(file, '.'); + const char* dot = strrchr(file, '.'); if (dot && !strcasecmp(dot, ".apk")) { if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) { fprintf(stderr, "Invalid APK file: %s\n", file); @@ -1542,7 +1542,7 @@ static int install_multiple_app(TransportType transport, const char* serial, int int first_apk = -1; for (i = argc - 1; i >= 0; i--) { const char* file = argv[i]; - char* dot = strrchr(file, '.'); + const char* dot = strrchr(file, '.'); if (dot && !strcasecmp(dot, ".apk")) { if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) { fprintf(stderr, "Invalid APK file: %s\n", file); diff --git a/adb/file_sync_service.cpp b/adb/file_sync_service.cpp index e8e9a0f4d..2067836f0 100644 --- a/adb/file_sync_service.cpp +++ b/adb/file_sync_service.cpp @@ -53,7 +53,7 @@ static int mkdirs(char *name) if(name[0] != '/') return -1; for(;;) { - x = adb_dirstart(x); + x = const_cast(adb_dirstart(x)); if(x == 0) return 0; *x = 0; if (should_use_fs_config(name)) { diff --git a/adb/sysdeps.h b/adb/sysdeps.h index 616092399..729bbcb20 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -247,10 +247,10 @@ static __inline__ char* adb_dirstart( const char* path ) return p; } -static __inline__ char* adb_dirstop( const char* path ) +static __inline__ const char* adb_dirstop( const char* path ) { - char* p = strrchr(path, '/'); - char* p2 = strrchr(path, '\\'); + const char* p = strrchr(path, '/'); + const char* p2 = strrchr(path, '\\'); if ( !p ) p = p2; @@ -521,12 +521,12 @@ static __inline__ void adb_sysdeps_init(void) { } -static __inline__ char* adb_dirstart(const char* path) +static __inline__ const char* adb_dirstart(const char* path) { return strchr(path, '/'); } -static __inline__ char* adb_dirstop(const char* path) +static __inline__ const char* adb_dirstop(const char* path) { return strrchr(path, '/'); } diff --git a/adb/usb_linux.cpp b/adb/usb_linux.cpp index e570ef599..dd2271218 100644 --- a/adb/usb_linux.cpp +++ b/adb/usb_linux.cpp @@ -264,14 +264,12 @@ static void find_usb_device(const std::string& base, // Determine the device path if (!fstat(fd, &st) && S_ISCHR(st.st_mode)) { - char *slash; - ssize_t link_len; snprintf(pathbuf, sizeof(pathbuf), "/sys/dev/char/%d:%d", major(st.st_rdev), minor(st.st_rdev)); - link_len = readlink(pathbuf, link, sizeof(link) - 1); + ssize_t link_len = readlink(pathbuf, link, sizeof(link) - 1); if (link_len > 0) { link[link_len] = '\0'; - slash = strrchr(link, '/'); + const char* slash = strrchr(link, '/'); if (slash) { snprintf(pathbuf, sizeof(pathbuf), "usb:%s", slash + 1);