@@ -93,32 +93,28 @@ static void syscall_write(riscv_t *rv)
9393 /* lookup the file descriptor */
9494 map_iter_t it ;
9595 map_find (attr -> fd_map , & it , & fd );
96+ if (map_at_end (attr -> fd_map , & it ))
97+ goto error_handler ;
98+
9699 uint32_t total_write = 0 ;
100+ FILE * handle = map_iter_value (& it , FILE * );
97101
98102 while (count > PREALLOC_SIZE ) {
99103 memory_read (attr -> mem , tmp , buffer + total_write , PREALLOC_SIZE );
100- if (!map_at_end (attr -> fd_map , & it )) {
101- /* write out the data */
102- FILE * handle = map_iter_value (& it , FILE * );
103- size_t written = fwrite (tmp , 1 , PREALLOC_SIZE , handle );
104- if (written != PREALLOC_SIZE && ferror (handle ))
105- goto error_handler ;
106- total_write += written ;
107- count -= PREALLOC_SIZE ;
108- } else
104+ /* write out the data */
105+ size_t written = fwrite (tmp , 1 , PREALLOC_SIZE , handle );
106+ if (written != PREALLOC_SIZE && ferror (handle ))
109107 goto error_handler ;
108+ total_write += written ;
109+ count -= PREALLOC_SIZE ;
110110 }
111111
112112 memory_read (attr -> mem , tmp , buffer + total_write , count );
113- if (!map_at_end (attr -> fd_map , & it )) {
114- /* write out the data */
115- FILE * handle = map_iter_value (& it , FILE * );
116- size_t written = fwrite (tmp , 1 , count , handle );
117- if (written != count && ferror (handle ))
118- goto error_handler ;
119- total_write += written ;
120- } else
113+ /* write out the data */
114+ size_t written = fwrite (tmp , 1 , count , handle );
115+ if (written != count && ferror (handle ))
121116 goto error_handler ;
117+ total_write += written ;
122118 assert (total_write == rv_get_reg (rv , rv_reg_a2 ));
123119
124120 /* return number of bytes written */
0 commit comments