diff options
author | Miles Bader <miles@gnu.org> | 1997-05-07 21:01:07 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1997-05-07 21:01:07 +0000 |
commit | 44340c896186ee1265520855d2b8f74883ba8829 (patch) | |
tree | 9fc6bf01cf48fb461a1db22b47576a3e3f66c637 /libftpconn/stats.c | |
parent | 6abfa49b04ea7b5d4721871296959ad620be0c80 (diff) |
Initial checkin
Diffstat (limited to 'libftpconn/stats.c')
-rw-r--r-- | libftpconn/stats.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/libftpconn/stats.c b/libftpconn/stats.c new file mode 100644 index 00000000..d6e6ebd1 --- /dev/null +++ b/libftpconn/stats.c @@ -0,0 +1,85 @@ +/* Fetch file stats + + Copyright (C) 1997 Free Software Foundation, Inc. + + Written by Miles Bader <miles@gnu.ai.mit.edu> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <unistd.h> +#include <errno.h> + +#include <ftpconn.h> + +/* Start an operation to get a list of file-stat structures for NAME (this + is often similar to ftp_conn_start_dir, but with OS-specific flags), and + return a file-descriptor for reading on, and a state structure in STATE + suitable for passing to cont_get_stats. FORCE_DIR controls what happens if + NAME refers to a directory: if FORCE_DIR is false, STATS will contain + entries for all files *in* NAME, and if FORCE_DIR is true, it will + contain just a single entry for NAME itself (or an error will be + returned when this isn't possible). */ +error_t +ftp_conn_start_get_stats (struct ftp_conn *conn, + const char *name, int force_dir, + int *fd, void **state) +{ + if (conn->syshooks.start_get_stats) + return + (*conn->syshooks.start_get_stats) (conn, name, force_dir, fd, state); + else + return EOPNOTSUPP; +} + +/* Read stats information from FD, calling ADD_STAT for each new stat (HOOK + is passed to ADD_STAT). FD and STATE should be returned from + start_get_stats. If this function returns EAGAIN, then it should be + called again to finish the job (possibly after calling select on FD); if + it returns 0, then it is finishe,d and FD and STATE are deallocated. */ +error_t +ftp_conn_cont_get_stats (struct ftp_conn *conn, int fd, void *state, + ftp_conn_add_stat_fun_t add_stat, void *hook) +{ + if (conn->syshooks.cont_get_stats) + return (*conn->syshooks.cont_get_stats) (conn, fd, state, add_stat, hook); + else + return EOPNOTSUPP; +} + +/* Get a list of file-stat structures for NAME, calling ADD_STAT for each one + (HOOK is passed to ADD_STAT). If NAME refers to an ordinary file, a + single entry for it is returned for it; if NAME refers to a directory, + then if FORCE_DIR is false, STATS will contain entries for all files *in* + NAME, and if FORCE_DIR is true, it will contain just a single entry for + NAME itself (or an error will be returned when this isn't possible). This + function may block. */ +error_t +ftp_conn_get_stats (struct ftp_conn *conn, + const char *name, int force_dir, + ftp_conn_add_stat_fun_t add_stat, void *hook) +{ + int fd; + void *state; + error_t err = ftp_conn_start_get_stats (conn, name, force_dir, &fd, &state); + + if (err) + return err; + + do + err = ftp_conn_cont_get_stats (conn, fd, state, add_stat, hook); + while (err == EAGAIN); + + return err; +} |