2 /* $OpenBSD: sftp-glob.c,v 1.22 2006/08/03 03:34:42 deraadt Exp $ */
4 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 __RCSID("$NetBSD: sftp-glob.c,v 1.13 2006/09/28 21:22:15 christos Exp $");
21 #include <sys/types.h>
31 #include "sftp-common.h"
32 #include "sftp-client.h"
34 int remote_glob(struct sftp_conn
*, const char *, int,
35 int (*)(const char *, int), glob_t
*);
43 struct sftp_conn
*conn
;
47 fudge_opendir(const char *path
)
49 struct SFTP_OPENDIR
*r
;
51 r
= xmalloc(sizeof(*r
));
53 if (do_readdir(cur
.conn
, (char *)path
, &r
->dir
)) {
63 static struct dirent
*
64 fudge_readdir(struct SFTP_OPENDIR
*od
)
66 static struct dirent ret
;
68 if (od
->dir
[od
->offset
] == NULL
)
71 memset(&ret
, 0, sizeof(ret
));
72 strlcpy(ret
.d_name
, od
->dir
[od
->offset
++]->filename
,
79 fudge_closedir(struct SFTP_OPENDIR
*od
)
81 free_sftp_dirents(od
->dir
);
86 fudge_lstat(const char *path
, struct stat
*st
)
90 if (!(a
= do_lstat(cur
.conn
, (char *)path
, 0)))
93 attrib_to_stat(a
, st
);
99 fudge_stat(const char *path
, struct stat
*st
)
103 if (!(a
= do_stat(cur
.conn
, (char *)path
, 0)))
106 attrib_to_stat(a
, st
);
112 remote_glob(struct sftp_conn
*conn
, const char *pattern
, int flags
,
113 int (*errfunc
)(const char *, int), glob_t
*pglob
)
115 pglob
->gl_opendir
= fudge_opendir
;
116 pglob
->gl_readdir
= (struct dirent
*(*)(void *))fudge_readdir
;
117 pglob
->gl_closedir
= (void (*)(void *))fudge_closedir
;
118 pglob
->gl_lstat
= fudge_lstat
;
119 pglob
->gl_stat
= fudge_stat
;
121 memset(&cur
, 0, sizeof(cur
));
124 return(glob(pattern
, flags
| GLOB_ALTDIRFUNC
, errfunc
, pglob
));