0b26f7
commit 52d0119743180164d1664b6773ac5d873f224608
0b26f7
Author: Jiaxun Yang <jiaxun.yang@flygoat.com>
0b26f7
Date:   Tue Sep 7 13:31:42 2021 +0800
0b26f7
0b26f7
    MIPS: Setup errno for {f,l,}xstat
0b26f7
    
0b26f7
    {f,l,}xstat stub for MIPS is using INTERNAL_SYSCALL
0b26f7
    to do xstat syscall for glibc ver, However it leaves
0b26f7
    errno untouched and thus giving bad errno output.
0b26f7
    
0b26f7
    Setup errno properly when syscall returns non-zero.
0b26f7
    
0b26f7
    Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
0b26f7
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
0b26f7
    
0b26f7
    (cherry picked from commit 66016ec8aeefd40e016d7040d966484c764b0e9c)
0b26f7
0b26f7
diff --git a/sysdeps/unix/sysv/linux/mips/fxstat.c b/sysdeps/unix/sysv/linux/mips/fxstat.c
0b26f7
index 11511d30b38708ce..4a6016ff123e8dd9 100644
0b26f7
--- a/sysdeps/unix/sysv/linux/mips/fxstat.c
0b26f7
+++ b/sysdeps/unix/sysv/linux/mips/fxstat.c
0b26f7
@@ -35,7 +35,9 @@ __fxstat (int vers, int fd, struct stat *buf)
0b26f7
       {
0b26f7
 	struct kernel_stat kbuf;
0b26f7
 	int r = INTERNAL_SYSCALL_CALL (fstat, fd, &kbuf);
0b26f7
-	return r ?: __xstat_conv (vers, &kbuf, buf);
0b26f7
+	if (r == 0)
0b26f7
+	  return  __xstat_conv (vers, &kbuf, buf);
0b26f7
+	return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
0b26f7
       }
0b26f7
     }
0b26f7
 }
0b26f7
diff --git a/sysdeps/unix/sysv/linux/mips/lxstat.c b/sysdeps/unix/sysv/linux/mips/lxstat.c
0b26f7
index 871fb6c6c5886665..54f990a250677091 100644
0b26f7
--- a/sysdeps/unix/sysv/linux/mips/lxstat.c
0b26f7
+++ b/sysdeps/unix/sysv/linux/mips/lxstat.c
0b26f7
@@ -35,7 +35,9 @@ __lxstat (int vers, const char *name, struct stat *buf)
0b26f7
       {
0b26f7
 	struct kernel_stat kbuf;
0b26f7
 	int r = INTERNAL_SYSCALL_CALL (lstat, name, &kbuf);
0b26f7
-	return r ?: __xstat_conv (vers, &kbuf, buf);
0b26f7
+	if (r == 0)
0b26f7
+	  return  __xstat_conv (vers, &kbuf, buf);
0b26f7
+	return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
0b26f7
       }
0b26f7
     }
0b26f7
 }
0b26f7
diff --git a/sysdeps/unix/sysv/linux/mips/xstat.c b/sysdeps/unix/sysv/linux/mips/xstat.c
0b26f7
index 9d810b6f653b964b..86f4dc31a82ff1bb 100644
0b26f7
--- a/sysdeps/unix/sysv/linux/mips/xstat.c
0b26f7
+++ b/sysdeps/unix/sysv/linux/mips/xstat.c
0b26f7
@@ -35,7 +35,9 @@ __xstat (int vers, const char *name, struct stat *buf)
0b26f7
       {
0b26f7
 	struct kernel_stat kbuf;
0b26f7
 	int r = INTERNAL_SYSCALL_CALL (stat, name, &kbuf);
0b26f7
-	return r ?: __xstat_conv (vers, &kbuf, buf);
0b26f7
+	if (r == 0)
0b26f7
+	  return  __xstat_conv (vers, &kbuf, buf);
0b26f7
+	return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
0b26f7
       }
0b26f7
     }
0b26f7
 }