diff options
author | Ben Peart <peartben@gmail.com> | 2017-05-05 11:27:55 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-08 10:57:26 +0900 |
commit | 825b9226bf7a962bc76571319b1444bc02fdcdf8 (patch) | |
tree | 25c951682283cdff32e19364c143c69efcd23a40 /pkt-line.c | |
parent | 974b50c5565107e1e3209176682ee6f6e420bd2b (diff) | |
download | git-825b9226bf7a962bc76571319b1444bc02fdcdf8.tar.gz |
pkt-line: add packet_read_line_gently()
Add packet_read_line_gently() to enable reading a line without dying on
EOF.
Signed-off-by: Ben Peart <benpeart@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pkt-line.c')
-rw-r--r-- | pkt-line.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/pkt-line.c b/pkt-line.c index 6f05b1a4a8..7db9119573 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -323,6 +323,18 @@ char *packet_read_line(int fd, int *len_p) return packet_read_line_generic(fd, NULL, NULL, len_p); } +int packet_read_line_gently(int fd, int *dst_len, char **dst_line) +{ + int len = packet_read(fd, NULL, NULL, + packet_buffer, sizeof(packet_buffer), + PACKET_READ_CHOMP_NEWLINE|PACKET_READ_GENTLE_ON_EOF); + if (dst_len) + *dst_len = len; + if (dst_line) + *dst_line = (len > 0) ? packet_buffer : NULL; + return len; +} + char *packet_read_line_buf(char **src, size_t *src_len, int *dst_len) { return packet_read_line_generic(-1, src, src_len, dst_len); |