Merge "There are no big endian hosts, grandpa."
This commit is contained in:
commit
93b9e8653e
3 changed files with 25 additions and 28 deletions
|
@ -79,7 +79,7 @@ static bool SendRequest(int fd, int id, const char* path) {
|
|||
char buf[sizeof(SyncRequest) + path_length] __attribute__((aligned(8)));
|
||||
SyncRequest* req = reinterpret_cast<SyncRequest*>(buf);
|
||||
req->id = id;
|
||||
req->path_length = htoll(path_length);
|
||||
req->path_length = path_length;
|
||||
char* data = reinterpret_cast<char*>(req + 1);
|
||||
memcpy(data, path, path_length);
|
||||
|
||||
|
@ -143,14 +143,14 @@ static bool sync_ls(int fd, const char* path, sync_ls_cb func, void* cookie) {
|
|||
if (msg.dent.id == ID_DONE) return true;
|
||||
if (msg.dent.id != ID_DENT) return false;
|
||||
|
||||
size_t len = ltohl(msg.dent.namelen);
|
||||
size_t len = msg.dent.namelen;
|
||||
if (len > 256) return false; // TODO: resize buffer? continue?
|
||||
|
||||
char buf[257];
|
||||
if (!ReadFdExactly(fd, buf, len)) return false;
|
||||
buf[len] = 0;
|
||||
|
||||
func(ltohl(msg.dent.mode), ltohl(msg.dent.size), ltohl(msg.dent.time), buf, cookie);
|
||||
func(msg.dent.mode, msg.dent.size, msg.dent.time, buf, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,9 +165,9 @@ static bool sync_finish_stat(SyncConnection& sc, unsigned int* timestamp,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (timestamp) *timestamp = ltohl(msg.stat.time);
|
||||
if (mode) *mode = ltohl(msg.stat.mode);
|
||||
if (size) *size = ltohl(msg.stat.size);
|
||||
if (timestamp) *timestamp = msg.stat.time;
|
||||
if (mode) *mode = msg.stat.mode;
|
||||
if (size) *size = msg.stat.size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ static int write_data_file(SyncConnection& sc, const char* path, syncsendbuf* sb
|
|||
break;
|
||||
}
|
||||
|
||||
sbuf->size = htoll(ret);
|
||||
sbuf->size = ret;
|
||||
if (!WriteFdExactly(sc.fd, sbuf, sizeof(unsigned) * 2 + ret)) {
|
||||
err = -1;
|
||||
break;
|
||||
|
@ -238,7 +238,7 @@ static int write_data_link(SyncConnection& sc, const char* path, syncsendbuf* sb
|
|||
}
|
||||
sbuf->data[len] = '\0';
|
||||
|
||||
sbuf->size = htoll(len + 1);
|
||||
sbuf->size = len + 1;
|
||||
sbuf->id = ID_DATA;
|
||||
|
||||
if (!WriteFdExactly(sc.fd, sbuf, sizeof(unsigned) * 2 + len + 1)) {
|
||||
|
@ -269,14 +269,14 @@ static bool sync_send(SyncConnection& sc, const char *lpath, const char *rpath,
|
|||
|
||||
syncmsg msg;
|
||||
msg.data.id = ID_DONE;
|
||||
msg.data.size = htoll(mtime);
|
||||
msg.data.size = mtime;
|
||||
if (!WriteFdExactly(sc.fd, &msg.data, sizeof(msg.data))) goto fail;
|
||||
|
||||
if (!ReadFdExactly(sc.fd, &msg.status, sizeof(msg.status))) goto fail;
|
||||
|
||||
if (msg.status.id != ID_OKAY) {
|
||||
if (msg.status.id == ID_FAIL) {
|
||||
size_t len = ltohl(msg.status.msglen);
|
||||
size_t len = msg.status.msglen;
|
||||
if (len > 256) len = 256;
|
||||
if (!ReadFdExactly(sc.fd, sbuf->data, len)) goto fail;
|
||||
sbuf->data[len] = 0;
|
||||
|
@ -333,7 +333,7 @@ static int sync_recv(SyncConnection& sc, const char* rpath, const char* lpath, b
|
|||
id = msg.data.id;
|
||||
|
||||
handle_data:
|
||||
len = ltohl(msg.data.size);
|
||||
len = msg.data.size;
|
||||
if (id == ID_DONE) break;
|
||||
if (id != ID_DATA) goto remote_error;
|
||||
if (len > sc.max) {
|
||||
|
@ -368,7 +368,7 @@ remote_error:
|
|||
adb_unlink(lpath);
|
||||
|
||||
if(id == ID_FAIL) {
|
||||
len = ltohl(msg.data.size);
|
||||
len = msg.data.size;
|
||||
if(len > 256) len = 256;
|
||||
if(!ReadFdExactly(sc.fd, buffer, len)) {
|
||||
return -1;
|
||||
|
|
|
@ -85,9 +85,9 @@ static bool do_stat(int s, const char* path) {
|
|||
memset(&st, 0, sizeof(st));
|
||||
// TODO: add a way to report that the stat failed!
|
||||
lstat(path, &st);
|
||||
msg.stat.mode = htoll(st.st_mode);
|
||||
msg.stat.size = htoll(st.st_size);
|
||||
msg.stat.time = htoll(st.st_mtime);
|
||||
msg.stat.mode = st.st_mode;
|
||||
msg.stat.size = st.st_size;
|
||||
msg.stat.time = st.st_mtime;
|
||||
|
||||
return WriteFdExactly(s, &msg.stat, sizeof(msg.stat));
|
||||
}
|
||||
|
@ -107,10 +107,10 @@ static bool do_list(int s, const char* path) {
|
|||
struct stat st;
|
||||
if (lstat(filename.c_str(), &st) == 0) {
|
||||
size_t d_name_length = strlen(de->d_name);
|
||||
msg.dent.mode = htoll(st.st_mode);
|
||||
msg.dent.size = htoll(st.st_size);
|
||||
msg.dent.time = htoll(st.st_mtime);
|
||||
msg.dent.namelen = htoll(d_name_length);
|
||||
msg.dent.mode = st.st_mode;
|
||||
msg.dent.size = st.st_size;
|
||||
msg.dent.time = st.st_mtime;
|
||||
msg.dent.namelen = d_name_length;
|
||||
|
||||
if (!WriteFdExactly(s, &msg.dent, sizeof(msg.dent)) ||
|
||||
!WriteFdExactly(s, de->d_name, d_name_length)) {
|
||||
|
@ -133,7 +133,7 @@ static bool fail_message(int s, const std::string& reason) {
|
|||
|
||||
syncmsg msg;
|
||||
msg.data.id = ID_FAIL;
|
||||
msg.data.size = htoll(reason.size());
|
||||
msg.data.size = reason.size();
|
||||
return WriteFdExactly(s, &msg.data, sizeof(msg.data)) && WriteFdExactly(s, reason);
|
||||
}
|
||||
|
||||
|
@ -185,13 +185,13 @@ static bool handle_send_file(int s, char *path, uid_t uid,
|
|||
|
||||
if(msg.data.id != ID_DATA) {
|
||||
if(msg.data.id == ID_DONE) {
|
||||
timestamp = ltohl(msg.data.size);
|
||||
timestamp = msg.data.size;
|
||||
break;
|
||||
}
|
||||
fail_message(s, "invalid data message");
|
||||
goto fail;
|
||||
}
|
||||
len = ltohl(msg.data.size);
|
||||
len = msg.data.size;
|
||||
if (len > buffer.size()) { // TODO: resize buffer?
|
||||
fail_message(s, "oversize data message");
|
||||
goto fail;
|
||||
|
@ -245,7 +245,7 @@ static bool handle_send_link(int s, char *path, std::vector<char>& buffer) {
|
|||
return false;
|
||||
}
|
||||
|
||||
len = ltohl(msg.data.size);
|
||||
len = msg.data.size;
|
||||
if (len > buffer.size()) { // TODO: resize buffer?
|
||||
fail_message(s, "oversize data message");
|
||||
return false;
|
||||
|
@ -346,7 +346,7 @@ static bool do_recv(int s, const char* path, std::vector<char>& buffer) {
|
|||
adb_close(fd);
|
||||
return status;
|
||||
}
|
||||
msg.data.size = htoll(r);
|
||||
msg.data.size = r;
|
||||
if (!WriteFdExactly(s, &msg.data, sizeof(msg.data)) || !WriteFdExactly(s, &buffer[0], r)) {
|
||||
adb_close(fd);
|
||||
return false;
|
||||
|
@ -368,7 +368,7 @@ static bool handle_sync_command(int fd, std::vector<char>& buffer) {
|
|||
fail_message(fd, "command read failure");
|
||||
return false;
|
||||
}
|
||||
size_t path_length = ltohl(request.path_length);
|
||||
size_t path_length = request.path_length;
|
||||
if (path_length > 1024) {
|
||||
fail_message(fd, "path too long");
|
||||
return false;
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#define htoll(x) (x)
|
||||
#define ltohl(x) (x)
|
||||
|
||||
#define MKID(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
|
||||
|
||||
#define ID_STAT MKID('S','T','A','T')
|
||||
|
|
Loading…
Reference in a new issue