summaryrefslogtreecommitdiffstats
path: root/sftp-client.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-12-04 03:41:10 +0100
committerDamien Miller <djm@mindrot.org>2020-12-04 03:43:01 +0100
commite4d1a0b40add800b6e9352b40c2223e44acc3a45 (patch)
tree5c6f615c562f21abebb4308824f7125c4ae9e98e /sftp-client.c
parentupstream: make ssh_free(NULL) a no-op (diff)
downloadopenssh-e4d1a0b40add800b6e9352b40c2223e44acc3a45.tar.xz
openssh-e4d1a0b40add800b6e9352b40c2223e44acc3a45.zip
upstream: shuffle a few utility functions into sftp-client.c; from
Jakub Jelen OpenBSD-Commit-ID: fdeb1aae1f6149b193f12cd2af158f948c514a2a
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/sftp-client.c b/sftp-client.c
index d82e31aee..4603b0098 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.c,v 1.138 2020/11/20 03:16:56 dtucker Exp $ */
+/* $OpenBSD: sftp-client.c,v 1.139 2020/12/04 02:41:10 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -1959,3 +1959,52 @@ path_append(const char *p1, const char *p2)
return(ret);
}
+char *
+make_absolute(char *p, const char *pwd)
+{
+ char *abs_str;
+
+ /* Derelativise */
+ if (p && !path_absolute(p)) {
+ abs_str = path_append(pwd, p);
+ free(p);
+ return(abs_str);
+ } else
+ return(p);
+}
+
+int
+remote_is_dir(struct sftp_conn *conn, const char *path)
+{
+ Attrib *a;
+
+ /* XXX: report errors? */
+ if ((a = do_stat(conn, path, 1)) == NULL)
+ return(0);
+ if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS))
+ return(0);
+ return(S_ISDIR(a->perm));
+}
+
+
+int
+local_is_dir(const char *path)
+{
+ struct stat sb;
+
+ /* XXX: report errors? */
+ if (stat(path, &sb) == -1)
+ return(0);
+
+ return(S_ISDIR(sb.st_mode));
+}
+
+/* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
+int
+globpath_is_dir(const char *pathname)
+{
+ size_t l = strlen(pathname);
+
+ return l > 0 && pathname[l - 1] == '/';
+}
+