From bf42081766a07842050e6dc8c4595d43b5358bbf Mon Sep 17 00:00:00 2001 From: Thomas Osterried Date: Thu, 22 Jan 2009 11:58:33 +0000 Subject: #BIN upload now preserves the file time. --- call/call.c | 27 +++++++++++++++++++++++++-- call/call.h | 1 + call/dostime.c | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) (limited to 'call') diff --git a/call/call.c b/call/call.c index 710f2f5..0e87a17 100644 --- a/call/call.c +++ b/call/call.c @@ -159,6 +159,20 @@ void convert_upper_lower(char *buf, int len) } } + +/* Convert linear UNIX date to a MS-DOS time/date pair. */ + +static char * unix_to_sfbin_date_string(time_t gmt) +{ + + static char buf[9]; + unsigned short s_time, s_date; + + date_unix2dos(((gmt == -1) ? time(0) : gmt), &s_time, &s_date); + sprintf(buf, "%X", ((s_date << 16) + s_time)); + return buf; +} + static int nr_convert_call(char *address, struct full_sockaddr_ax25 *addr) { char buffer[100], *call, *alias; @@ -1833,8 +1847,15 @@ int cmd_call(char *call[], int mode) case 'a': case 'A': { + struct stat statbuf; + time_t file_time = 0L; binup = TRUE; crc = 0; + if (!fstat(uploadfile, &statbuf)) + file_time = statbuf.st_mtime; + else + file_time = time(0); + do { upllen = @@ -1874,9 +1895,11 @@ int cmd_call(char *call[], int mode) 0L, SEEK_SET); sprintf(s, - "#BIN#%ld#$%u#|000000#%s\r", + "#BIN#%ld#|%u#$%s#%s\r", uplsize, - crc, t); + crc, + unix_to_sfbin_date_string(file_time), + t); write(fd, s, strlen(s)); uplpos = 0; diff --git a/call/call.h b/call/call.h index 5a7115d..bbc1fb4 100644 --- a/call/call.h +++ b/call/call.h @@ -16,5 +16,6 @@ extern void convert_lfcr(char *, int); extern void cmd_yapp(char *, int); /* In dostime.c */ +extern void date_unix2dos(time_t, unsigned short*, unsigned short*); extern int yapp2unix(char *); extern void unix2yapp( int, char *); diff --git a/call/dostime.c b/call/dostime.c index defbaf4..ea266a4 100644 --- a/call/dostime.c +++ b/call/dostime.c @@ -40,7 +40,7 @@ int date_dos2unix(unsigned short time, unsigned short date) /* Convert linear UNIX date to a MS-DOS time/date pair. */ -void date_unix2dos(int unix_date, unsigned short *time, +void date_unix2dos(time_t unix_date, unsigned short *time, unsigned short *date) { int day, year, nl_day, month; @@ -84,7 +84,7 @@ int yapp2unix(char *ytime) /* Convert unix time to 8 character yapp hex format */ -void unix2yapp(int unix_date, char *buffer) +void unix2yapp(time_t unix_date, char *buffer) { unsigned short time, date; date_unix2dos(unix_date, &time, &date); -- cgit v1.2.3