aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2005-03-04 15:38:58 +0000
committerWayne Davison <wayned@samba.org>2005-03-04 15:38:58 +0000
commit46e99b09b980f3d67dc3f92f07b27db754981662 (patch)
tree9ac987e7359ed31ffbc353e1cd85da80047be8b4 /io.c
parentaf436313a05bd40ccc08df05dbf22c46e51882bf (diff)
downloadandroid_external_rsync-46e99b09b980f3d67dc3f92f07b27db754981662.tar.gz
android_external_rsync-46e99b09b980f3d67dc3f92f07b27db754981662.tar.bz2
android_external_rsync-46e99b09b980f3d67dc3f92f07b27db754981662.zip
Added read_vstring() and write_vstring() to io.c instead of
having this code in generator.c and receiver.c.
Diffstat (limited to 'io.c')
-rw-r--r--io.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/io.c b/io.c
index a53b347c..64c19007 100644
--- a/io.c
+++ b/io.c
@@ -850,6 +850,25 @@ uchar read_byte(int f)
return c;
}
+int read_vstring(int f, char *buf, int bufsize)
+{
+ int len = read_byte(f);
+
+ if (len & 0x80)
+ len = (len & ~0x80) * 0x100 + read_byte(f);
+
+ if (len >= bufsize) {
+ rprintf(FERROR, "over-long vstring received (%d > %d)\n",
+ len, bufsize - 1);
+ exit_cleanup(RERR_PROTOCOL);
+ }
+
+ if (len)
+ readfd(f, buf, len);
+ buf[len] = '\0';
+ return len;
+}
+
/* Populate a sum_struct with values from the socket. This is
* called by both the sender and the receiver. */
void read_sum_head(int f, struct sum_struct *sum)
@@ -1203,6 +1222,26 @@ void write_byte(int f, uchar c)
writefd(f, (char *)&c, 1);
}
+void write_vstring(int f, char *str, int len)
+{
+ uchar lenbuf[3], *lb = lenbuf;
+
+ if (len > 0x7F) {
+ if (len > 0x7FFF) {
+ rprintf(FERROR,
+ "attempting to send over-long vstring (%d > %d)\n",
+ len, 0x7FFF);
+ exit_cleanup(RERR_PROTOCOL);
+ }
+ *lb++ = len / 0x100 + 0x80;
+ }
+ *lb = len;
+
+ writefd(f, (char*)lenbuf, lb - lenbuf + 1);
+ if (len)
+ writefd(f, str, len);
+}
+
/**
* Read a line of up to @p maxlen characters into @p buf (not counting