[PATCH] utimes: constify path

Mike Frysinger vapier at gentoo.org
Fri Feb 25 04:54:36 AEDT 2022


From: Mike Frysinger <vapier at chromium.org>

The standard C API uses a const string, and code in OpenSSH call this
with const strings, so fix the function definition to match.  Otherwise:

sftp-client.c:1716:15: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                        if (utimes(local_path, tv) == -1)
                                   ^~~~~~~~~~
./openbsd-compat/bsd-misc.h:65:18: note: passing argument to parameter here
int utimes(char *, struct timeval *);
                 ^
sftp-client.c:1828:15: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                        if (utimes(dst, tv) == -1)
                                   ^~~
./openbsd-compat/bsd-misc.h:65:18: note: passing argument to parameter here
int utimes(char *, struct timeval *);
                 ^
2 warnings generated.
---
 openbsd-compat/bsd-misc.c | 2 +-
 openbsd-compat/bsd-misc.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 059b6d3b3ec7..d9c9b2671ef7 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -107,7 +107,7 @@ const char *strerror(int e)
 #endif
 
 #ifndef HAVE_UTIMES
-int utimes(char *filename, struct timeval *tvp)
+int utimes(const char *filename, struct timeval *tvp)
 {
 	struct utimbuf ub;
 
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 2206e1a82140..61ead1b7fad0 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -62,7 +62,7 @@ struct timeval {
 }
 #endif /* HAVE_STRUCT_TIMEVAL */
 
-int utimes(char *, struct timeval *);
+int utimes(const char *, struct timeval *);
 #endif /* HAVE_UTIMES */
 
 #ifndef AT_FDCWD
-- 
2.34.1



More information about the openssh-unix-dev mailing list