.\" $OpenBSD: glob.3,v 1.21 2003/09/02 18:24:21 jmc Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Guido van Rossum. .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" Changes from OpenBSD glob(3) to fget's ftpglob(3) .\" Copyright (c) 2000-2004 Mark D. Roth .\" .TH ftp_glob 3 "January 2004" "Feep Networks" "C Library Calls" .SH NAME ftp_glob, ftp_globfree \- find pathnames matching a pattern from an FTP server .SH SYNOPSIS .B #include .BI "int ftp_glob(FTP *" ftp ", const char *" pattern "," .BI "int " flags ", int (*" errfunc ")(const char *, int)," .BI "ftp_glob_t *" pglob ");" .BI "void ftp_globfree(ftp_glob_t *" pglob ");" .SH VERSION This man page documents version 1.3 of \fBlibfget\fP. .SH DESCRIPTION The \fBftp_glob\fP() function searches for all the pathnames on the FTP server associated with \fIftp\fP that match \fIpattern\fP according to the rules used by the shell. The structure type \fBftp_glob_t\fP contains at least the following fields: .RS .nf typedef struct { int gl_pathc; /* count of total paths so far */ int gl_matchc; /* count of paths matching pattern */ int gl_offs; /* reserved at beginning of gl_pathv */ int gl_flags; /* returned flags */ char **gl_pathv; /* list of paths matching pattern */ } ftp_glob_t; .fi .RE The argument \fIpattern\fP is a pointer to a pathname pattern to be expanded. \fBftp_glob\fP() matches all accessible pathnames against the pattern and creates a list of the pathnames that match. In order to have access to a pathname, \fBftp_glob\fP() requires search permission on every component of a path except the last and read permission on each directory of any filename component of pattern that contains any of the special characters `*', `?', or `['. The number of matched pathnames is stored in the \fIgl_pathc\fP field, and a pointer to a list of pointers to pathnames in the \fIgl_pathv\fP field. The first pointer after the last pathname is \fBNULL\fP. If the pattern does not match any pathnames, the returned number of matched paths is set to zero. It is the caller's responsibility to create the structure pointed to by \fIpglob\fP. The \fBftp_glob\fP() function allocates other space as needed, including the memory pointed to by \fIgl_pathv\fP. The argument \fIflags\fP is used to modify the behavior of \fBftp_glob\fP(). The value of \fIflags\fP is the bitwise inclusive OR of any of the following values: .TP .B FTPGLOB_APPEND Append pathnames generated to the ones from a previous call (or calls) to \fBftp_glob\fP(). The value of \fIgl_pathc\fP will be the total matches found by this call and the previous call(s). The pathnames are appended to, not merged with the pathnames returned by the previous call(s). Between calls, the caller must not change the setting of the \fBFTPGLOB_DOOFFS\fP flag, nor change the value of \fIgl_offs\fP when \fBFTPGLOB_DOOFFS\fP is set, nor (obviously) call \fBftp_globfree\fP() for \fIpglob\fP. .TP .B FTPGLOB_DOOFFS Make use of the \fIgl_offs\fP field. If this flag is set, \fIgl_offs\fP is used to specify how many null pointers to prepend to the beginning of the \fIgl_pathv\fP field. In other words, \fIgl_pathv\fP will point to \fIgl_offs\fP null pointers, followed by \fIgl_pathc\fP pathname pointers, followed by a null pointer. .TP .B FTPGLOB_ERR Causes \fBftp_glob\fP() to return when it encounters a directory that it cannot open or read. Ordinarily, \fBftp_glob\fP() continues to find matches. .TP .B FTPGLOB_MARK Each pathname that is a directory that matches pattern has a slash appended. .TP .B FTPGLOB_NOCHECK If \fIpattern\fP does not match any pathname, then \fBftp_glob\fP() returns a list consisting of only \fIpattern\fP, with the number of total pathnames set to 1, and the number of matched pathnames set to 0. .TP .B FTPGLOB_NOESCAPE Normally, every occurrence of a backslash (`\\') followed by a character in \fIpattern\fP is replaced by that character. This is done to negate any special meaning for the character. If the \fBFTPGLOB_NOESCAPE\fP flag is set, a backslash character is treated as an ordinary character. .TP .B FTPGLOB_NOSORT By default, the pathnames are sorted in ascending ASCII order; this flag prevents that sorting (speeding up \fBftp_glob\fP()). .TP .B FTPGLOB_BRACE Pre-process the pattern string to expand `{pat,pat,...}' strings like \fBcsh\fP(1). The pattern `{}' is left unexpanded for historical reasons. (\fBcsh\fP(1) does the same thing to ease typing of \fBfind\fP(1) patterns.) .TP .B FTPGLOB_MAGCHAR Set by the \fBftp_glob\fP() function if the pattern included globbing characters. See the description of the usage of the \fIgl_matchc\fP structure member for more details. .TP .B FTPGLOB_NOMAGIC Is the same as \fBFTPGLOB_NOCHECK\fP, but it only appends the pattern if it does not contain any of the special characters `*', `?', or `['. \fBFTPGLOB_NOMAGIC\fP is provided to emulate the historic \fBcsh\fP(1) globbing behavior, and should probably not be used in most applications. .PP If, during the search, a directory is encountered that cannot be opened or read and \fIerrfunc\fP is non-null, \fBftp_glob\fP() calls \fI(*errfunc)(path, errno)\fP. This may be unintuitive: a pattern like ``*/Makefile'' will try to \fBstat\fP(2) ``foo/Makefile'' even if ``foo'' is not a directory, resulting in a call to \fIerrfunc\fP. The error routine can suppress this action by testing for \fBENOENT\fP and \fBENOTDIR\fP; however, the \fBFTPGLOB_ERR\fP flag will still cause an immediate return when this happens. If \fIerrfunc\fP returns non-zero, \fBftp_glob\fP() stops the scan and returns \fBFTPGLOB_ABORTED\fP after setting \fIgl_pathc\fP and \fIgl_pathv\fP to reflect any paths already matched. This also happens if an error is encountered and \fBFTPGLOB_ERR\fP is set in \fIflags\fP, regardless of the return value of \fIerrfunc\fP, if called. If \fBFTPGLOB_ERR\fP is not set and either \fIerrfunc\fP is \fBNULL\fP or \fIerrfunc\fP returns zero, the error is ignored. The \fBftp_globfree\fP() function frees any space associated with \fIpglob\fP from a previous call(s) to \fBftp_glob\fP(). .SH RETURN VALUES On successful completion, \fBftp_glob\fP() returns 0. In addition the fields of \fIpglob\fP contain the values described below: .TP .I gl_pathc Contains the total number of matched pathnames so far. This includes other matches from previous invocations of \fBftp_glob\fP() if \fBFTPGLOB_APPEND\fP was specified. .TP .I gl_matchc Contains the number of matched pathnames in the current invocation of \fBftp_glob\fP(). .TP .I gl_flags Contains a copy of the \fIflags\fP parameter with the bit \fBFTPGLOB_MAGCHAR\fP set if pattern contained any of the special characters `*', `?', or `[', cleared if not. .TP .I gl_pathv Contains a pointer to a null-terminated list of matched pathnames. However, if \fIgl_pathc\fP is zero, the contents of \fIgl_pathv\fP are undefined. .PP If \fBftp_glob\fP() terminates due to an error, it sets \fIerrno\fP and returns one of the following non-zero constants: .TP .B FTPGLOB_NOSPACE An attempt to allocate memory failed. .TP .B FTPGLOB_ABORTED The scan was stopped because an error was encountered and either \fBFTPGLOB_ERR\fP was set, or \fI(*errfunc)()\fP returned non-zero. .TP .B FTPGLOB_NOMATCH The pattern did not match a pathname and \fBFTPGLOB_NOCHECK\fP was not set. .PP The \fIpglob\fP fields \fIgl_pathc\fP and \fI_gl_pathv\fP are still set as specified above. .SH EXAMPLES The following code will find all matches for `*.c' and `*.h' on the FTP server associated with \fIftp\fP: .RS .nf int i; ftp_glob_t g; ftp_glob(ftp, "*.c", 0, NULL, &g); ftp_glob(ftp, "*.h", FTPGLOB_APPEND, NULL, &g); for (i = 0; i < g.gl_pathc; i++) printf("matching file: \\"%s\\"\\n", g.gl_pathv[i]); .fi .RE .SH ERRORS The \fBftp_glob\fP() function may fail and set \fIerrno\fP for any of the errors specified for any of the \fBftp_stat\fP(3), \fBftp_opendir\fP(3), \fBmalloc\fP(3), or \fBfree\fP(3) library calls. .SH BUGS Patterns longer than \fBMAXPATHLEN\fP may cause unchecked errors. .SH SEE ALSO .BR libfget (3), .BR glob (3)