src/t_enospc.c: Fix an error for the loop initialization declaration
authorFeiyu Zhu <zhufy.jy@cn.fujitsu.com>
Thu, 10 Dec 2020 02:59:54 +0000 (21:59 -0500)
committerEryu Guan <guaneryu@gmail.com>
Sun, 20 Dec 2020 16:18:43 +0000 (00:18 +0800)
When I compiled xfstests using the gcc(version 4.8.5), the following error occurred:
t_enospc.c: In function 'enospc_test':
t_enospc.c:88:2: error: 'for' loop initial declarations are only allowed in C99 mode
  for (int i = 0; i < size; i++) {
  ^

Signed-off-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
Reviewed-by: Ritesh Harjani <riteshh@linux.ibm.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/t_enospc.c

index d06c6764c581f31bd63e204cbadc2a07d57277cc..4070ea51666ff15dc03dd3e2fef5feca820e03bb 100644 (file)
@@ -44,6 +44,7 @@ void handle_sigbus(int sig)
 
 void enospc_test(int id)
 {
+       int i;
        int fd;
        char fpath[255] = {0};
        char *addr;
@@ -85,7 +86,7 @@ void enospc_test(int id)
        addr = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, 0);
        assert(addr != MAP_FAILED);
 
-       for (int i = 0; i < size; i++) {
+       for (i = 0; i < size; i++) {
                addr[i] = 0xAB;
        }
 
@@ -104,10 +105,11 @@ void *spawn_test_thread(void *arg)
 
 void _run_test(int threads)
 {
+       int i;
        pthread_t tid[threads];
 
        pthread_barrier_init(&bar, NULL, threads+1);
-       for (int i = 0; i < threads; i++) {
+       for (i = 0; i < threads; i++) {
                struct thread_s *thread_info = (struct thread_s *) malloc(sizeof(struct thread_s));
                thread_info->id = i;
                assert(pthread_create(&tid[i], NULL, spawn_test_thread, thread_info) == 0);
@@ -115,7 +117,7 @@ void _run_test(int threads)
 
        pthread_barrier_wait(&bar);
 
-       for (int i = 0; i <threads; i++) {
+       for (i = 0; i < threads; i++) {
                assert(pthread_join(tid[i], NULL) == 0);
        }