* replace ifdefs against __SVR4 and __linux__ with DIRENT_MISSING_D_NAMLEN;

it's more portable and more obvious
* remove the mkgmtime() && HAVE_TIMEGM stuff:
	a) why should netbsd have to define HAVE_TIMEGM to compile cleanly?
	b) foreign compiles of ftp should just be linked with working
	   timegm function

a more portable version of this ftp client will be released as a 3rdparty
product; no use polluting our code with half-baked attempts...
This commit is contained in:
lukem 1999-09-26 02:00:12 +00:00
parent accf01ad1d
commit 75e3195cad
5 changed files with 11 additions and 147 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.20 1999/07/02 08:07:40 itojun Exp $
# $NetBSD: Makefile,v 1.21 1999/09/26 02:00:12 lukem Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
PROG= ftp
@ -9,7 +9,6 @@ SRCS= cmds.c cmdtab.c complete.c domacro.c fetch.c ftp.c main.c ruserpass.c \
#
#CPPFLAGS+=-DGATE_SERVER=\"ftp-gw.host\" # -DGATE_PORT=21
CPPFLAGS+= -DHAVE_TIMEGM # system has timegm(3), a UTC version of mktime
LDADD+= -ledit -ltermcap -lutil
DPADD+= ${LIBEDIT} ${LIBTERMCAP} ${LIBUTIL}

View File

@ -1,4 +1,4 @@
/* $NetBSD: complete.c,v 1.29 1999/09/24 14:28:14 lukem Exp $ */
/* $NetBSD: complete.c,v 1.30 1999/09/26 02:00:12 lukem Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: complete.c,v 1.29 1999/09/24 14:28:14 lukem Exp $");
__RCSID("$NetBSD: complete.c,v 1.30 1999/09/26 02:00:12 lukem Exp $");
#endif /* not lint */
/*
@ -220,7 +220,7 @@ complete_local(word, list)
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
continue;
#if defined(__SVR4) || defined(__linux__)
#if defined(DIRENT_MISSING_D_NAMLEN)
if (len > strlen(dp->d_name))
continue;
#else

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.35 1999/09/22 07:18:32 lukem Exp $ */
/* $NetBSD: extern.h,v 1.36 1999/09/26 02:00:12 lukem Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@ -123,7 +123,6 @@ void makeargv __P((void));
void makedir __P((int, char **));
void mdelete __P((int, char **));
void mget __P((int, char **));
time_t mkgmtime __P((struct tm *));
void mls __P((int, char **));
void modtime __P((int, char **));
void mput __P((int, char **));

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.75 1999/09/24 14:28:14 lukem Exp $ */
/* $NetBSD: fetch.c,v 1.76 1999/09/26 02:00:12 lukem Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: fetch.c,v 1.75 1999/09/24 14:28:14 lukem Exp $");
__RCSID("$NetBSD: fetch.c,v 1.76 1999/09/26 02:00:12 lukem Exp $");
#endif /* not lint */
/*
@ -881,7 +881,7 @@ fetch_url(url, proxyenv, proxyauth, wwwauth)
&parsed))) {
parsed.tm_isdst = -1;
if (*t == '\0')
mtime = mkgmtime(&parsed);
mtime = timegm(&parsed);
if (debug && mtime != -1) {
fprintf(ttyout,
"parsed date as: %s",

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.60 1999/09/24 14:28:14 lukem Exp $ */
/* $NetBSD: util.c,v 1.61 1999/09/26 02:00:12 lukem Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.60 1999/09/24 14:28:14 lukem Exp $");
__RCSID("$NetBSD: util.c,v 1.61 1999/09/26 02:00:12 lukem Exp $");
#endif /* not lint */
/*
@ -106,10 +106,6 @@ __RCSID("$NetBSD: util.c,v 1.60 1999/09/24 14:28:14 lukem Exp $");
#include "ftp_var.h"
#include "pathnames.h"
#ifndef HAVE_TIMEGM
static time_t sub_mkgmt __P((struct tm *tm));
#endif
/*
* Connect to peer server and
* auto-login, if possible.
@ -610,7 +606,7 @@ remotemodtime(file, noisy)
timebuf.tm_mon = mo - 1;
timebuf.tm_year = yy - TM_YEAR_BASE;
timebuf.tm_isdst = -1;
rtime = mkgmtime(&timebuf);
rtime = timegm(&timebuf);
if (rtime == -1 && (noisy || debug != 0))
fprintf(ttyout, "Can't convert %s to a time.\n",
reply_string);
@ -624,136 +620,6 @@ remotemodtime(file, noisy)
return (rtime);
}
/*
* UTC version of mktime(3)
*/
#ifdef HAVE_TIMEGM
time_t
mkgmtime(tm)
struct tm *tm;
{
/* This is very clean, but not portable at all. */
return (timegm(tm));
}
#else /* not HAVE_TIMEGM */
/*
* This code is not portable, but works on most Unix-like systems.
* If the local timezone has no summer time, using mktime(3) function
* and adjusting offset would be usable (adjusting leap seconds
* is still required, though), but the assumption is not always true.
*
* Anyway, no portable and correct implementation of UTC to time_t
* conversion exists....
*/
static time_t
sub_mkgmt(tm)
struct tm *tm;
{
int y, nleapdays;
time_t t;
/* days before the month */
static const unsigned short moff[12] = {
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
};
/*
* XXX: This code assumes the given time to be normalized.
* Normalizing here is impossible in case the given time is a leap
* second but the local time library is ignorant of leap seconds.
*/
/* minimal sanity checking not to access outside of the array */
if ((unsigned) tm->tm_mon >= 12)
return (time_t) -1;
if (tm->tm_year < EPOCH_YEAR - TM_YEAR_BASE)
return (time_t) -1;
y = tm->tm_year + TM_YEAR_BASE - (tm->tm_mon < 2);
nleapdays = y / 4 - y / 100 + y / 400 -
((EPOCH_YEAR-1) / 4 - (EPOCH_YEAR-1) / 100 + (EPOCH_YEAR-1) / 400);
t = ((((time_t) (tm->tm_year - (EPOCH_YEAR - TM_YEAR_BASE)) * 365 +
moff[tm->tm_mon] + tm->tm_mday - 1 + nleapdays) * 24 +
tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
return (t < 0 ? (time_t) -1 : t);
}
time_t
mkgmtime(tm)
struct tm *tm;
{
time_t t, t2;
struct tm *tm2;
int sec;
/* Do the first guess. */
if ((t = sub_mkgmt(tm)) == (time_t) -1)
return (time_t) -1;
/* save value in case *tm is overwritten by gmtime() */
sec = tm->tm_sec;
tm2 = gmtime(&t);
if ((t2 = sub_mkgmt(tm2)) == (time_t) -1)
return (time_t) -1;
if (t2 < t || tm2->tm_sec != sec) {
/*
* Adjust for leap seconds.
*
* real time_t time
* |
* tm
* / ... (a) first sub_mkgmt() conversion
* t
* |
* tm2
* / ... (b) second sub_mkgmt() conversion
* t2
* --->time
*/
/*
* Do the second guess, assuming (a) and (b) are almost equal.
*/
t += t - t2;
tm2 = gmtime(&t);
/*
* Either (a) or (b), may include one or two extra
* leap seconds. Try t, t + 2, t - 2, t + 1, and t - 1.
*/
if (tm2->tm_sec == sec
|| (t += 2, tm2 = gmtime(&t), tm2->tm_sec == sec)
|| (t -= 4, tm2 = gmtime(&t), tm2->tm_sec == sec)
|| (t += 3, tm2 = gmtime(&t), tm2->tm_sec == sec)
|| (t -= 2, tm2 = gmtime(&t), tm2->tm_sec == sec))
; /* found */
else {
/*
* Not found.
*/
if (sec >= 60)
/*
* The given time is a leap second
* (sec 60 or 61), but the time library
* is ignorant of the leap second.
*/
; /* treat sec 60 as 59,
sec 61 as 0 of the next minute */
else
/* The given time may not be normalized. */
t++; /* restore t */
}
}
return (t < 0 ? (time_t) -1 : t);
}
#endif /* not HAVE_TIMEGM */
#ifndef NO_PROGRESS
/*