@matheusbsbs / matheus-bagliano / commits / 7e2fe3a9fc
Fork 0

vcs-svn: remove buffer_read_string

All previous users of buffer_read_string have already been converted to use the more intuitive buffer_read_binary, so remove the old API to avoid some confusion. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

Jonathan Nieder committed Mar 24, 2011 at 23:09 UTC 7e2fe3a9fc816391b322ad9b3f2adf9342631db6
5 files changed +17 -48
t/t0081-line-buffer.sh
+13 -22
@@ -53,7 +53,7 @@ long_read_test () {
53 } >input &
54 } &&
55 test-line-buffer input <<-EOF >output &&
56 - read $readsize
56 + binary $readsize
57 copy $copysize
58 EOF
59 kill $! &&
@@ -71,23 +71,23 @@ test_expect_success 'setup: have pipes?' '
71 '
72
73 test_expect_success 'hello world' '
74 - echo HELLO >expect &&
74 + echo ">HELLO" >expect &&
75 test-line-buffer <<-\EOF >actual &&
76 - read 6
76 + binary 6
77 HELLO
78 EOF
79 test_cmp expect actual
80 '
81
82 test_expect_success PIPE '0-length read, no input available' '
83 - >expect &&
83 + printf ">" >expect &&
84 rm -f input &&
85 mkfifo input &&
86 {
87 sleep 100 >input &
88 } &&
89 test-line-buffer input <<-\EOF >actual &&
90 - read 0
90 + binary 0
91 copy 0
92 EOF
93 kill $! &&
@@ -95,9 +95,9 @@ test_expect_success PIPE '0-length read, no input available' '
95 '
96
97 test_expect_success '0-length read, send along greeting' '
98 - echo HELLO >expect &&
98 + echo ">HELLO" >expect &&
99 test-line-buffer <<-\EOF >actual &&
100 - read 0
100 + binary 0
101 copy 6
102 HELLO
103 EOF
@@ -105,7 +105,7 @@ test_expect_success '0-length read, send along greeting' '
105 '
106
107 test_expect_success PIPE '1-byte read, no input available' '
108 - printf "%s" ab >expect &&
108 + printf ">%s" ab >expect &&
109 rm -f input &&
110 mkfifo input &&
111 {
@@ -116,7 +116,7 @@ test_expect_success PIPE '1-byte read, no input available' '
116 } >input &
117 } &&
118 test-line-buffer input <<-\EOF >actual &&
119 - read 1
119 + binary 1
120 copy 1
121 EOF
122 kill $! &&
@@ -140,15 +140,6 @@ test_expect_success 'read from file descriptor' '
140 test_cmp expect actual
141 '
142
143 -test_expect_success 'buffer_read_string copes with null byte' '
144 - >expect &&
145 - q_to_nul <<-\EOF | test-line-buffer >actual &&
146 - read 2
147 - Q
148 - EOF
149 - test_cmp expect actual
150 -'
151 -
143 test_expect_success 'skip, copy null byte' '
144 echo Q | q_to_nul >expect &&
145 q_to_nul <<-\EOF | test-line-buffer >actual &&
@@ -170,18 +161,18 @@ test_expect_success 'read null byte' '
161 '
162
163 test_expect_success 'long reads are truncated' '
173 - echo foo >expect &&
164 + echo ">foo" >expect &&
165 test-line-buffer <<-\EOF >actual &&
175 - read 5
166 + binary 5
167 foo
168 EOF
169 test_cmp expect actual
170 '
171
172 test_expect_success 'long copies are truncated' '
182 - printf "%s\n" "" foo >expect &&
173 + printf "%s\n" ">" foo >expect &&
174 test-line-buffer <<-\EOF >actual &&
184 - read 1
175 + binary 1
176
177 copy 5
178 foo
test-line-buffer.c
-6
@@ -32,12 +32,6 @@ static void handle_command(const char *command, const char *arg, struct line_buf
32 buffer_copy_bytes(buf, strtouint32(arg));
33 return;
34 }
35 - case 'r':
36 - if (!prefixcmp(command, "read ")) {
37 - const char *s = buffer_read_string(buf, strtouint32(arg));
38 - fputs(s, stdout);
39 - return;
40 - }
35 case 's':
36 if (!prefixcmp(command, "skip ")) {
37 buffer_skip_bytes(buf, strtouint32(arg));
vcs-svn/line_buffer.c
-8
@@ -91,13 +91,6 @@ char *buffer_read_line(struct line_buffer *buf)
91 return buf->line_buffer;
92 }
93
94 -char *buffer_read_string(struct line_buffer *buf, uint32_t len)
95 -{
96 - strbuf_reset(&buf->blob_buffer);
97 - strbuf_fread(&buf->blob_buffer, len, buf->infile);
98 - return ferror(buf->infile) ? NULL : buf->blob_buffer.buf;
99 -}
100 -
94 void buffer_read_binary(struct line_buffer *buf,
95 struct strbuf *sb, uint32_t size)
96 {
@@ -134,5 +127,4 @@ off_t buffer_skip_bytes(struct line_buffer *buf, off_t nbytes)
127
128 void buffer_reset(struct line_buffer *buf)
129 {
137 - strbuf_release(&buf->blob_buffer);
130 }
vcs-svn/line_buffer.h
+1 -3
@@ -7,10 +7,9 @@
7
8 struct line_buffer {
9 char line_buffer[LINE_BUFFER_LEN];
10 - struct strbuf blob_buffer;
10 FILE *infile;
11 };
13 -#define LINE_BUFFER_INIT {"", STRBUF_INIT, NULL}
12 +#define LINE_BUFFER_INIT { "", NULL }
13
14 int buffer_init(struct line_buffer *buf, const char *filename);
15 int buffer_fdinit(struct line_buffer *buf, int fd);
@@ -23,7 +22,6 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf);
22
23 int buffer_ferror(struct line_buffer *buf);
24 char *buffer_read_line(struct line_buffer *buf);
26 -char *buffer_read_string(struct line_buffer *buf, uint32_t len);
25 int buffer_read_char(struct line_buffer *buf);
26 void buffer_read_binary(struct line_buffer *buf, struct strbuf *sb, uint32_t len);
27 /* Returns number of bytes read (not necessarily written). */
vcs-svn/line_buffer.txt
+3 -9
@@ -16,8 +16,8 @@ The calling program:
16
17 - initializes a `struct line_buffer` to LINE_BUFFER_INIT
18 - specifies a file to read with `buffer_init`
19 - - processes input with `buffer_read_line`, `buffer_read_string`,
20 - `buffer_skip_bytes`, and `buffer_copy_bytes`
19 + - processes input with `buffer_read_line`, `buffer_skip_bytes`,
20 + and `buffer_copy_bytes`
21 - closes the file with `buffer_deinit`, perhaps to start over and
22 read another file.
23
@@ -37,7 +37,7 @@ the calling program. A program
37 the temporary file
38 - declares writing is over with `buffer_tmpfile_prepare_to_read`
39 - can re-read what was written with `buffer_read_line`,
40 - `buffer_read_string`, and so on
40 + `buffer_copy_bytes`, and so on
41 - can reuse the temporary file by calling `buffer_tmpfile_rewind`
42 again
43 - removes the temporary file with `buffer_deinit`, perhaps to
@@ -64,12 +64,6 @@ Functions
64 Read a line and strip off the trailing newline.
65 On failure or end of file, returns NULL.
66
67 -`buffer_read_string`::
68 - Read `len` characters of input or up to the end of the
69 - file, whichever comes first. Returns NULL on error.
70 - Returns whatever characters were read (possibly "")
71 - for end of file.
72 -
67 `buffer_copy_bytes`::
68 Read `len` bytes of input and dump them to the standard output
69 stream. Returns early for error or end of file.