diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-26 12:07:48 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-26 12:07:48 +0200 |
| commit | 0b0ccd457016d6a4eaa3e79bd65a852ea7d4294b (patch) | |
| tree | 88a66fea6596f6ef6426b8590e2ca348da7ba50c | |
| parent | 2a870d091e86687c8b7b9e14b9c75815d40d7053 (diff) | |
| download | busybox-w32-0b0ccd457016d6a4eaa3e79bd65a852ea7d4294b.tar.gz busybox-w32-0b0ccd457016d6a4eaa3e79bd65a852ea7d4294b.tar.bz2 busybox-w32-0b0ccd457016d6a4eaa3e79bd65a852ea7d4294b.zip | |
ftpd: optimize writes of LIST results a bit
function old new delta
handle_dir_common 201 207 +6
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/ftpd.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c index b4d73e55d..e724734df 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c | |||
| @@ -709,6 +709,7 @@ handle_dir_common(int opts) | |||
| 709 | * which can be problematic in chroot */ | 709 | * which can be problematic in chroot */ |
| 710 | ls_fd = popen_ls((opts & LONG_LISTING) ? "-l" : "-1"); | 710 | ls_fd = popen_ls((opts & LONG_LISTING) ? "-l" : "-1"); |
| 711 | ls_fp = xfdopen_for_read(ls_fd); | 711 | ls_fp = xfdopen_for_read(ls_fd); |
| 712 | /* FIXME: filenames with embedded newlines are mishandled */ | ||
| 712 | 713 | ||
| 713 | if (opts & USE_CTRL_CONN) { | 714 | if (opts & USE_CTRL_CONN) { |
| 714 | /* STAT <filename> */ | 715 | /* STAT <filename> */ |
| @@ -729,16 +730,20 @@ handle_dir_common(int opts) | |||
| 729 | int remote_fd = get_remote_transfer_fd(" Directory listing"); | 730 | int remote_fd = get_remote_transfer_fd(" Directory listing"); |
| 730 | if (remote_fd >= 0) { | 731 | if (remote_fd >= 0) { |
| 731 | while (1) { | 732 | while (1) { |
| 732 | line = xmalloc_fgetline(ls_fp); | 733 | unsigned len; |
| 734 | |||
| 735 | line = xmalloc_fgets(ls_fp); | ||
| 733 | if (!line) | 736 | if (!line) |
| 734 | break; | 737 | break; |
| 735 | /* I've seen clients complaining when they | 738 | /* I've seen clients complaining when they |
| 736 | * are fed with ls output with bare '\n'. | 739 | * are fed with ls output with bare '\n'. |
| 737 | * Pity... that would be much simpler. | 740 | * Replace trailing "\n\0" with "\r\n". |
| 738 | */ | 741 | */ |
| 739 | /* TODO: need to s/LF/NUL/g here */ | 742 | len = strlen(line); |
| 740 | xwrite_str(remote_fd, line); | 743 | if (len != 0) /* paranoia check */ |
| 741 | xwrite(remote_fd, "\r\n", 2); | 744 | line[len - 1] = '\r'; |
| 745 | line[len] = '\n'; | ||
| 746 | xwrite(remote_fd, line, len + 1); | ||
| 742 | free(line); | 747 | free(line); |
| 743 | } | 748 | } |
| 744 | } | 749 | } |
