To be able to move the errno handling code out of syscall.c,
first refactor the target_to_host_errno_table[] initialization
as a new init() function.

Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org>
---
 linux-user/syscall.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 64bbf331b28..33b7fef12a8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -509,8 +509,10 @@ static inline int next_free_host_timer(void)
 
 #define ERRNO_TABLE_SIZE 1200
 
-/* target_to_host_errno_table[] is initialized from
- * host_to_target_errno_table[] in syscall_init(). */
+/*
+ * target_to_host_errno_table[] is initialized from
+ * host_to_target_errno_table[] in target_to_host_errno_table_init().
+ */
 static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = {
 };
 
@@ -637,6 +639,17 @@ static uint16_t 
host_to_target_errno_table[ERRNO_TABLE_SIZE] = {
 #endif
 };
 
+static void target_to_host_errno_table_init(void)
+{
+    /*
+     * Build target_to_host_errno_table[] table
+     * from host_to_target_errno_table[].
+     */
+    for (int i = 0; i < ERRNO_TABLE_SIZE; i++) {
+        target_to_host_errno_table[host_to_target_errno_table[i]] = i;
+    }
+}
+
 static inline int host_to_target_errno(int err)
 {
     if (err >= 0 && err < ERRNO_TABLE_SIZE &&
@@ -7102,7 +7115,6 @@ void syscall_init(void)
     IOCTLEntry *ie;
     const argtype *arg_type;
     int size;
-    int i;
 
     thunk_init(STRUCT_MAX);
 
@@ -7112,11 +7124,7 @@ void syscall_init(void)
 #undef STRUCT
 #undef STRUCT_SPECIAL
 
-    /* Build target_to_host_errno_table[] table from
-     * host_to_target_errno_table[]. */
-    for (i = 0; i < ERRNO_TABLE_SIZE; i++) {
-        target_to_host_errno_table[host_to_target_errno_table[i]] = i;
-    }
+    target_to_host_errno_table_init();
 
     /* we patch the ioctl size if necessary. We rely on the fact that
        no ioctl has all the bits at '1' in the size field */
-- 
2.31.1


Reply via email to