summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/ftp.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1998-11-05 19:48:17 +0000
committerdes <des@FreeBSD.org>1998-11-05 19:48:17 +0000
commite9582417392ed244d57d8d625ab335a3589831fe (patch)
treef937a3458c7c3f4987fe77d8a77a47b948807065 /lib/libfetch/ftp.c
parent58045d2d2c66cc826418c2c40735d7130c308a14 (diff)
downloadFreeBSD-src-e9582417392ed244d57d8d625ab335a3589831fe.zip
FreeBSD-src-e9582417392ed244d57d8d625ab335a3589831fe.tar.gz
First of a series of cleanups to libfetch. Changed files, in
alphabetical order: Makefile: Add common.c to SRCS. Make debugging easier by making 'CFLAGS += -DNDEBUG' conditional on DEBUG Don't declare struct {ftp,http}err in {ftp,http}err.c; use struct fetcherr instead. README: Remove the todo list, which is out of date anyway. common.c: (new file) Gather utility functions in this file. Merge the error reporting functions intp _fetch_errstring(), _fetch_seterr() and _fetch_syserr(). Set fetchLastErrCode and fetchLastErrText appropriately when fetchConnect fails. common.h: (new file) Gather internal prototypes and structures in this files. fetch.3: Undocument fetchFreeURL(). Document a few more known bugs. Document fetchLastErrCode and fetchLastErrText. fetch.c: Add descriptive comments to all functions that lacked them. Move fetchConnect() to common.c. Obviate the need for fetchFreeURL(), and remove it. fetch.h: Modify struct url_t so the document part is at the end. ftp.c: Remove code that is duplicated elsewhere. http.c: Remove code that is duplicated elsewhere. Prompted by: jkh
Diffstat (limited to 'lib/libfetch/ftp.c')
-rw-r--r--lib/libfetch/ftp.c47
1 files changed, 7 insertions, 40 deletions
diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c
index d66b7c3..1899d03 100644
--- a/lib/libfetch/ftp.c
+++ b/lib/libfetch/ftp.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: ftp.c,v 1.4 1998/07/12 22:34:39 des Exp $
+ * $Id: ftp.c,v 1.5 1998/08/17 09:30:19 des Exp $
*/
/*
@@ -70,6 +70,7 @@
#include <unistd.h>
#include "fetch.h"
+#include "common.h"
#include "ftperr.c"
#define FTP_DEFAULT_TO_ANONYMOUS
@@ -93,40 +94,6 @@ static FILE *cached_socket;
static char *_ftp_last_reply;
/*
- * Map error code to string
- */
-static const char *
-_ftp_errstring(int e)
-{
- struct ftperr *p = _ftp_errlist;
-
- while ((p->num != -1) && (p->num != e))
- p++;
-
- return p->string;
-}
-
-/*
- * Set error code
- */
-static void
-_ftp_seterr(int e)
-{
- fetchLastErrCode = e;
- fetchLastErrText = _ftp_errstring(e);
-}
-
-/*
- * Set error code according to errno
- */
-static void
-_ftp_syserr(void)
-{
- fetchLastErrCode = errno;
- fetchLastErrText = strerror(errno);
-}
-
-/*
* Get server response, check that first digit is a '2'
*/
static int
@@ -140,7 +107,7 @@ _ftp_chkerr(FILE *s, int *e)
do {
if (((line = fgetln(s, &len)) == NULL) || (len < 4)) {
- _ftp_syserr();
+ _fetch_syserr();
return -1;
}
} while (line[3] == '-');
@@ -217,7 +184,7 @@ _ftp_transfer(FILE *cf, char *oper, char *file, char *mode, int pasv)
/* open data socket */
if ((sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
- _ftp_syserr();
+ _fetch_syserr();
return NULL;
}
@@ -296,7 +263,7 @@ _ftp_transfer(FILE *cf, char *oper, char *file, char *mode, int pasv)
return df;
sysouch:
- _ftp_syserr();
+ _fetch_syserr();
ouch:
close(sd);
return NULL;
@@ -330,13 +297,13 @@ _ftp_connect(char *host, int port, char *user, char *pwd)
/* check connection */
if (sd == -1) {
- _ftp_syserr();
+ _fetch_syserr();
return NULL;
}
/* streams make life easier */
if ((f = fdopen(sd, "r+")) == NULL) {
- _ftp_syserr();
+ _fetch_syserr();
goto ouch;
}
OpenPOWER on IntegriCloud