tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Initial MirBSD support for pkgsrc



On Sat, 15 Jan 2011, Thorsten Glaser wrote:

Benny Siegert dixit:

net/libfetch/files/ftp.c: On some operating systems (notably MirBSD), the
        tm_year member in struct tm is a long, not an int. The package

This is wrong, itâs actually a time_t because some applications, most
notably GNU CVSâ configure script (via gnulib), depend on being able
to have a lossless round-trip conversion of any value of time_t to
struct tm and back.

        tools already have support for this, libfetch does not. Here, use
        a temporary variable to read in the year so the length is known.

This patch is correct, for int values of tm_year.

net/libfetch/files/http.c: Same issue as above; cast tm_year to a long
        before printing it.

-           tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
+           (long)tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);

I think (long)(tm.tm_year + 1900) would be better. Or casting to int,
which can be changed to int64_t if pkgsrc is still around by then.
Casting to long involves quite some overhead on current LP64 platforms.

Okay, here is a revised libfetch.diff to go along with the other two patches from Jan 15.

--Benny.
Index: net/libfetch/files/ftp.c
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/ftp.c,v
retrieving revision 1.36
diff -u -d -r1.36 ftp.c
--- net/libfetch/files/ftp.c    20 Aug 2010 17:56:49 -0000      1.36
+++ net/libfetch/files/ftp.c    28 Dec 2010 15:38:07 -0000
@@ -464,7 +464,7 @@
 {
        char *ln;
        const char *filename;
-       int filenamelen, type;
+       int filenamelen, type, year;
        struct tm tm;
        time_t t;
        int e;
@@ -516,13 +516,13 @@
                return (-1);
        }
        if (sscanf(ln, "%04d%02d%02d%02d%02d%02d",
-           &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+           &year, &tm.tm_mon, &tm.tm_mday,
            &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
                ftp_seterr(FTP_PROTOCOL_ERROR);
                return (-1);
        }
        tm.tm_mon--;
-       tm.tm_year -= 1900;
+       tm.tm_year = year - 1900;
        tm.tm_isdst = -1;
        t = timegm(&tm);
        if (t == (time_t)-1)
Index: net/libfetch/files/http.c
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/http.c,v
retrieving revision 1.29
diff -u -d -r1.29 http.c
--- net/libfetch/files/http.c   24 Jan 2010 19:10:35 -0000      1.29
+++ net/libfetch/files/http.c   28 Dec 2010 15:38:08 -0000
@@ -797,9 +797,9 @@
        struct tm tm;
        char buf[80];
        gmtime_r(&last_modified, &tm);
-       snprintf(buf, sizeof(buf), "%.3s, %02d %.3s %4d %02d:%02d:%02d GMT",
+       snprintf(buf, sizeof(buf), "%.3s, %02d %.3s %4ld %02d:%02d:%02d GMT",
            weekdays + tm.tm_wday * 3, tm.tm_mday, months + tm.tm_mon * 3,
-           tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
+           (long)(tm.tm_year + 1900), tm.tm_hour, tm.tm_min, tm.tm_sec);
        http_cmd(conn, "If-Modified-Since: %s\r\n", buf);
 }
 


Home | Main Index | Thread Index | Old Index