diff mbox series

[uclibc-ng-devel] NFC: Don't put function def inside function def

Message ID 20240909045326.13132-1-dm.chestnykh@gmail.com
State New
Headers show
Series [uclibc-ng-devel] NFC: Don't put function def inside function def | expand

Commit Message

Dmitry Chestnykh Sept. 9, 2024, 4:53 a.m. UTC
clang rejects the code where function body is placed
inside body of another function

Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
---
 libc/sysdeps/linux/common/rename.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Max Filippov Sept. 9, 2024, 5:23 a.m. UTC | #1
On Sun, Sep 8, 2024 at 9:57 PM Dmitry Chestnykh <dm.chestnykh@gmail.com> wrote:
>
> clang rejects the code where function body is placed
> inside body of another function
>
> Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
> ---
>  libc/sysdeps/linux/common/rename.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libc/sysdeps/linux/common/rename.c b/libc/sysdeps/linux/common/rename.c
> index 613ae4e44..821467e3c 100644
> --- a/libc/sysdeps/linux/common/rename.c
> +++ b/libc/sysdeps/linux/common/rename.c
> @@ -18,10 +18,12 @@ int rename(const char *oldpath, const char *newpath)
>  }
>  #elif defined __NR_renameat2
>  # include <fcntl.h>
> +
> +_syscall5(int, renameat2, int, olddfd, const char *, oldpath,
> +               int, newdfd, const char *, newpath, int, flags)
> +
>  int rename(const char *oldpath, const char *newpath)
>  {
> -       _syscall5(int, renameat2, int, olddfd, const char *, oldpath,
> -                 int, newdfd, const char *, newpath, int, flags)
>         return renameat2(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
>  }

I wonder why this duplication is needed at all, in the #if block above
rename() is implemented via renameat(), and renameat() already
wraps both renameat and renameat2 syscalls. Could this #else block
just be collapsed with the above #if?
diff mbox series

Patch

diff --git a/libc/sysdeps/linux/common/rename.c b/libc/sysdeps/linux/common/rename.c
index 613ae4e44..821467e3c 100644
--- a/libc/sysdeps/linux/common/rename.c
+++ b/libc/sysdeps/linux/common/rename.c
@@ -18,10 +18,12 @@  int rename(const char *oldpath, const char *newpath)
 }
 #elif defined __NR_renameat2
 # include <fcntl.h>
+
+_syscall5(int, renameat2, int, olddfd, const char *, oldpath,
+		int, newdfd, const char *, newpath, int, flags)
+
 int rename(const char *oldpath, const char *newpath)
 {
-	_syscall5(int, renameat2, int, olddfd, const char *, oldpath,
-		  int, newdfd, const char *, newpath, int, flags)
 	return renameat2(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
 }
 #else