am 5f2ccb0e: Merge "Move adb to C++."

* commit '5f2ccb0efd1331f0137e294bed7a076c472f0ed6':
  Move adb to C++.
This commit is contained in:
Dan Albert 2015-03-10 02:10:00 +00:00 committed by Android Git Automerger
commit 3f4113571f
34 changed files with 317 additions and 278 deletions

View File

@ -17,14 +17,14 @@ ADB_CLANG :=
# small by moving common files into a static library. Hopefully some day we can
# get enough of adb in here that we no longer need minadb. https://b/17626262
LIBADB_SRC_FILES := \
adb.c \
adb_auth.c \
adb.cpp \
adb_auth.cpp \
adb_io.cpp \
adb_listeners.c \
sockets.c \
transport.c \
transport_local.c \
transport_usb.c \
adb_listeners.cpp \
sockets.cpp \
transport.cpp \
transport_local.cpp \
transport_usb.cpp \
LIBADB_CFLAGS := \
-Wall -Werror \
@ -32,9 +32,20 @@ LIBADB_CFLAGS := \
-Wno-missing-field-initializers \
-fvisibility=hidden \
LIBADB_darwin_SRC_FILES := fdevent.cpp get_my_path_darwin.c usb_osx.c
LIBADB_linux_SRC_FILES := fdevent.cpp get_my_path_linux.c usb_linux.c
LIBADB_windows_SRC_FILES := get_my_path_windows.c sysdeps_win32.c usb_windows.c
LIBADB_darwin_SRC_FILES := \
fdevent.cpp \
get_my_path_darwin.c \
usb_osx.c \
LIBADB_linux_SRC_FILES := \
fdevent.cpp \
get_my_path_linux.cpp \
usb_linux.cpp \
LIBADB_windows_SRC_FILES := \
get_my_path_windows.cpp \
sysdeps_win32.c \
usb_windows.cpp \
include $(CLEAR_VARS)
LOCAL_CLANG := $(ADB_CLANG)
@ -42,10 +53,10 @@ LOCAL_MODULE := libadbd
LOCAL_CFLAGS := $(LIBADB_CFLAGS) -DADB_HOST=0
LOCAL_SRC_FILES := \
$(LIBADB_SRC_FILES) \
adb_auth_client.c \
adb_auth_client.cpp \
fdevent.cpp \
jdwp_service.c \
qemu_tracing.c \
jdwp_service.cpp \
qemu_tracing.cpp \
usb_linux_client.c \
include $(BUILD_STATIC_LIBRARY)
@ -57,7 +68,7 @@ LOCAL_CFLAGS := $(LIBADB_CFLAGS) -DADB_HOST=1
LOCAL_SRC_FILES := \
$(LIBADB_SRC_FILES) \
$(LIBADB_$(HOST_OS)_SRC_FILES) \
adb_auth_host.c \
adb_auth_host.cpp \
# Even though we're building a static library (and thus there's no link step for
# this to take effect), this adds the SSL includes to our path.
@ -86,7 +97,7 @@ include $(CLEAR_VARS)
LOCAL_CLANG := $(ADB_CLANG)
LOCAL_MODULE := adb_test
LOCAL_CFLAGS := -DADB_HOST=1 $(LIBADB_CFLAGS)
LOCAL_SRC_FILES := $(LIBADB_TEST_SRCS) services.c
LOCAL_SRC_FILES := $(LIBADB_TEST_SRCS) services.cpp
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_STATIC_LIBRARIES := \
libadb \
@ -126,16 +137,12 @@ endif
LOCAL_CLANG := $(ADB_CLANG)
LOCAL_SRC_FILES := \
adb_main.c \
console.c \
commandline.c \
adb_client.c \
services.c \
file_sync_client.c \
ifneq ($(USE_SYSDEPS_WIN32),)
LOCAL_SRC_FILES += sysdeps_win32.c
endif
adb_main.cpp \
console.cpp \
commandline.cpp \
adb_client.cpp \
services.cpp \
file_sync_client.cpp \
LOCAL_CFLAGS += \
-Wall -Werror \
@ -153,7 +160,7 @@ LOCAL_STATIC_LIBRARIES := \
$(EXTRA_STATIC_LIBS) \
ifeq ($(USE_SYSDEPS_WIN32),)
LOCAL_STATIC_LIBRARIES += libcutils
LOCAL_STATIC_LIBRARIES += libcutils
endif
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
@ -176,19 +183,19 @@ include $(CLEAR_VARS)
LOCAL_CLANG := $(ADB_CLANG)
LOCAL_SRC_FILES := \
adb_main.c \
services.c \
file_sync_service.c \
framebuffer_service.c \
remount_service.c \
set_verity_enable_state_service.c \
adb_main.cpp \
services.cpp \
file_sync_service.cpp \
framebuffer_service.cpp \
remount_service.cpp \
set_verity_enable_state_service.cpp \
LOCAL_CFLAGS := \
-O2 \
-g \
-DADB_HOST=0 \
-D_GNU_SOURCE \
-Wall -Wno-unused-parameter -Werror -Wno-deprecated-declarations \
-DADB_HOST=0 \
-D_GNU_SOURCE \
-Wall -Werror \
-Wno-unused-parameter \
-Wno-deprecated-declarations \
ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
LOCAL_CFLAGS += -DALLOW_ADBD_ROOT=1

View File

@ -140,10 +140,13 @@ void adb_trace_init(void)
}
}
apacket *get_apacket(void)
apacket* get_apacket(void)
{
apacket *p = malloc(sizeof(apacket));
if(p == 0) fatal("failed to allocate an apacket");
apacket* p = reinterpret_cast<apacket*>(malloc(sizeof(apacket)));
if (p == nullptr) {
fatal("failed to allocate an apacket");
}
memset(p, 0, sizeof(apacket) - MAX_PAYLOAD);
return p;
}
@ -293,7 +296,7 @@ void send_connect(atransport *t)
}
#if ADB_HOST
static char *connection_state_name(atransport *t)
static const char* connection_state_name(atransport *t)
{
if (t == NULL) {
return "unknown";
@ -713,8 +716,8 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
// Create the list of forward redirections.
int buffer_size = format_listeners(NULL, 0);
// Add one byte for the trailing zero.
char* buffer = malloc(buffer_size + 1);
if (buffer == NULL) {
char* buffer = reinterpret_cast<char*>(malloc(buffer_size + 1));
if (buffer == nullptr) {
sendfailmsg(reply_fd, "not enough memory");
return 1;
}
@ -740,7 +743,7 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
if (!strncmp(service, "forward:",8) ||
!strncmp(service, "killforward:",12)) {
char *local, *remote, *err;
char *local, *remote;
int r;
atransport *transport;
@ -777,6 +780,7 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
}
}
const char* err;
transport = acquire_one_transport(CS_ANY, ttype, serial, &err);
if (!transport) {
sendfailmsg(reply_fd, err);
@ -835,7 +839,6 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
// "transport-local:" is used for switching transport to the only local transport
// "transport-any:" is used for switching transport to the only transport
if (!strncmp(service, "transport", strlen("transport"))) {
char* error_string = "unknown failure";
transport_type type = kTransportAny;
if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
@ -849,6 +852,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
serial = service;
}
const char* error_string = "unknown failure";
transport = acquire_one_transport(CS_ANY, type, serial, &error_string);
if (transport) {
@ -911,8 +915,8 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
}
if(!strncmp(service,"get-serialno",strlen("get-serialno"))) {
char *out = "unknown";
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
const char *out = "unknown";
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
if (transport && transport->serial) {
out = transport->serial;
}
@ -920,8 +924,8 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
return 0;
}
if(!strncmp(service,"get-devpath",strlen("get-devpath"))) {
char *out = "unknown";
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
const char *out = "unknown";
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
if (transport && transport->devpath) {
out = transport->devpath;
}
@ -938,7 +942,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
if(!strncmp(service,"get-state",strlen("get-state"))) {
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
char *state = connection_state_name(transport);
const char *state = connection_state_name(transport);
send_msg_with_okay(reply_fd, state, strlen(state));
return 0;
}

View File

@ -239,8 +239,8 @@ struct alistener
fdevent fde;
int fd;
const char *local_name;
const char *connect_to;
char *local_name;
char *connect_to;
atransport *transport;
adisconnect disconnect;
};
@ -348,7 +348,7 @@ void usb_kick(usb_handle *h);
int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol);
#endif
int adb_commandline(int argc, char **argv);
int adb_commandline(int argc, const char **argv);
int connection_state(atransport *t);

View File

@ -40,7 +40,8 @@ void send_auth_publickey(atransport *t);
#if ADB_HOST
int adb_auth_sign(void *key, void *token, size_t token_size, void *sig);
int adb_auth_sign(void *key, const unsigned char* token, size_t token_size,
unsigned char* sig);
void *adb_auth_nextkey(void *current);
int adb_auth_get_userkey(unsigned char *data, size_t len);
@ -50,12 +51,15 @@ static inline void adb_auth_confirm_key(unsigned char *data, size_t len, atransp
#else // !ADB_HOST
static inline int adb_auth_sign(void* key, void *token, size_t token_size, void *sig) { return 0; }
static inline int adb_auth_sign(void* key, const unsigned char* token,
size_t token_size, unsigned char* sig) {
return 0;
}
static inline void *adb_auth_nextkey(void *current) { return NULL; }
static inline int adb_auth_get_userkey(unsigned char *data, size_t len) { return 0; }
int adb_auth_generate_token(void *token, size_t token_size);
int adb_auth_verify(void *token, void *sig, int siglen);
int adb_auth_verify(uint8_t* token, uint8_t* sig, int siglen);
void adb_auth_confirm_key(unsigned char *data, size_t len, atransport *t);
#endif // ADB_HOST

View File

@ -37,7 +37,7 @@ struct adb_public_key {
RSAPublicKey key;
};
static char *key_paths[] = {
static const char *key_paths[] = {
"/adb_keys",
"/data/misc/adb/adb_keys",
NULL
@ -53,7 +53,6 @@ static bool needs_retry = false;
static void read_keys(const char *file, struct listnode *list)
{
struct adb_public_key *key;
FILE *f;
char buf[MAX_PAYLOAD];
char *sep;
@ -67,8 +66,9 @@ static void read_keys(const char *file, struct listnode *list)
while (fgets(buf, sizeof(buf), f)) {
/* Allocate 4 extra bytes to decode the base64 data in-place */
key = calloc(1, sizeof(*key) + 4);
if (!key) {
auto key = reinterpret_cast<adb_public_key*>(
calloc(1, sizeof(adb_public_key) + 4));
if (key == nullptr) {
D("Can't malloc key\n");
break;
}
@ -109,8 +109,8 @@ static void free_keys(struct listnode *list)
static void load_keys(struct listnode *list)
{
char *path;
char **paths = key_paths;
const char* path;
const char** paths = key_paths;
struct stat buf;
list_init(list);
@ -138,10 +138,9 @@ int adb_auth_generate_token(void *token, size_t token_size)
return ret * token_size;
}
int adb_auth_verify(void *token, void *sig, int siglen)
int adb_auth_verify(uint8_t* token, uint8_t* sig, int siglen)
{
struct listnode *item;
struct adb_public_key *key;
struct listnode key_list;
int ret = 0;
@ -151,7 +150,7 @@ int adb_auth_verify(void *token, void *sig, int siglen)
load_keys(&key_list);
list_for_each(item, &key_list) {
key = node_to_item(item, struct adb_public_key, node);
adb_public_key* key = node_to_item(item, struct adb_public_key, node);
ret = RSA_verify(&key->key, sig, siglen, token, SHA_DIGEST_SIZE);
if (ret)
break;

View File

@ -157,7 +157,7 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path)
RSAPublicKey pkey;
FILE *outfile = NULL;
char path[PATH_MAX], info[MAX_PAYLOAD];
uint8_t *encoded = NULL;
uint8_t* encoded = nullptr;
size_t encoded_length;
int ret = 0;
@ -191,8 +191,8 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path)
encoded_length = 1 + ((sizeof(pkey) + 2) / 3 * 4);
#endif
encoded = malloc(encoded_length);
if (encoded == NULL) {
encoded = reinterpret_cast<uint8_t*>(malloc(encoded_length));
if (encoded == nullptr) {
D("Allocation failure");
goto out;
}
@ -272,18 +272,16 @@ out:
static int read_key(const char *file, struct listnode *list)
{
struct adb_private_key *key;
FILE *f;
D("read_key '%s'\n", file);
f = fopen(file, "r");
FILE* f = fopen(file, "r");
if (!f) {
D("Failed to open '%s'\n", file);
return 0;
}
key = malloc(sizeof(*key));
adb_private_key* key = reinterpret_cast<adb_private_key*>(
malloc(sizeof(adb_private_key)));
if (!key) {
D("Failed to alloc key\n");
fclose(f);
@ -390,7 +388,8 @@ static void get_vendor_keys(struct listnode *list)
}
}
int adb_auth_sign(void *node, void *token, size_t token_size, void *sig)
int adb_auth_sign(void *node, const unsigned char* token, size_t token_size,
unsigned char* sig)
{
unsigned int len;
struct adb_private_key *key = node_to_item(node, struct adb_private_key, node);
@ -433,31 +432,33 @@ void *adb_auth_nextkey(void *current)
int adb_auth_get_userkey(unsigned char *data, size_t len)
{
char path[PATH_MAX];
char *file;
int ret;
ret = get_user_keyfilepath(path, sizeof(path) - 4);
int ret = get_user_keyfilepath(path, sizeof(path) - 4);
if (ret < 0 || ret >= (signed)(sizeof(path) - 4)) {
D("Error getting user key filename");
return 0;
}
strcat(path, ".pub");
file = load_file(path, (unsigned*)&ret);
if (!file) {
// TODO(danalbert): ReadFileToString
unsigned size;
char* file_data = reinterpret_cast<char*>(load_file(path, &size));
if (file_data == nullptr) {
D("Can't load '%s'\n", path);
return 0;
}
if (len < (size_t)(ret + 1)) {
D("%s: Content too large ret=%d\n", path, ret);
if (len < (size_t)(size + 1)) {
D("%s: Content too large ret=%d\n", path, size);
free(file_data);
return 0;
}
memcpy(data, file, ret);
data[ret] = '\0';
memcpy(data, file_data, size);
free(file_data);
file_data = nullptr;
data[size] = '\0';
return ret + 1;
return size + 1;
}
int adb_auth_keygen(const char* filename) {

View File

@ -115,7 +115,7 @@ static int switch_socket_transport(int fd)
if (__adb_serial)
snprintf(service, sizeof service, "host:transport:%s", __adb_serial);
else {
char* transport_type = "???";
const char* transport_type = "???";
switch (__adb_transport) {
case kTransportUsb:
@ -328,8 +328,8 @@ int adb_command(const char *service)
char *adb_query(const char *service)
{
char buf[5];
unsigned n;
char *tmp;
unsigned long n;
char* tmp;
D("adb_query: %s\n", service);
int fd = adb_connect(service);
@ -347,7 +347,7 @@ char *adb_query(const char *service)
goto oops;
}
tmp = malloc(n + 1);
tmp = reinterpret_cast<char*>(malloc(n + 1));
if(tmp == 0) goto oops;
if(!ReadFdExactly(fd, tmp, n) == 0) {

View File

@ -47,7 +47,7 @@ int adb_get_emulator_console_port(void);
* is zero, or more than one emulator connected (or if you use -s <serial>
* with a <serial> that does not designate an emulator)
*/
int adb_send_emulator_command(int argc, char** argv);
int adb_send_emulator_command(int argc, const char** argv);
/* return verbose error string from last operation */
const char *adb_error(void);

View File

@ -33,7 +33,7 @@ bool ReadFdExactly(int fd, void* buf, size_t len) {
D("readx: fd=%d wanted=%zu\n", fd, len);
while (len > 0) {
int r = TEMP_FAILURE_RETRY(adb_read(fd, p, len));
int r = adb_read(fd, p, len);
if (r > 0) {
len -= r;
p += r;
@ -69,7 +69,7 @@ bool WriteFdExactly(int fd, const void* buf, size_t len) {
#endif
while (len > 0) {
r = TEMP_FAILURE_RETRY(adb_write(fd, p, len));
r = adb_write(fd, p, len);
if (r == -1) {
D("writex: fd=%d error %d: %s\n", fd, errno, strerror(errno));
if (errno == EAGAIN) {

View File

@ -54,24 +54,26 @@ void ss_listener_event_func(int _fd, unsigned ev, void *_l)
}
}
void listener_event_func(int _fd, unsigned ev, void *_l)
void listener_event_func(int _fd, unsigned ev, void* _l)
{
alistener *l = _l;
alistener* listener = reinterpret_cast<alistener*>(_l);
asocket *s;
if(ev & FDE_READ) {
if (ev & FDE_READ) {
struct sockaddr addr;
socklen_t alen;
int fd;
alen = sizeof(addr);
fd = adb_socket_accept(_fd, &addr, &alen);
if(fd < 0) return;
if (fd < 0) {
return;
}
s = create_local_socket(fd);
if(s) {
s->transport = l->transport;
connect_to_remote(s, l->connect_to);
if (s) {
s->transport = listener->transport;
connect_to_remote(s, listener->connect_to);
return;
}
@ -102,11 +104,9 @@ static void free_listener(alistener* l)
free(l);
}
void listener_disconnect(void* _l, atransport* t)
void listener_disconnect(void* listener, atransport* t)
{
alistener* l = _l;
free_listener(l);
free_listener(reinterpret_cast<alistener*>(listener));
}
int local_name_to_fd(const char *name)
@ -220,20 +220,16 @@ install_status_t install_listener(const char *local_name,
atransport* transport,
int no_rebind)
{
alistener *l;
for (alistener* l = listener_list.next; l != &listener_list; l = l->next) {
if (strcmp(local_name, l->local_name) == 0) {
char* cto;
//printf("install_listener('%s','%s')\n", local_name, connect_to);
for(l = listener_list.next; l != &listener_list; l = l->next){
if(strcmp(local_name, l->local_name) == 0) {
char *cto;
/* can't repurpose a smartsocket */
/* can't repurpose a smartsocket */
if(l->connect_to[0] == '*') {
return INSTALL_STATUS_INTERNAL_ERROR;
}
/* can't repurpose a listener if 'no_rebind' is true */
/* can't repurpose a listener if 'no_rebind' is true */
if (no_rebind) {
return INSTALL_STATUS_CANNOT_REBIND;
}
@ -243,7 +239,6 @@ install_status_t install_listener(const char *local_name,
return INSTALL_STATUS_INTERNAL_ERROR;
}
//printf("rebinding '%s' to '%s'\n", local_name, connect_to);
free((void*) l->connect_to);
l->connect_to = cto;
if (l->transport != transport) {
@ -255,38 +250,51 @@ install_status_t install_listener(const char *local_name,
}
}
if((l = calloc(1, sizeof(alistener))) == 0) goto nomem;
if((l->local_name = strdup(local_name)) == 0) goto nomem;
if((l->connect_to = strdup(connect_to)) == 0) goto nomem;
alistener* listener = reinterpret_cast<alistener*>(
calloc(1, sizeof(alistener)));
if (listener == nullptr) {
goto nomem;
}
listener->local_name = strdup(local_name);
if (listener->local_name == nullptr) {
goto nomem;
}
l->fd = local_name_to_fd(local_name);
if(l->fd < 0) {
free((void*) l->local_name);
free((void*) l->connect_to);
free(l);
listener->connect_to = strdup(connect_to);
if (listener->connect_to == nullptr) {
goto nomem;
}
listener->fd = local_name_to_fd(local_name);
if (listener->fd < 0) {
free(listener->local_name);
free(listener->connect_to);
free(listener);
printf("cannot bind '%s'\n", local_name);
return -2;
return INSTALL_STATUS_CANNOT_BIND;
}
close_on_exec(l->fd);
if(!strcmp(l->connect_to, "*smartsocket*")) {
fdevent_install(&l->fde, l->fd, ss_listener_event_func, l);
close_on_exec(listener->fd);
if (!strcmp(listener->connect_to, "*smartsocket*")) {
fdevent_install(&listener->fde, listener->fd, ss_listener_event_func,
listener);
} else {
fdevent_install(&l->fde, l->fd, listener_event_func, l);
fdevent_install(&listener->fde, listener->fd, listener_event_func,
listener);
}
fdevent_set(&l->fde, FDE_READ);
fdevent_set(&listener->fde, FDE_READ);
l->next = &listener_list;
l->prev = listener_list.prev;
l->next->prev = l;
l->prev->next = l;
l->transport = transport;
listener->next = &listener_list;
listener->prev = listener_list.prev;
listener->next->prev = listener;
listener->prev->next = listener;
listener->transport = transport;
if (transport) {
l->disconnect.opaque = l;
l->disconnect.func = listener_disconnect;
add_transport_disconnect(transport, &l->disconnect);
listener->disconnect.opaque = listener;
listener->disconnect.func = listener_disconnect;
add_transport_disconnect(transport, &listener->disconnect);
}
return INSTALL_STATUS_OK;

View File

@ -387,7 +387,7 @@ int main(int argc, char **argv)
adb_sysdeps_init();
adb_trace_init();
D("Handling commandline()\n");
return adb_commandline(argc - 1, argv + 1);
return adb_commandline(argc - 1, const_cast<const char**>(argv + 1));
#else
/* If adbd runs inside the emulator this will enable adb tracing via
* adb-debug qemud service in the emulator. */

View File

@ -40,31 +40,30 @@
#include "adb_io.h"
#include "file_sync_service.h"
static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
static int do_cmd(transport_type ttype, const char* serial, const char *cmd, ...);
void get_my_path(char *s, size_t maxLen);
int find_sync_dirs(const char *srcarg,
char **android_srcdir_out, char **data_srcdir_out, char **vendor_srcdir_out);
int install_app(transport_type transport, char* serial, int argc, char** argv);
int install_multiple_app(transport_type transport, char* serial, int argc, char** argv);
int uninstall_app(transport_type transport, char* serial, int argc, char** argv);
int install_app(transport_type transport, const char* serial, int argc,
const char** argv);
int install_multiple_app(transport_type transport, const char* serial, int argc,
const char** argv);
int uninstall_app(transport_type transport, const char* serial, int argc,
const char** argv);
static const char *gProductOutPath = NULL;
extern int gListenAll;
static char *product_file(const char *extra)
{
int n;
char *x;
if (gProductOutPath == NULL) {
fprintf(stderr, "adb: Product directory not specified; "
"use -p or define ANDROID_PRODUCT_OUT\n");
exit(1);
}
n = strlen(gProductOutPath) + strlen(extra) + 2;
x = malloc(n);
int n = strlen(gProductOutPath) + strlen(extra) + 2;
char* x = reinterpret_cast<char*>(malloc(n));
if (x == 0) {
fprintf(stderr, "adb: Out of memory (product_file())\n");
exit(1);
@ -422,7 +421,6 @@ int interactive_shell(void)
{
adb_thread_t thr;
int fdi, fd;
int *fds;
fd = adb_connect("shell:");
if(fd < 0) {
@ -431,7 +429,7 @@ int interactive_shell(void)
}
fdi = 0; //dup(0);
fds = malloc(sizeof(int) * 2);
int* fds = reinterpret_cast<int*>(malloc(sizeof(int) * 2));
fds[0] = fd;
fds[1] = fdi;
@ -464,7 +462,6 @@ int adb_download_buffer(const char *service, const char *fn, const void* data, i
char buf[4096];
unsigned total;
int fd;
const unsigned char *ptr;
sprintf(buf,"%s:%d", service, sz);
fd = adb_connect(buf);
@ -477,7 +474,7 @@ int adb_download_buffer(const char *service, const char *fn, const void* data, i
opt = adb_setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *) &opt, sizeof(opt));
total = sz;
ptr = data;
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(data);
if(progress) {
char *x = strrchr(service, ':');
@ -557,14 +554,15 @@ int adb_download(const char *service, const char *fn, unsigned progress)
* we hang up.
*/
int adb_sideload_host(const char* fn) {
uint8_t* data;
unsigned sz;
size_t xfer = 0;
int status;
int last_percent = -1;
int opt = SIDELOAD_HOST_BLOCK_SIZE;
printf("loading: '%s'", fn);
fflush(stdout);
data = load_file(fn, &sz);
uint8_t* data = reinterpret_cast<uint8_t*>(load_file(fn, &sz));
if (data == 0) {
printf("\n");
fprintf(stderr, "* cannot read '%s' *\n", fn);
@ -582,10 +580,8 @@ int adb_sideload_host(const char* fn) {
goto done;
}
int opt = SIDELOAD_HOST_BLOCK_SIZE;
opt = adb_setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *) &opt, sizeof(opt));
int last_percent = -1;
for (;;) {
if (!ReadFdExactly(fd, buf, 8)) {
fprintf(stderr, "* failed to read command: %s\n", adb_error());
@ -739,13 +735,12 @@ static char *escape_arg(const char *s)
* ppp dev:/dev/omap_csmi_tty0 <ppp options>
*
*/
int ppp(int argc, char **argv)
int ppp(int argc, const char **argv)
{
#if defined(_WIN32)
fprintf(stderr, "error: adb %s not implemented on Win32\n", argv[0]);
return -1;
#else
char *adb_service_name;
pid_t pid;
int fd;
@ -756,8 +751,7 @@ int ppp(int argc, char **argv)
return 1;
}
adb_service_name = argv[1];
const char* adb_service_name = argv[1];
fd = adb_connect(adb_service_name);
if(fd < 0) {
@ -807,7 +801,8 @@ int ppp(int argc, char **argv)
#endif /* !defined(_WIN32) */
}
static int send_shellcommand(transport_type transport, char* serial, char* buf)
static int send_shellcommand(transport_type transport, const char* serial,
char* buf)
{
int fd, ret;
@ -828,7 +823,8 @@ static int send_shellcommand(transport_type transport, char* serial, char* buf)
return ret;
}
static int logcat(transport_type transport, char* serial, int argc, char **argv)
static int logcat(transport_type transport, const char* serial, int argc,
const char** argv)
{
char buf[4096];
@ -877,7 +873,7 @@ static int mkdirs(const char *path)
return 0;
}
static int backup(int argc, char** argv) {
static int backup(int argc, const char** argv) {
char buf[4096];
char default_name[32];
const char* filename = strcpy(default_name, "./backup.ab");
@ -933,7 +929,7 @@ static int backup(int argc, char** argv) {
return 0;
}
static int restore(int argc, char** argv) {
static int restore(int argc, const char** argv) {
const char* filename;
int fd, tarFd;
@ -1102,8 +1098,9 @@ static const char *find_product_out_path(const char *hint)
return path_buf;
}
static void parse_push_pull_args(char **arg, int narg, char const **path1, char const **path2,
int *show_progress, int *copy_attrs) {
static void parse_push_pull_args(const char **arg, int narg, char const **path1,
char const **path2, int *show_progress,
int *copy_attrs) {
*show_progress = 0;
*copy_attrs = 0;
@ -1130,7 +1127,7 @@ static void parse_push_pull_args(char **arg, int narg, char const **path1, char
}
}
int adb_commandline(int argc, char **argv)
int adb_commandline(int argc, const char **argv)
{
char buf[4096];
int no_daemon = 0;
@ -1139,8 +1136,8 @@ int adb_commandline(int argc, char **argv)
int persist = 0;
int r;
transport_type ttype = kTransportAny;
char* serial = NULL;
char* server_port_str = NULL;
const char* serial = NULL;
const char* server_port_str = NULL;
/* If defined, this should be an absolute path to
* the directory containing all of the various system images
@ -1274,7 +1271,7 @@ int adb_commandline(int argc, char **argv)
/* handle wait-for-* prefix */
if (!strncmp(argv[0], "wait-for-", strlen("wait-for-"))) {
char* service = argv[0];
const char* service = argv[0];
if (!strncmp(service, "wait-for-device", strlen("wait-for-device"))) {
if (ttype == kTransportUsb) {
service = "wait-for-usb";
@ -1308,7 +1305,7 @@ int adb_commandline(int argc, char **argv)
/* adb_connect() commands */
if (!strcmp(argv[0], "devices")) {
char *tmp;
char *listopt;
const char *listopt;
if (argc < 2)
listopt = "";
else if (argc == 2 && !strcmp(argv[1], "-l"))
@ -1635,7 +1632,8 @@ int adb_commandline(int argc, char **argv)
return uninstall_app(ttype, serial, argc, argv);
}
else if (!strcmp(argv[0], "sync")) {
char *srcarg, *android_srcpath, *data_srcpath, *vendor_srcpath;
const char* srcarg;
char *android_srcpath, *data_srcpath, *vendor_srcpath;
int listonly = 0;
int ret;
@ -1736,9 +1734,9 @@ int adb_commandline(int argc, char **argv)
}
#define MAX_ARGV_LENGTH 16
static int do_cmd(transport_type ttype, char* serial, char *cmd, ...)
static int do_cmd(transport_type ttype, const char* serial, const char *cmd, ...)
{
char *argv[MAX_ARGV_LENGTH];
const char *argv[MAX_ARGV_LENGTH];
int argc;
va_list ap;
@ -1818,8 +1816,8 @@ int find_sync_dirs(const char *srcarg,
return 0;
}
static int pm_command(transport_type transport, char* serial,
int argc, char** argv)
static int pm_command(transport_type transport, const char* serial,
int argc, const char** argv)
{
char buf[4096];
@ -1836,7 +1834,8 @@ static int pm_command(transport_type transport, char* serial,
return 0;
}
int uninstall_app(transport_type transport, char* serial, int argc, char** argv)
int uninstall_app(transport_type transport, const char* serial, int argc,
const char** argv)
{
/* if the user choose the -k option, we refuse to do it until devices are
out with the option to uninstall the remaining data somehow (adb/ui) */
@ -1854,7 +1853,7 @@ int uninstall_app(transport_type transport, char* serial, int argc, char** argv)
return pm_command(transport, serial, argc, argv);
}
static int delete_file(transport_type transport, char* serial, char* filename)
static int delete_file(transport_type transport, const char* serial, char* filename)
{
char buf[4096];
char* quoted;
@ -1879,7 +1878,8 @@ static const char* get_basename(const char* filename)
}
}
int install_app(transport_type transport, char* serial, int argc, char** argv)
int install_app(transport_type transport, const char* serial, int argc,
const char** argv)
{
static const char *const DATA_DEST = "/data/local/tmp/%s";
static const char *const SD_DEST = "/sdcard/tmp/%s";
@ -1897,7 +1897,7 @@ int install_app(transport_type transport, char* serial, int argc, char** argv)
// All other arguments passed through verbatim.
int last_apk = -1;
for (i = argc - 1; i >= 0; i--) {
char* file = argv[i];
const char* file = argv[i];
char* dot = strrchr(file, '.');
if (dot && !strcasecmp(dot, ".apk")) {
if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) {
@ -1915,7 +1915,7 @@ int install_app(transport_type transport, char* serial, int argc, char** argv)
return -1;
}
char* apk_file = argv[last_apk];
const char* apk_file = argv[last_apk];
char apk_dest[PATH_MAX];
snprintf(apk_dest, sizeof apk_dest, where, get_basename(apk_file));
int err = do_sync_push(apk_file, apk_dest, 0 /* no show progress */);
@ -1932,7 +1932,8 @@ cleanup_apk:
return err;
}
int install_multiple_app(transport_type transport, char* serial, int argc, char** argv)
int install_multiple_app(transport_type transport, const char* serial, int argc,
const char** argv)
{
char buf[1024];
int i;
@ -1943,7 +1944,7 @@ int install_multiple_app(transport_type transport, char* serial, int argc, char*
// All other arguments passed through verbatim.
int first_apk = -1;
for (i = argc - 1; i >= 0; i--) {
char* file = argv[i];
const char* file = argv[i];
char* dot = strrchr(file, '.');
if (dot && !strcasecmp(dot, ".apk")) {
if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) {
@ -1998,7 +1999,7 @@ int install_multiple_app(transport_type transport, char* serial, int argc, char*
// Valid session, now stream the APKs
int success = 1;
for (i = first_apk; i < argc; i++) {
char* file = argv[i];
const char* file = argv[i];
if (stat(file, &sb) == -1) {
fprintf(stderr, "Failed to stat %s\n", file);
success = 0;

View File

@ -24,7 +24,7 @@ static int connect_to_console(void)
}
int adb_send_emulator_command(int argc, char** argv)
int adb_send_emulator_command(int argc, const char** argv)
{
int fd, nn;

View File

@ -580,7 +580,8 @@ copyinfo *mkcopyinfo(const char *spath, const char *dpath,
int ssize = slen + nlen + 2;
int dsize = dlen + nlen + 2;
copyinfo *ci = malloc(sizeof(copyinfo) + ssize + dsize);
copyinfo *ci = reinterpret_cast<copyinfo*>(
malloc(sizeof(copyinfo) + ssize + dsize));
if(ci == 0) {
fprintf(stderr,"out of memory\n");
abort();
@ -684,14 +685,14 @@ static int copy_local_dir_remote(int fd, const char *lpath, const char *rpath, i
if((lpath[0] == 0) || (rpath[0] == 0)) return -1;
if(lpath[strlen(lpath) - 1] != '/') {
int tmplen = strlen(lpath)+2;
char *tmp = malloc(tmplen);
char *tmp = reinterpret_cast<char*>(malloc(tmplen));
if(tmp == 0) return -1;
snprintf(tmp, tmplen, "%s/",lpath);
lpath = tmp;
}
if(rpath[strlen(rpath) - 1] != '/') {
int tmplen = strlen(rpath)+2;
char *tmp = malloc(tmplen);
char *tmp = reinterpret_cast<char*>(malloc(tmplen));
if(tmp == 0) return -1;
snprintf(tmp, tmplen, "%s/",rpath);
rpath = tmp;
@ -784,7 +785,8 @@ int do_sync_push(const char *lpath, const char *rpath, int show_progress)
name++;
}
int tmplen = strlen(name) + strlen(rpath) + 2;
char *tmp = malloc(strlen(name) + strlen(rpath) + 2);
char *tmp = reinterpret_cast<char*>(
malloc(strlen(name) + strlen(rpath) + 2));
if(tmp == 0) return 1;
snprintf(tmp, tmplen, "%s/%s", rpath, name);
rpath = tmp;
@ -872,7 +874,7 @@ static int remote_build_list(int syncfd, copyinfo **filelist,
return 0;
}
static int set_time_and_mode(const char *lpath, unsigned int time, unsigned int mode)
static int set_time_and_mode(const char *lpath, time_t time, unsigned int mode)
{
struct utimbuf times = { time, time };
int r1 = utime(lpath, &times);
@ -890,7 +892,7 @@ static char *add_slash_to_path(const char *path)
{
if (path[strlen(path) - 1] != '/') {
size_t len = strlen(path) + 2;
char *path_with_slash = malloc(len);
char *path_with_slash = reinterpret_cast<char*>(malloc(len));
if (path_with_slash == NULL)
return NULL;
snprintf(path_with_slash, len, "%s/", path);
@ -999,7 +1001,7 @@ int do_sync_pull(const char *rpath, const char *lpath, int show_progress, int co
name++;
}
int tmplen = strlen(name) + strlen(lpath) + 2;
char *tmp = malloc(tmplen);
char *tmp = reinterpret_cast<char*>(malloc(tmplen));
if(tmp == 0) return 1;
snprintf(tmp, tmplen, "%s/%s", lpath, name);
lpath = tmp;

View File

@ -420,7 +420,7 @@ void file_sync_service(int fd, void *cookie)
char name[1025];
unsigned namelen;
char *buffer = malloc(SYNC_DATA_MAX);
char *buffer = reinterpret_cast<char*>(malloc(SYNC_DATA_MAX));
if(buffer == 0) goto fail;
for(;;) {

View File

@ -62,10 +62,11 @@ void framebuffer_service(int fd, void *cookie)
int fd_screencap;
int w, h, f;
int fds[2];
pid_t pid;
if (pipe2(fds, O_CLOEXEC) < 0) goto pipefail;
pid_t pid = fork();
pid = fork();
if (pid < 0) goto done;
if (pid == 0) {

View File

@ -17,6 +17,8 @@
#import <Carbon/Carbon.h>
#include <unistd.h>
#include "adb.h"
void get_my_path(char *s, size_t maxLen)
{
CFBundleRef mainBundle = CFBundleGetMainBundle();

View File

@ -14,10 +14,12 @@
* limitations under the License.
*/
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include "adb.h"
void get_my_path(char *exe, size_t maxLen)
{

View File

@ -14,10 +14,12 @@
* limitations under the License.
*/
#include <limits.h>
#include <assert.h>
#include <limits.h>
#include <windows.h>
#include "adb.h"
void get_my_path(char *exe, size_t maxLen)
{
char *r;

View File

@ -194,7 +194,8 @@ static void jdwp_process_event(int, unsigned, void*); /* forward */
static JdwpProcess*
jdwp_process_alloc( int socket )
{
JdwpProcess* proc = calloc(1,sizeof(*proc));
JdwpProcess* proc = reinterpret_cast<JdwpProcess*>(
calloc(1, sizeof(*proc)));
if (proc == NULL) {
D("not enough memory to create new JDWP process\n");
@ -234,7 +235,7 @@ jdwp_process_alloc( int socket )
static void
jdwp_process_event( int socket, unsigned events, void* _proc )
{
JdwpProcess* proc = _proc;
JdwpProcess* proc = reinterpret_cast<JdwpProcess*>(_proc);
if (events & FDE_READ) {
if (proc->pid < 0) {
@ -601,7 +602,7 @@ jdwp_socket_ready( asocket* s )
asocket*
create_jdwp_service_socket( void )
{
JdwpSocket* s = calloc(sizeof(*s),1);
JdwpSocket* s = reinterpret_cast<JdwpSocket*>(calloc(sizeof(*s), 1));
if (s == NULL)
return NULL;
@ -696,7 +697,7 @@ jdwp_tracker_enqueue( asocket* s, apacket* p )
asocket*
create_jdwp_tracker_service_socket( void )
{
JdwpTracker* t = calloc(sizeof(*t),1);
JdwpTracker* t = reinterpret_cast<JdwpTracker*>(calloc(sizeof(*t), 1));
if (t == NULL)
return NULL;

View File

@ -51,7 +51,7 @@ struct stinfo {
void *service_bootstrap_func(void *x)
{
stinfo *sti = x;
stinfo* sti = reinterpret_cast<stinfo*>(x);
sti->func(sti->fd, sti->cookie);
free(sti);
return 0;
@ -161,7 +161,7 @@ cleanup:
void reverse_service(int fd, void* arg)
{
const char* command = arg;
const char* command = reinterpret_cast<const char*>(arg);
if (handle_forward_request(command, kTransportAny, NULL, fd) < 0) {
sendfailmsg(fd, "not a reverse forwarding command");
@ -174,23 +174,23 @@ void reverse_service(int fd, void* arg)
static int create_service_thread(void (*func)(int, void *), void *cookie)
{
stinfo *sti;
adb_thread_t t;
int s[2];
if(adb_socketpair(s)) {
if (adb_socketpair(s)) {
printf("cannot create service socket pair\n");
return -1;
}
D("socketpair: (%d,%d)", s[0], s[1]);
sti = malloc(sizeof(stinfo));
if(sti == 0) fatal("cannot allocate stinfo");
stinfo* sti = reinterpret_cast<stinfo*>(malloc(sizeof(stinfo)));
if (sti == nullptr) {
fatal("cannot allocate stinfo");
}
sti->func = func;
sti->cookie = cookie;
sti->fd = s[1];
if(adb_thread_create( &t, service_bootstrap_func, sti)){
adb_thread_t t;
if (adb_thread_create(&t, service_bootstrap_func, sti)) {
free(sti);
adb_close(s[0]);
adb_close(s[1]);
@ -359,7 +359,6 @@ static void subproc_waiter_service(int fd, void *cookie)
static int create_subproc_thread(const char *name, const subproc_mode mode)
{
stinfo *sti;
adb_thread_t t;
int ret_fd;
pid_t pid = -1;
@ -384,7 +383,7 @@ static int create_subproc_thread(const char *name, const subproc_mode mode)
}
D("create_subproc ret_fd=%d pid=%d\n", ret_fd, pid);
sti = malloc(sizeof(stinfo));
stinfo* sti = reinterpret_cast<stinfo*>(malloc(sizeof(stinfo)));
if(sti == 0) fatal("cannot allocate stinfo");
sti->func = subproc_waiter_service;
sti->cookie = (void*) (uintptr_t) pid;
@ -512,11 +511,11 @@ struct state_info {
static void wait_for_state(int fd, void* cookie)
{
struct state_info* sinfo = cookie;
char* err = "unknown error";
state_info* sinfo = reinterpret_cast<state_info*>(cookie);
D("wait_for_state %d\n", sinfo->state);
const char* err = "unknown error";
atransport *t = acquire_one_transport(sinfo->state, sinfo->transport, sinfo->serial, &err);
if(t != 0) {
WriteFdExactly(fd, "OKAY", 4);
@ -635,7 +634,7 @@ static void connect_service(int fd, void* cookie)
{
char buf[4096];
char resp[4096];
char *host = cookie;
char *host = reinterpret_cast<char*>(cookie);
if (!strncmp(host, "emu:", 4)) {
connect_emulator(host + 4, buf, sizeof(buf));
@ -656,7 +655,7 @@ asocket* host_service_to_socket(const char* name, const char *serial)
if (!strcmp(name,"track-devices")) {
return create_device_tracker();
} else if (!strncmp(name, "wait-for-", strlen("wait-for-"))) {
struct state_info* sinfo = malloc(sizeof(struct state_info));
auto sinfo = reinterpret_cast<state_info*>(malloc(sizeof(state_info)));
if (serial)
sinfo->serial = strdup(serial);

View File

@ -140,7 +140,7 @@ static int set_verity_enabled_state(int fd, const char *block_device,
if (magic_number != VERITY_METADATA_MAGIC_NUMBER
&& magic_number != VERITY_METADATA_MAGIC_DISABLE) {
write_console(fd,
"Couldn't find verity metadata at offset %"PRIu64"!\n",
"Couldn't find verity metadata at offset %" PRIu64 "!\n",
device_length);
goto errout;
}

View File

@ -284,98 +284,101 @@ static void local_socket_close_locked(asocket *s)
insert_local_socket(s, &local_socket_closing_list);
}
static void local_socket_event_func(int fd, unsigned ev, void *_s)
static void local_socket_event_func(int fd, unsigned ev, void* _s)
{
asocket *s = _s;
asocket* s = reinterpret_cast<asocket*>(_s);
D("LS(%d): event_func(fd=%d(==%d), ev=%04x)\n", s->id, s->fd, fd, ev);
/* put the FDE_WRITE processing before the FDE_READ
** in order to simplify the code.
*/
if(ev & FDE_WRITE){
apacket *p;
while((p = s->pkt_first) != 0) {
while(p->len > 0) {
if (ev & FDE_WRITE) {
apacket* p;
while ((p = s->pkt_first) != nullptr) {
while (p->len > 0) {
int r = adb_write(fd, p->ptr, p->len);
if(r > 0) {
if (r == -1) {
/* returning here is ok because FDE_READ will
** be processed in the next iteration loop
*/
if (errno == EAGAIN) {
return;
}
} else if (r > 0) {
p->ptr += r;
p->len -= r;
continue;
}
if(r < 0) {
/* returning here is ok because FDE_READ will
** be processed in the next iteration loop
*/
if(errno == EAGAIN) return;
if(errno == EINTR) continue;
}
D(" closing after write because r=%d and errno is %d\n", r, errno);
s->close(s);
return;
}
if(p->len == 0) {
if (p->len == 0) {
s->pkt_first = p->next;
if(s->pkt_first == 0) s->pkt_last = 0;
if (s->pkt_first == 0) {
s->pkt_last = 0;
}
put_apacket(p);
}
}
/* if we sent the last packet of a closing socket,
** we can now destroy it.
*/
/* if we sent the last packet of a closing socket,
** we can now destroy it.
*/
if (s->closing) {
D(" closing because 'closing' is set after write\n");
s->close(s);
return;
}
/* no more packets queued, so we can ignore
** writable events again and tell our peer
** to resume writing
*/
/* no more packets queued, so we can ignore
** writable events again and tell our peer
** to resume writing
*/
fdevent_del(&s->fde, FDE_WRITE);
s->peer->ready(s->peer);
}
if(ev & FDE_READ){
if (ev & FDE_READ) {
apacket *p = get_apacket();
unsigned char *x = p->data;
size_t avail = MAX_PAYLOAD;
int r;
int is_eof = 0;
while(avail > 0) {
while (avail > 0) {
r = adb_read(fd, x, avail);
D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%zu\n", s->id, s->fd, r, r<0?errno:0, avail);
if(r > 0) {
D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%zu\n",
s->id, s->fd, r, r < 0 ? errno : 0, avail);
if (r == -1) {
if (errno == EAGAIN) {
break;
}
} else if (r > 0) {
avail -= r;
x += r;
continue;
}
if(r < 0) {
if(errno == EAGAIN) break;
if(errno == EINTR) continue;
}
/* r = 0 or unhandled error */
/* r = 0 or unhandled error */
is_eof = 1;
break;
}
D("LS(%d): fd=%d post avail loop. r=%d is_eof=%d forced_eof=%d\n",
s->id, s->fd, r, is_eof, s->fde.force_eof);
if((avail == MAX_PAYLOAD) || (s->peer == 0)) {
if ((avail == MAX_PAYLOAD) || (s->peer == 0)) {
put_apacket(p);
} else {
p->len = MAX_PAYLOAD - avail;
r = s->peer->enqueue(s->peer, p);
D("LS(%d): fd=%d post peer->enqueue(). r=%d\n", s->id, s->fd, r);
D("LS(%d): fd=%d post peer->enqueue(). r=%d\n", s->id, s->fd,
r);
if(r < 0) {
if (r < 0) {
/* error return means they closed us as a side-effect
** and we must return immediately.
**
@ -387,7 +390,7 @@ static void local_socket_event_func(int fd, unsigned ev, void *_s)
return;
}
if(r > 0) {
if (r > 0) {
/* if the remote cannot accept further events,
** we disable notification of READs. They'll
** be enabled again when we get a call to ready()
@ -396,13 +399,14 @@ static void local_socket_event_func(int fd, unsigned ev, void *_s)
}
}
/* Don't allow a forced eof if data is still there */
if((s->fde.force_eof && !r) || is_eof) {
D(" closing because is_eof=%d r=%d s->fde.force_eof=%d\n", is_eof, r, s->fde.force_eof);
if ((s->fde.force_eof && !r) || is_eof) {
D(" closing because is_eof=%d r=%d s->fde.force_eof=%d\n",
is_eof, r, s->fde.force_eof);
s->close(s);
}
}
if(ev & FDE_ERROR){
if (ev & FDE_ERROR){
/* this should be caught be the next read or write
** catching it here means we may skip the last few
** bytes of readable data.
@ -415,7 +419,7 @@ static void local_socket_event_func(int fd, unsigned ev, void *_s)
asocket *create_local_socket(int fd)
{
asocket *s = calloc(1, sizeof(asocket));
asocket *s = reinterpret_cast<asocket*>(calloc(1, sizeof(asocket)));
if (s == NULL) fatal("cannot allocate socket");
s->fd = fd;
s->enqueue = local_socket_enqueue;
@ -539,8 +543,8 @@ static void remote_socket_close(asocket *s)
static void remote_socket_disconnect(void* _s, atransport* t)
{
asocket* s = _s;
asocket* peer = s->peer;
asocket* s = reinterpret_cast<asocket*>(_s);
asocket* peer = s->peer;
D("remote_socket_disconnect RS(%d)\n", s->id);
if (peer) {
@ -557,12 +561,9 @@ static void remote_socket_disconnect(void* _s, atransport* t)
Returns a new non-NULL asocket handle. */
asocket *create_remote_socket(unsigned id, atransport *t)
{
asocket* s;
adisconnect* dis;
if (id == 0) fatal("invalid remote socket id (0)");
s = calloc(1, sizeof(aremotesocket));
dis = &((aremotesocket*)s)->disconnect;
asocket* s = reinterpret_cast<asocket*>(calloc(1, sizeof(aremotesocket)));
adisconnect* dis = &reinterpret_cast<aremotesocket*>(s)->disconnect;
if (s == NULL) fatal("cannot allocate socket");
s->id = id;
@ -824,7 +825,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
}
#else /* !ADB_HOST */
if (s->transport == NULL) {
char* error_string = "unknown failure";
const char* error_string = "unknown failure";
s->transport = acquire_one_transport (CS_ANY,
kTransportAny, NULL, &error_string);
@ -892,7 +893,7 @@ static void smart_socket_close(asocket *s)
static asocket *create_smart_socket(void)
{
D("Creating smart socket \n");
asocket *s = calloc(1, sizeof(asocket));
asocket *s = reinterpret_cast<asocket*>(calloc(1, sizeof(asocket)));
if (s == NULL) fatal("cannot allocate socket");
s->enqueue = smart_socket_enqueue;
s->ready = smart_socket_ready;

View File

@ -221,7 +221,7 @@ write_packet(int fd, const char* name, apacket** ppacket)
static void transport_socket_events(int fd, unsigned events, void *_t)
{
atransport *t = _t;
atransport *t = reinterpret_cast<atransport*>(_t);
D("transport_socket_events(fd=%d, events=%04x,...)\n", fd, events);
if(events & FDE_READ){
apacket *p = 0;
@ -278,7 +278,7 @@ void send_packet(apacket *p, atransport *t)
static void *output_thread(void *_t)
{
atransport *t = _t;
atransport *t = reinterpret_cast<atransport*>(_t);
apacket *p;
D("%s: starting transport output thread on fd %d, SYNC online (%d)\n",
@ -333,7 +333,7 @@ oops:
static void *input_thread(void *_t)
{
atransport *t = _t;
atransport *t = reinterpret_cast<atransport*>(_t);
apacket *p;
int active = 0;
@ -494,7 +494,8 @@ device_tracker_ready( asocket* socket )
asocket*
create_device_tracker(void)
{
device_tracker* tracker = calloc(1,sizeof(*tracker));
device_tracker* tracker = reinterpret_cast<device_tracker*>(
calloc(1, sizeof(*tracker)));
if(tracker == 0) fatal("cannot allocate device tracker");
@ -799,7 +800,8 @@ static int qual_match(const char *to_test,
return !*to_test;
}
atransport *acquire_one_transport(int state, transport_type ttype, const char* serial, char** error_out)
atransport *acquire_one_transport(int state, transport_type ttype,
const char* serial, const char** error_out)
{
atransport *t;
atransport *result = NULL;
@ -1007,7 +1009,8 @@ void close_usb_devices()
int register_socket_transport(int s, const char *serial, int port, int local)
{
atransport *t = calloc(1, sizeof(atransport));
atransport *t = reinterpret_cast<atransport*>(
calloc(1, sizeof(atransport)));
atransport *n;
char buff[32];
@ -1106,7 +1109,8 @@ void unregister_all_tcp_transports()
void register_usb_transport(usb_handle *usb, const char *serial, const char *devpath, unsigned writeable)
{
atransport *t = calloc(1, sizeof(atransport));
atransport *t = reinterpret_cast<atransport*>(
calloc(1, sizeof(atransport)));
D("transport: %p init'ing for usb_handle %p (sn='%s')\n", t, usb,
serial ? serial : "");
init_usb_transport(t, usb, (writeable ? CS_OFFLINE : CS_NOPERM));

View File

@ -37,7 +37,7 @@ void dump_hex(const unsigned char* ptr, size_t len);
* If no suitable transport is found, error is set.
*/
atransport* acquire_one_transport(int state, transport_type ttype,
const char* serial, char** error_out);
const char* serial, const char** error_out);
void add_transport_disconnect(atransport* t, adisconnect* dis);
void remove_transport_disconnect(atransport* t, adisconnect* dis);
void kick_transport(atransport* t);

View File

@ -574,7 +574,6 @@ static void register_device(const char *dev_name, const char *devpath,
unsigned char ep_in, unsigned char ep_out,
int interface, int serial_index, unsigned zero_mask)
{
usb_handle* usb = 0;
int n = 0;
char serial[256];
@ -587,8 +586,9 @@ static void register_device(const char *dev_name, const char *devpath,
** name, we have no further work to do.
*/
adb_mutex_lock(&usb_lock);
for(usb = handle_list.next; usb != &handle_list; usb = usb->next){
if(!strcmp(usb->fname, dev_name)) {
for (usb_handle* usb = handle_list.next; usb != &handle_list;
usb = usb->next) {
if (!strcmp(usb->fname, dev_name)) {
adb_mutex_unlock(&usb_lock);
return;
}
@ -597,7 +597,8 @@ static void register_device(const char *dev_name, const char *devpath,
D("[ usb located new device %s (%d/%d/%d) ]\n",
dev_name, ep_in, ep_out, interface);
usb = calloc(1, sizeof(usb_handle));
usb_handle* usb = reinterpret_cast<usb_handle*>(
calloc(1, sizeof(usb_handle)));
strcpy(usb->fname, dev_name);
usb->ep_in = ep_in;
usb->ep_out = ep_out;