X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/9486289ce452ab82ca8b3f16fae8c2ef5247a923..f855d1a309f38301bcd8898e9fbc5c70133d1f98:/io.c diff --git a/io.c b/io.c index f5816ed9..004f4cee 100644 --- a/io.c +++ b/io.c @@ -423,10 +423,16 @@ void write_buf(int f,char *buf,int len) total_written += len; } +/* write a string to the connection */ +void write_sbuf(int f,char *buf) +{ + write_buf(f, buf, strlen(buf)); +} + void write_byte(int f,unsigned char c) { - write_buf(f,(char *)&c,1); + write_buf(f,(char *)&c,1); } void write_flush(int f) @@ -434,3 +440,44 @@ void write_flush(int f) } +int read_line(int f, char *buf, int maxlen) +{ + while (maxlen) { + read_buf(f, buf, 1); + if (buf[0] == '\n') { + buf[0] = 0; + break; + } + if (buf[0] != '\r') { + buf++; + maxlen--; + } + } + if (maxlen == 0) { + *buf = 0; + return 0; + } + return 1; +} + + +void io_printf(int fd, const char *format, ...) +{ + va_list ap; + char buf[1024]; + int len; + + va_start(ap, format); + +#if HAVE_VSNPRINTF + len = vsnprintf(buf, sizeof(buf)-1, format, ap); +#else + vsprintf(buf, format, ap); + len = strlen(buf); +#endif + va_end(ap); + + if (len < 0) exit_cleanup(1); + + write_sbuf(fd, buf); +}