fstests: fix compilation error in splice2pipe on old (<C99) compilers
PATCH 1/1 fstests: fix compilation error in splice2pipe on old (<C99) compilers
Compilation fails on system with compiler which uses older C dialect (e.g. RHEL7; gcc with gnu90) with:
splice2pipe.c: In function 'prepare_pipe':
splice2pipe.c:54:2: error: 'for' loop initial declarations are only allowed in C99 mode
for (unsigned r = pipe_size; r > 0;) {
Fix it by declaring 'r' outside of the loop.
--- src/splice2pipe.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
src/splice2pipe.c +3 -2
@@ -41,6 +41,7 @@*/ static void prepare_pipe (int p[2 ]) { +unsigned int r =0 ;if (pipe (p)) {perror ("pipe failed" );abort ();
@@ -51,7 +52,7 @@ static void prepare_pipe(int p[2])/* fill the pipe completely; each pipe_buffer will now have the PIPE_BUF_FLAG_CAN_MERGE flag */ -for (unsigned r = pipe_size; r >0 ;) { +for (r = pipe_size; r >0 ;) {unsigned n = r >sizeof (buffer) ?sizeof (buffer) : r;write (p[1 ], buffer, n); r -= n;
@@ -59,7 +60,7 @@ static void prepare_pipe(int p[2])/* drain the pipe, freeing all pipe_buffer instances (but leaving the flags initialized) */ -for (unsigned r = pipe_size; r >0 ;) { +for (r = pipe_size; r >0 ;) {unsigned n = r >sizeof (buffer) ?sizeof (buffer) : r;read (p[0 ], buffer, n); r -= n;
Signature · 1 line
2.31.1
Quoted 10 lines · Andrey Albershteyn
Compilation fails on system with compiler which uses older C dialect (e.g. RHEL7; gcc with gnu90) with:
splice2pipe.c: In function 'prepare_pipe':
splice2pipe.c:54:2: error: 'for' loop initial declarations are only allowed in C99 mode
for (unsigned r =pipe_size; r > 0;) {Fix it by declaring 'r' outside of the loop.
Signed-off-by Andrey Albershteyn <[email protected]>
Not sure if you need to zero-init the variable, but eh looks good to me
--D
Quoted 37 lines
--- src/splice2pipe.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)src/splice2pipe.c +3
-2@@ -41,6 +41,7 @@*/ static void prepare_pipe (int p[2 ]) { +unsigned int r =0 ;if (pipe (p)) {perror ("pipe failed" );abort ();@@ -51,7 +52,7 @@ static void prepare_pipe(int p[2])/* fill the pipe completely; each pipe_buffer will now have the PIPE_BUF_FLAG_CAN_MERGE flag */ -for (unsigned r = pipe_size; r >0 ;) { +for (r = pipe_size; r >0 ;) {unsigned n = r >sizeof (buffer) ?sizeof (buffer) : r;write (p[1 ], buffer, n); r -= n;@@ -59,7 +60,7 @@ static void prepare_pipe(int p[2])/* drain the pipe, freeing all pipe_buffer instances (but leaving the flags initialized) */ -for (unsigned r = pipe_size; r >0 ;) { +for (r = pipe_size; r >0 ;) {unsigned n = r >sizeof (buffer) ?sizeof (buffer) : r;read (p[0 ], buffer, n); r -= n;Signature · 1 line
2.31.1