Commit b04ef410 authored by Dave Hart's avatar Dave Hart

Remove remaining sprintf() calls except refclock_ripencc.c ...

...(which is kept out of --enable-all-clocks as a result), upstream
libs which use sprintf() ony after careful buffer sizing, and
ntp_proto.c.
parent b45c5f54
* Remove never-used, incomplete ports/winnt/ntpd/refclock_trimbledc.[ch]
* On systems without C99-compliant (v)snprintf(), use C99-snprintf
replacements (http://www.jhweiss.de/software/snprintf.html)
* Remove remaining sprintf() calls except refclock_ripencc.c (which is
kept out of --enable-all-clocks as a result), upstream libs which use
sprintf() ony after careful buffer sizing, and ntp_proto.c.
(4.2.7p149) 2011/04/11 Released by Harlan Stenn <stenn@ntp.org>
* [Bug 1881] describe the {+,-,s} characters in configure --help output.
(4.2.7p148) 2011/04/09 Released by Harlan Stenn <stenn@ntp.org>
......
......@@ -895,12 +895,6 @@ case "$ac_cv_func_recvmsg" in
esac
esac
case "$host" in
*-*-sunos4*)
AC_DEFINE([SPRINTF_CHAR], [1], [*s*printf() functions are char*])
;;
esac
AC_CACHE_CHECK(
[number of arguments taken by setpgrp()],
[ntp_cv_func_setpgrp_nargs],
......
......@@ -49,7 +49,6 @@ noinst_HEADERS = \
ntp_request.h \
ntp_rfc2553.h \
ntp_select.h \
ntp_sprintf.h \
ntp_stdlib.h \
ntp_string.h \
ntp_syscall.h \
......
/*
* Handle ancient char* *s*printf*() systems
*/
#ifdef SPRINTF_CHAR
# define SPRINTF(x) strlen(sprintf/**/x)
# define SNPRINTF(x) strlen(snprintf/**/x)
# define VSNPRINTF(x) strlen(vsnprintf/**/x)
#else
# define SPRINTF(x) ((size_t)sprintf x)
# define SNPRINTF(x) ((size_t)snprintf x)
# define VSNPRINTF(x) ((size_t)vsnprintf x)
#endif
......@@ -31,8 +31,6 @@ static char rcsid[] =
#include <isc/net.h>
#include <isc/print.h>
#include "ntp_sprintf.h" /* NTP local change, helps SunOS 4 */
#define NS_INT16SZ 2
#define NS_IN6ADDRSZ 16
......@@ -181,7 +179,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
tp += strlen(tp);
break;
}
tp += SPRINTF((tp, "%x", words[i])); /* NTP local change */
tp += sprintf(tp, "%x", words[i]);
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) ==
......
......@@ -39,9 +39,10 @@ strerror(
static char ebuf[20];
if ((unsigned int)errnum < sys_nerr)
return(sys_errlist[errnum]);
(void)sprintf(ebuf, "Unknown error: %d", errnum);
return(ebuf);
return sys_errlist[errnum];
snprintf(ebuf, sizeof(ebuf), "Unknown error: %d", errnum);
return ebuf;
}
#else
int strerror_bs;
......
......@@ -10,7 +10,7 @@
* C99-compliant implementations.
*/
/* $Id: snprintf.c 1.9 2011/04/11 21:24:10+00:00 davehart@shiny.ad.hartbrothers.com $ */
/* $Id: snprintf.c 1.10 2011/04/12 06:01:53+00:00 davehart@shiny.ad.hartbrothers.com $ */
/*
* Copyright (c) 1995 Patrick Powell.
......@@ -123,10 +123,10 @@
* HW_WANT_RPL_SNPRINTF
* HW_WANT_RPL_VASPRINTF
* HW_WANT_RPL_ASPRINTF
* HAVE_VSNPRINTF
* HAVE_SNPRINTF
* HAVE_VASPRINTF
* HAVE_ASPRINTF
* HAVE_VSNPRINTF // define to 1 #if HW_WANT_RPL_VSNPRINTF
* HAVE_SNPRINTF // define to 1 #if HW_WANT_RPL_SNPRINTF
* HAVE_VASPRINTF // define to 1 #if HW_WANT_RPL_VASPRINTF
* HAVE_ASPRINTF // define to 1 #if HW_WANT_RPL_ASPRINTF
* HAVE_STDARG_H
* HAVE_STDDEF_H
* HAVE_STDINT_H
......
......@@ -89,14 +89,15 @@ fmt_flt(
unsigned long ch
)
{
char *buf;
char *buf;
LIB_GETBUF(buf);
sprintf(buf, "%c %s %s %s", sign ? '-' : '+',
fmt_blong(ch, 11),
fmt_blong(mh, 20),
fmt_blong(ml, 32));
return buf;
LIB_GETBUF(buf);
snprintf(buf, LIB_BUFLENGTH, "%c %s %s %s", sign ? '-' : '+',
fmt_blong(ch, 11),
fmt_blong(mh, 20),
fmt_blong(ml, 32));
return buf;
}
static char *
......@@ -105,15 +106,18 @@ fmt_hex(
int length
)
{
char *buf;
int i;
char * buf;
char hex[4];
int i;
LIB_GETBUF(buf);
buf[0] = '\0';
for (i = 0; i < length; i++) {
snprintf(hex, sizeof(hex), "%02x", bufp[i]);
strlcat(buf, hex, LIB_BUFLENGTH);
}
LIB_GETBUF(buf);
for (i = 0; i < length; i++)
{
sprintf(buf+i*2, "%02x", bufp[i]);
}
return buf;
return buf;
}
#endif
......
......@@ -67,8 +67,6 @@
# include <sys/ppsclock.h>
#endif
#include "ntp_sprintf.h"
#ifndef HAVE_STRUCT_PPSCLOCKEV
struct ppsclockev {
# ifdef HAVE_STRUCT_TIMESPEC
......
......@@ -160,7 +160,7 @@ tpro_poll(
* proper format, we declare bad format and exit. Note: we
* can't use the sec/usec conversion produced by the driver,
* since the year may be suspect. All format error checking is
* done by the sprintf() and sscanf() routines.
* done by the snprintf() and sscanf() routines.
*
* Note that the refclockproc usec member has now become nsec.
* We could either multiply the read-in usec value by 1000 or
......
......@@ -76,14 +76,14 @@ tt560_start(
{
register struct tt560unit *up;
struct refclockproc *pp;
char device[20];
int fd;
caddr_t membase;
char device[20];
int fd;
caddr_t membase;
/*
* Open TT560 device
*/
(void)sprintf(device, DEVICE, unit);
snprintf(device, sizeof(device), DEVICE, unit);
fd = open(device, O_RDWR);
if (fd == -1) {
msyslog(LOG_ERR, "tt560_start: open of %s: %m", device);
......@@ -195,9 +195,9 @@ tt560_poll(
* proper format, we declare bad format and exit. Note: we
* can't use the sec/usec conversion produced by the driver,
* since the year may be suspect. All format error checking is
* done by the sprintf() and sscanf() routines.
* done by the snprintf() and sscanf() routines.
*/
sprintf(pp->a_lastcode,
snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
"%1x%1x%1x %1x%1x:%1x%1x:%1x%1x.%1x%1x%1x%1x%1x%1x %1x",
tp->hun_day, tp->tens_day, tp->unit_day,
tp->tens_hour, tp->unit_hour,
......
......@@ -1569,7 +1569,7 @@ wwv_endpoc(
}
}
if (pp->sloppyclockflag & CLK_FLAG4) {
sprintf(tbuf,
snprintf(tbuf, sizeof(tbuf),
"wwv2 %04x %5.0f %5.1f %5d %4d %4d %4d %4.0f %7.2f",
up->status, up->epomax, up->eposnr, mepoch,
up->avgint, maxrun, mcount - zcount, dtemp,
......@@ -2021,7 +2021,7 @@ wwv_rsec(
}
if ((pp->sloppyclockflag & CLK_FLAG4) && !(up->status &
DSYNC)) {
sprintf(tbuf,
snprintf(tbuf, sizeof(tbuf),
"wwv3 %2d %04x %3d %4d %5.0f %5.1f %5.0f %5.1f %5.0f",
nsec, up->status, up->gain, up->yepoch, up->epomax,
up->eposnr, up->datsig, up->datsnr, bit);
......
......@@ -4,7 +4,7 @@
* GOAL:
* The goal of ntptime is to set the current time on system startup
* to the best possible time using the network very wisely. It is assumed
* that after a resonable time has been sett then ntp daemon will
* that after a reasonable time has been set then ntp daemon will
* maintain it.
*
* PROBLEM DOMAIN:
......@@ -51,7 +51,7 @@
* NOTE: Please do not have this program print out every minute some line,
* of output. If this happens and the environment is in trouble then
* many pages of paper on many different machines will be filled up.
* Save some tress in your lifetime.
* Save some trees in your lifetime.
*
* CONCLUSION:
* The behavior of the program derived from these three issues should be
......@@ -318,9 +318,6 @@ static void init_io P((void));
static int sendpkt P((struct sockaddr_in *dest, struct pkt *pkt, int len));
void input_handler P((l_fp *xts));
static void printserver P((register struct server *pp, FILE *fp));
#if !defined(HAVE_VSPRINTF)
int vsprintf P((char *str, const char *fmt, va_list ap));
#endif
#ifdef HAVE_SIGNALED_IO
extern void wait_for_signal P((void));
......@@ -592,10 +589,8 @@ ntptimesetmain(
exit(1);
}
if (!authistrusted(sys_authkey)) {
char buf[10];
(void) sprintf(buf, "%lu", (unsigned long)sys_authkey);
msyslog(LOG_ERR, "authentication key %s unknown", buf);
msyslog(LOG_ERR, "authentication key %lu unknown",
(u_long)sys_authkey);
exit(1);
}
}
......@@ -2137,23 +2132,3 @@ printserver(
(void) fprintf(fp, "offset %s\n\n",
lfptoa(&pp->offset, 6));
}
#if !defined(HAVE_VSPRINTF)
int
vsprintf(
char *str,
const char *fmt,
va_list ap
)
{
FILE f;
int len;
f._flag = _IOWRT+_IOSTRG;
f._ptr = str;
f._cnt = 32767;
len = _doprnt(fmt, ap, &f);
*f._ptr = 0;
return (len);
}
#endif
......@@ -262,8 +262,8 @@ typedef int socklen_t;
* to other names
*/
#define inline __inline
#define vsnprintf _vsnprintf
#define snprintf _snprintf
/* #define vsnprintf _vsnprintf */
/* #define snprintf _snprintf */
#define stricmp _stricmp
#define strcasecmp _stricmp
#define isascii __isascii
......@@ -390,6 +390,8 @@ typedef __int32 int32_t; /* define a typedef for int32_t */
#define HW_WANT_RPL_VSNPRINTF 1
#define HW_WANT_RPL_SNPRINTF 1
#define HAVE_VSNPRINTF 1
#define HAVE_SNPRINTF 1
typedef char *caddr_t;
......
......@@ -102,7 +102,7 @@ syslog(int level, const char *fmt, ...) {
str[0] = buf;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
/* Make sure that the channel is open to write the event */
......
......@@ -21,6 +21,8 @@
#include <stdlib.h>
#include <stddef.h>
#include <winioctl.h>
#include "ntp_stdlib.h"
#include "hopf_PCI_io.h"
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(REFCLOCK) && defined(CLOCK_TRIMBLEDC)
#include "refclock_trimbledc.h"
extern int debug;
static int trimbledc_start (int, struct peer *);
static void trimbledc_shutdown (int, struct peer *);
static void trimbledc_receive (struct recvbuf *);
static void trimbledc_poll (int, struct peer *);
static void trimbledc_io (char, int, unsigned char *, l_fp*, struct trimbledc_unit *);
/*
* Transfer vector
*/
struct refclock refclock_trimbledc = {
trimbledc_start, /* start up driver */
trimbledc_shutdown, /* shut down driver */
trimbledc_poll, /* transmit poll message */
noentry, /* not used */
noentry, /* initialize driver (not used) */
noentry, /* not used */
NOFLAGS /* not used */
};
/*
* trimbledc_start - open the devices and initialize data for processing
*/
static int
trimbledc_start (
int unit,
struct peer *peer
)
{
register struct trimbledc_unit *up;
struct refclockproc *pp;
int fd;
char gpsdev[20];
struct termios tio;
#ifdef SYS_WINNT
(void) sprintf(gpsdev, DEVICE, unit);
#else
(void) sprintf(gpsdev, DEVICE, unit + 1);
#endif
/*
* Open serial port.
*/
fd = refclock_open(gpsdev, SPEED232, LDISC_RAW);
if (fd == -1) {
msyslog(LOG_ERR,"Trimble (%d) start: open %s failed: %m",
unit, gpsdev);
return 0;
}
msyslog(LOG_NOTICE, "Trimble (%d) fd: %d dev: %s", unit, fd, gpsdev);
if (tcgetattr(fd, &tio) < 0) {
msyslog(LOG_ERR,
"Trimble (%d) tcgetattr(fd, &tio): %m",unit);
return (0);
}
tio.c_cflag |= (PARENB|PARODD);
tio.c_iflag &= ~ICRNL;
if (tcsetattr(fd, TCSANOW, &tio) == -1) {
msyslog(LOG_ERR, "Trimble (%d) tcsetattr(fd, &tio): %m",unit);
return 0;
}
/*
* Allocate and initialize unit structure
*/
if (!(up = (struct trimbledc_unit *)
emalloc(sizeof(struct trimbledc_unit)))) {
(void) close(fd);
return (0);
}
memset((char *)up, 0, sizeof(struct trimbledc_unit));
pp = peer->procptr;
pp->io.clock_recv = trimbledc_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
(void) close(fd);
free(up);
return (0);
}
/*
* Initialize miscellaneous variables
*/
pp->unitptr = (caddr_t)up;
pp->clockdesc = DESCRIPTION;
peer->precision = PRECISION;
peer->sstclktype = CTL_SST_TS_UHF;
peer->minpoll = TRIMBLEDC_MINPOLL;
peer->maxpoll = TRIMBLEDC_MAXPOLL;
memcpy((char *)&pp->refid, REFID, 4);
up->leap_status = 0;
up->unit = unit;
up->io_ptr[0] = up->io_ptr[1] = 0;
return 1;
}
/*
* trimbledc_shutdown - shut down the clock
*/
static void
trimbledc_shutdown (
int unit,
struct peer *peer
)
{
register struct trimbledc_unit *up;
struct refclockproc *pp;
pp = peer->procptr;
up = (struct trimbledc_unit *)pp->unitptr;
io_closeclock(&pp->io);
free(up);
}
/*
* TSIP_decode - decode the TSIP data packets
*/
static int
trimbledc_decode (
struct peer *peer
)
{
#ifdef DEBUG
double lat, lon, alt;
#endif
int st, ts;
long secint;
double secs;
double secfrac;
unsigned short event = 0;
register struct trimbledc_unit *up;
struct refclockproc *pp;
pp = peer->procptr;
up = (struct trimbledc_unit *)pp->unitptr;
/*
* Check the time packet, decode its contents.
* If the timecode has invalid length or is not in
* proper format, declare bad format and exit.
*/
if (up->rpt_buf[0] ==0x41)
/* standard time packet - GPS time and GPS week number */
return 0;
refclock_report(peer, CEVNT_BADREPLY);
up->polled = -1;
#ifdef DEBUG
if (debug)
printf("TRIMBLEDC_decode: unit %d: bad packet %02x-%02x event %d len %d\n",
up->unit, up->rpt_buf[0] & 0xff, mb(0) & 0xff,
event, up->rpt_cnt);
#endif
return 0;
}
/*
* trimbledc__receive - receive data from the serial interface
*/
static void
trimbledc_receive (
struct recvbuf *rbufp
)
{
register struct trimbledc_unit *up;
struct refclockproc *pp;
struct peer *peer;
/*
* Initialize pointers and read the timecode and timestamp.
*/
peer = (struct peer *)rbufp->recv_srcclock;
pp = peer->procptr;
up = (struct trimbledc_unit *)pp->unitptr;
for (;FALSE;) {
trimbledc_io(pp->sloppyclockflag & CLK_FLAG2, rbufp->recv_length,
&rbufp->recv_buffer, &pp->lastrec, up);
(void) sprintf(pp->a_lastcode,"%4d %03d %02d:%02d:%02d.%06ld",
pp->year,pp->day,pp->hour,pp->minute, pp->second,pp->usec);
pp->lencode = 24;
if (!refclock_process(pp)) {
refclock_report(peer, CEVNT_BADTIME);
#ifdef DEBUG
if (debug)
printf("trimbledc_receive: unit %d: refclock_process failed!\n",
up->unit);
#endif
continue;
}
record_clock_stats(&peer->srcadr, pp->a_lastcode);
#ifdef DEBUG
if (debug)
if (debug)
printf("trimbledc_receive: unit %d: %s\n",
up->unit, prettydate(&pp->lastrec));
#endif
refclock_receive(peer);
}
}
/*
* trimbledc_poll - called by the transmit procedure
*
*/
static void
trimbledc_poll (
int unit,
struct peer *peer
)
{
struct trimbledc_unit *up;
struct refclockproc *pp;
pp = peer->procptr;
up = (struct trimbledc_unit *)pp->unitptr;
pp->polls++;
if (up->polled > 0) /* last reply never arrived or error */
refclock_report(peer, CEVNT_TIMEOUT);
up->polled = 2; /* synchronous packet + 1 event */
#ifdef DEBUG
if (debug)
printf("trimbledc_poll: unit %d: polling %s\n", unit,
(pp->sloppyclockflag & CLK_FLAG2) ?
"synchronous packet" : "event");
#endif
if (pp->sloppyclockflag & CLK_FLAG2)
return; /* using synchronous packet input */
// if (HW_poll(pp) < 0)
refclock_report(peer, CEVNT_FAULT);
}
static void
trimbledc_io (
char noevents,
int buflen, /* bytes in buffer to process */
unsigned char *bufp, /* receive buffer */
l_fp* t_in, /* receive time stamp */
struct trimbledc_unit *up /* pointer to unit data structure */
)
{
}
#endif /* REFCLOCK */
/*
* refclock_trimbledc - clock driver for the Trimble Data Collector compatible
* GPS receivers (4000, 4700, 4800, 7400, ...)
*
* Greg Brackley (greg@trimble.co.nz)
*/
#ifndef _REFCLOCK_TRIMBLEDC_H
#define _REFCLOCK_TRIMBLEDC_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined HAVE_SYS_MODEM_H
#include <sys/modem.h>
#define TIOCMSET MCSETA
#define TIOCMGET MCGETA
#define TIOCM_RTS MRTS
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_control.h"
#include "ntp_refclock.h"
#include "ntp_unixtime.h"
#include "ntp_stdlib.h"
/*
* GPS Definitions
*/
#define DESCRIPTION "Trimble Data Collector GPS" /* Long name */
#define PRECISION (-20) /* precision assumed (about 1 us) */
#define REFID "GPS\0" /* reference ID */
#define NSAMPLES 1
#define NSKEEP 1
#define TRIMBLEDC_MINPOLL 4
#define TRIMBLEDC_MAXPOLL 4
/*
* I/O Definitions
*/
#if !defined SYS_WINNT
#define DEVICE "/dev/trimbledc%d" /* device name and unit */
#else
#define DEVICE "\\\\.\\COM%d" /* device name and unit */
#endif
#define SPEED232 B9600 /* uart speed (9600 baud) */
#define POLL_AVG 10 /* number of samples to average code delay */
#define DC_IO_BUFSIZE 512 /* IO buffer */
#define DC_MAXLEN 260 /* maximum length TSIP packet */
/*
* Leap-Insert and Leap-Delete are encoded as follows:
* PALISADE_UTC_TIME set and PALISADE_LEAP_PENDING set: INSERT leap
* PALISADE_UTC_TIME clear and PALISADE_LEAP_PENDING set: DELETE leap
*/
#define PALISADE_LEAP_WARNING 0x04 /* GPS Leap Warning (see ICD-200) */
#define PALISADE_LEAP_PENDING 0x02 /* Leap Pending (24 hours) */
#define PALISADE_UTC_TIME 0x01 /* UTC time available */
#define mb(_X_) (up->rpt_buf[(_X_ + 1)]) /* shortcut for buffer access */
/* Conversion Definitions */
#define GPS_PI (3.1415926535898)
#define R2D (180.0/GPS_PI)
typedef enum TrimbleDcParseState {
TrimbleParseStateAck,
TrimbleParseStateNak,
TrimbleParseStateData,
} TrimbleDcParseState;
struct trimbledc_unit {
int unit; /* NTP refclock unit number */
int polled; /* flag to detect noreplies */
char leap_status; /* leap second flag */
TrimbleDcParseState rpt_status;
short rpt_cnt;
char rpt_buf[DC_MAXLEN];
char io_buf[DC_IO_BUFSIZE];
short io_ptr[2]; /* 0 = head, 1 = tail */
};
#endif /* _REFCLOCK_TRIMBLEDC_H */
......@@ -1575,9 +1575,6 @@
<File
RelativePath="..\..\..\include\ntp_select.h">
</File>
<File
RelativePath="..\..\..\include\ntp_sprintf.h">
</File>
<File
RelativePath="..\..\..\include\ntp_stdlib.h">
</File>
......
......@@ -765,10 +765,6 @@
RelativePath="..\..\..\include\ntp_select.h"
>
</File>
<File
RelativePath="..\..\..\include\ntp_sprintf.h"
>
</File>