- } else if (buf[0] == '4') {
- do {
- if (fgets(buf, sizeof buf, stdin) == NULL)
- strcpy(buf, "000");
- if (strlen(buf) > 0)
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = 0;
- if (strlen(buf) > 0)
- if (buf[strlen(buf) - 1] == '\r')
- buf[strlen(buf) - 1] = 0;
- if (strcmp(buf, "000"))
- CtdlIPC_chat_send(ipc, buf);
-
- FD_ZERO(&read_fd);
- FD_SET(ipc->sock, &read_fd);
- ret = select(ipc->sock+1, &read_fd, NULL, NULL, &tv);
- err = errno;
- if (err!=0)
- printf("select failed: %d", err);
-
- if (ret == -1) {
- if (!(errno == EINTR || errno == EAGAIN))
- printf("select failed: %d", err);
- return 1;
- }
+ }
+
+ if (xfermode == '6') { /* receive binary */
+ size_t len = atoi(&buf[4]);
+ size_t bytes_remaining = len;
+
+ while (bytes_remaining > 0) {
+ size_t this_block = bytes_remaining;
+ if (this_block > SIZ) this_block = SIZ;
+ serv_read(buf, this_block);
+ fwrite(buf, this_block, 1, stdout);
+ bytes_remaining -= this_block;
+ }
+ }