Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
bk: 4b690279XH7_NKsG8uPbWDVeQPvJ1Q
---
+* [Bug 1455] ntpd does not try /etc/ntp.audio as documented.
* [Bug 1467] Fix bogus rebuild of sntp/sntp.html
* [Bug 1470] "make distdir" in $srcdir builds keyword-gen, libntp.a.
* [Bug 1473] "make distcheck" before build can't make sntp/version.m4.
+* Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
+* Fix widely cut-n-pasted bug in refclock shutdown after failed start.
+* Remove some dead code checking for emalloc() returning NULL.
---
(4.2.6p1-RC3) 2010/01/24 Released by Harlan Stenn <stenn@ntp.org>
if ((flags & IFF_POINTTOPOINT) != 0) {
iter->current.flags |= INTERFACE_F_POINTTOPOINT;
- sprintf(iter->current.name, "PPP %d", iter->numIF);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "PPP %d", iter->numIF);
ifNamed = TRUE;
}
if ((flags & IFF_LOOPBACK) != 0) {
iter->current.flags |= INTERFACE_F_LOOPBACK;
- sprintf(iter->current.name, "v4loop %d",
- iter->numIF);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "v4loop %d", iter->numIF);
ifNamed = TRUE;
}
&iter->current.netmask);
if (ifNamed == FALSE)
- sprintf(iter->current.name,
+ snprintf(iter->current.name, sizeof(iter->current.name),
"IPv4 %d", iter->numIF);
return (ISC_R_SUCCESS);
sizeof(iter->current.address.type.in6))) {
iter->current.flags |= INTERFACE_F_LOOPBACK;
- sprintf(iter->current.name, "v6loop %d",
- iter->buf6->iAddressCount - iter->pos6);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "v6loop %d",
+ iter->buf6->iAddressCount - iter->pos6);
ifNamed = TRUE;
}
if (ifNamed == FALSE)
- sprintf(iter->current.name, "IPv6 %d",
- iter->buf6->iAddressCount - iter->pos6);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "IPv6 %d",
+ iter->buf6->iAddressCount - iter->pos6);
memset(iter->current.netmask.type.in6.s6_addr, 0xff,
sizeof(iter->current.netmask.type.in6.s6_addr));
FILE *fd;
char device[20], line[100], ab[100];
- sprintf(device, "%s%d", INIT_FILE, unit);
+ snprintf(device, sizeof(device), "%s%d", INIT_FILE, unit);
if ((fd = fopen(device, "r")) == NULL) {
printf("audio_config_read: <%s> NO\n", device);
- sprintf(device, "%s.%d", INIT_FILE, unit);
+ snprintf(device, sizeof(device), "%s.%d", INIT_FILE,
+ unit);
if ((fd = fopen(device, "r")) == NULL) {
printf("audio_config_read: <%s> NO\n", device);
- sprintf(device, "%s.%d", INIT_FILE, unit);
+ snprintf(device, sizeof(device), "%s",
+ INIT_FILE);
if ((fd = fopen(device, "r")) == NULL) {
- printf("audio_config_read: <%s> NO\n", device);
+ printf("audio_config_read: <%s> NO\n",
+ device);
return;
}
}
;
#ifdef PCM_STYLE_SOUND
- (void)sprintf(actl_dev, ACTL_DEV, unit);
+ snprintf(actl_dev, sizeof(actl_dev), ACTL_DEV, unit);
audio_config_read(unit, &actl, &dname);
/* If we have values for cf_c_dev or cf_i_dev, use them. */
/* First choice is my hostname */
if (gethostname(hostname, BUFSIZ) >= 0) {
- (void) sprintf(result, "%s/%s", base, hostname);
+ snprintf(result, sizeof(result), "%s/%s", base, hostname);
if (stat(result, &sbuf) == 0) {
goto outahere;
} else {
cp = unamebuf.machine + 5;
else
cp = unamebuf.machine;
- (void) sprintf(result, "%s/default.%s", base, cp);
+ snprintf(result, sizeof(result), "%s/default.%s", base, cp);
if (stat(result, &sbuf) == 0) {
goto outahere;
} else {
/* Last choice is just default */
- (void) sprintf(result, "%s/default", base);
+ snprintf(result, sizeof(result), "%s/default", base);
if (stat(result, &sbuf) == 0) {
goto outahere;
} else {
char *
humanlogtime(void)
{
- char *bp;
- time_t cursec = time((time_t *) 0);
- struct tm *tm;
+ char * bp;
+ time_t cursec;
+ struct tm * tm;
+ cursec = time(NULL);
tm = localtime(&cursec);
if (!tm)
return "-- --- --:--:--";
LIB_GETBUF(bp);
- (void) sprintf(bp, "%2d %s %02d:%02d:%02d",
- tm->tm_mday, months[tm->tm_mon],
- tm->tm_hour, tm->tm_min, tm->tm_sec);
+ snprintf(bp, LIB_BUFLENGTH, "%2d %s %02d:%02d:%02d",
+ tm->tm_mday, months[tm->tm_mon],
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
return bp;
}
"bclient",
};
- if (mode < 0 || mode >= (sizeof modestrings)/sizeof(char *)) {
+ if (mode < 0 || mode >= COUNTOF(modestrings)) {
LIB_GETBUF(bp);
- (void)sprintf(bp, "mode#%d", mode);
+ snprintf(bp, LIB_BUFLENGTH, "mode#%d", mode);
return bp;
}
msec = ts->l_uf / 4294967; /* fract / (2 ** 32 / 1000) */
tm = ntp2unix_tm(sec, local);
- if (!tm) {
- (void) sprintf(bp, "%08lx.%08lx --- --- -- ---- --:--:--",
- (u_long)ts->l_ui, (u_long)ts->l_uf);
- }
- else {
- (void) sprintf(bp, "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03lu",
- (u_long)ts->l_ui, (u_long)ts->l_uf, days[tm->tm_wday],
- months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year,
- tm->tm_hour,tm->tm_min, tm->tm_sec, msec);
- }
+ if (!tm)
+ snprintf(bp, LIB_BUFLENGTH,
+ "%08lx.%08lx --- --- -- ---- --:--:--",
+ (u_long)ts->l_ui, (u_long)ts->l_uf);
+ else
+ snprintf(bp, LIB_BUFLENGTH,
+ "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03lu",
+ (u_long)ts->l_ui, (u_long)ts->l_uf,
+ days[tm->tm_wday], months[tm->tm_mon],
+ tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour,
+ tm->tm_min, tm->tm_sec, msec);
return bp;
}
while (year >= 100)
year -= 100;
}
- (void) sprintf(bp, "%17s %02d:%03d:%02d:%02d:%02d.%03ld",
- timep, year, tm->tm_yday, tm->tm_hour, tm->tm_min,
- tm->tm_sec, msec);
+ snprintf(bp, LIB_BUFLENGTH,
+ "%17s %02d:%03d:%02d:%02d:%02d.%03ld", timep, year,
+ tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec,
+ msec);
+
return bp;
}
register char *buf;
LIB_GETBUF(buf);
+ snprintf(buf, LIB_BUFLENGTH, "%lu", uval);
- (void) sprintf(buf, "%lu", (u_long)uval);
return buf;
}
while (*cq != '\0')
*cp++ = *cq++;
*cp++ = '=';
- (void)sprintf(cp, "%.3f", ts);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%.3f", ts);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)(cp - buffer), 0);
}
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "%lu", uval);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%lu", uval);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
*cp++ = '=';
fstamp = uval - JAN_1970;
tm = gmtime(&fstamp);
- if (tm == NULL)
+ if (NULL == tm)
return;
-
- sprintf(cp, "%04d%02d%02d%02d%02d", tm->tm_year + 1900,
- tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer),
+ "%04d%02d%02d%02d%02d", tm->tm_year + 1900,
+ tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "0x%lx", uval);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%lx", uval);
+ cp += strlen(cp);
ctl_putdata(buffer,(unsigned)( cp - buffer ), 0);
}
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "%ld", ival);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%ld", ival);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "0x%08lx.%08lx", ts->l_ui & 0xffffffffUL,
- ts->l_uf & 0xffffffffUL);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%08lx.%08lx",
+ ts->l_ui & 0xffffffffUL, ts->l_uf & 0xffffffffUL);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
*cp++ = *cq++;
*cp++ = '=';
- if (addr == NULL)
+ if (NULL == addr)
cq = numtoa(addr32);
else
cq = stoa(addr);
- while (*cq != '\0')
- *cp++ = *cq++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%s", cq);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)(cp - buffer), 0);
}
*cp++ = *cq++;
*cp++ = '=';
- cq = id;
- while (*cq != '\0' && (cq - id) < 4)
- *cp++ = *cq++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%s", id);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
if (i == 0)
i = NTP_SHIFT;
i--;
- (void)sprintf(cp, " %.2f", arr[i] * 1e3);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer),
+ " %.2f", arr[i] * 1e3);
+ cp += strlen(cp);
} while(i != start);
ctl_putdata(buffer, (unsigned)(cp - buffer), 0);
}
ctl_putstr(sys_var[CS_SYSTEM].text, str_system,
sizeof(str_system) - 1);
#else
- sprintf(str, "%s/%s", utsnamebuf.sysname, utsnamebuf.release);
+ snprintf(str, sizeof(str), "%s/%s", utsnamebuf.sysname,
+ utsnamebuf.release);
ctl_putstr(sys_var[CS_SYSTEM].text, str, strlen(str));
#endif /* HAVE_UNAME */
break;
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct arbunit *)emalloc(sizeof(struct arbunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct arbunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = arb_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
pp = peer->procptr;
up = (struct arbunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, SPEED, LDISC_CLK)))
return(0);
#ifdef DEBUG
#endif
- up = (struct arcunit *) emalloc(sizeof(struct arcunit));
- if(!up) { (void) close(fd); return(0); }
+ up = emalloc(sizeof(*up));
/* Set structure to all zeros... */
- memset((char *)up, 0, sizeof(struct arcunit));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = arc_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); }
+ if (!io_addclock(&pp->io)) {
+ close(fd);
+ pp->io.fd = -1;
+ free(up);
+ return(0);
+ }
pp->unitptr = (caddr_t)up;
/*
pp = peer->procptr;
up = (struct arcunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
/*
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
if (!(fd = refclock_open(gpsdev, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct as2201unit *)
- emalloc(sizeof(struct as2201unit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct as2201unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = as2201_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
pp = peer->procptr;
up = (struct as2201unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
* Open PPS device. This can be any serial or parallel port and
* not necessarily the port used for the associated radio.
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
up->fddev = tty_open(device, O_RDWR, 0777);
if (up->fddev <= 0) {
msyslog(LOG_ERR,
- "refclock_atom: %s: %m", device);
+ "refclock_atom: %s: %m", device);
return (0);
}
* That's so we can make awesome Allan deviation plots.
*/
if (pp->sloppyclockflag & CLK_FLAG4) {
- sprintf(tbuf, "%.9f", pp->filter[pp->coderecv]);
+ snprintf(tbuf, sizeof(tbuf), "%.9f",
+ pp->filter[pp->coderecv]);
record_clock_stats(&peer->srcadr, tbuf);
}
}
vme = (struct vmeunit *)pp->unitptr;
io_closeclock(&pp->io);
pp->unitptr = NULL;
- free(vme);
- if (tfp_type == 2) bcStopPci(stfp_handle);
+ if (NULL != vme)
+ free(vme);
+ if (tfp_type == 2)
+ bcStopPci(stfp_handle);
}
tadr = gmtime(&tloc);
tptr->year = (unsigned short)(tadr->tm_year + 1900);
- sprintf(pp->a_lastcode,
- "%3.3d %2.2d:%2.2d:%2.2d.%.6ld %1d",
- tptr->day,
- tptr->hr,
- tptr->mn,
- tptr->sec,
- tptr->frac,
- tptr->status);
+ snprintf(pp->a_lastcode,
+ sizeof(pp->a_lastcode),
+ "%3.3d %2.2d:%2.2d:%2.2d.%.6ld %1d",
+ tptr->day,
+ tptr->hr,
+ tptr->mn,
+ tptr->sec,
+ tptr->frac,
+ tptr->status);
pp->lencode = (u_short) strlen(pp->a_lastcode);
default: /* legacy bancomm card */
if (ioctl(fd_vme, READTIME, &vts)) {
- msyslog(LOG_ERR, "get_datumtime error: %m");
+ msyslog(LOG_ERR,
+ "get_datumtime error: %m");
return(NULL);
}
/* Get day */
- sprintf(cbuf,"%3.3x", ((vts.btfp_time[ 0 ] & 0x000f) <<8) +
- ((vts.btfp_time[ 1 ] & 0xff00) >> 8));
+ snprintf(cbuf, sizeof(cbuf), "%3.3x",
+ ((vts.btfp_time[ 0 ] & 0x000f) << 8) +
+ ((vts.btfp_time[ 1 ] & 0xff00) >> 8));
time_vme->day = (unsigned short)atoi(cbuf);
/* Get hour */
- sprintf(cbuf,"%2.2x", vts.btfp_time[ 1 ] & 0x00ff);
-
+ snprintf(cbuf, sizeof(cbuf), "%2.2x",
+ vts.btfp_time[ 1 ] & 0x00ff);
time_vme->hr = (unsigned short)atoi(cbuf);
/* Get minutes */
- sprintf(cbuf,"%2.2x", (vts.btfp_time[ 2 ] & 0xff00) >>8);
+ snprintf(cbuf, sizeof(cbuf), "%2.2x",
+ (vts.btfp_time[ 2 ] & 0xff00) >> 8);
time_vme->mn = (unsigned short)atoi(cbuf);
/* Get seconds */
- sprintf(cbuf,"%2.2x", vts.btfp_time[ 2 ] & 0x00ff);
+ snprintf(cbuf, sizeof(cbuf), "%2.2x",
+ vts.btfp_time[ 2 ] & 0x00ff);
time_vme->sec = (unsigned short)atoi(cbuf);
/* Get microseconds. Yes, we ignore the 0.1 microsecond digit so
we can use the TVTOTSF function later on...*/
- sprintf(cbuf,"%4.4x%2.2x", vts.btfp_time[ 3 ],
- vts.btfp_time[ 4 ]>>8);
-
+ snprintf(cbuf, sizeof(cbuf), "%4.4x%2.2x",
+ vts.btfp_time[ 3 ],
+ vts.btfp_time[ 4 ] >> 8);
time_vme->frac = (u_long) atoi(cbuf);
/* Get status bit */
- time_vme->status = (vts.btfp_time[0] & 0x0010) >>4;
+ time_vme->status = (vts.btfp_time[0] & 0x0010) >> 4;
break;
}
* Open serial port. Don't bother with CLK line discipline, since
* it's not available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
#ifdef DEBUG
if (debug)
printf ("starting Chronolog with device %s\n",device);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct chronolog_unit *)
- emalloc(sizeof(struct chronolog_unit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct chronolog_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = chronolog_receive;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
pp = peer->procptr;
up = (struct chronolog_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
if (fd_audio > 0) {
fd = fd_audio;
} else {
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = refclock_open(device, SPEED232, LDISC_RAW);
}
#else /* HAVE_AUDIO */
/*
* Open serial port in raw mode.
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = refclock_open(device, SPEED232, LDISC_RAW);
#endif /* HAVE_AUDIO */
if (fd < 0)
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct chuunit *)
- emalloc(sizeof(struct chuunit)))) {
- close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct chuunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = chu_receive;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
u_char code[11]; /* decoded timecode */
char tbuf[80]; /* trace buffer */
+ char * p;
+ size_t chars;
+ size_t cb;
int i;
pp = peer->procptr;
* only if the distance is 40. Note that once a valid frame has
* been found errors are ignored.
*/
- sprintf(tbuf, "chuB %04x %4.0f %2d %2d ", up->status,
- up->maxsignal, nchar, -up->burdist);
- for (i = 0; i < nchar; i++)
- sprintf(&tbuf[strlen(tbuf)], "%02x", up->cbuf[i]);
+ snprintf(tbuf, sizeof(tbuf), "chuB %04x %4.0f %2d %2d ",
+ up->status, up->maxsignal, nchar, -up->burdist);
+ cb = sizeof(tbuf);
+ p = tbuf;
+ for (i = 0; i < nchar; i++) {
+ chars = strlen(p);
+ if (cb < chars + 1) {
+ msyslog(LOG_ERR, "chu_b() fatal out buffer");
+ exit(1);
+ }
+ cb -= chars;
+ p += chars;
+ snprintf(p, cb, "%02x", up->cbuf[i]);
+ }
if (pp->sloppyclockflag & CLK_FLAG4)
record_clock_stats(&peer->srcadr, tbuf);
#ifdef DEBUG
struct chuunit *up;
char tbuf[80]; /* trace buffer */
+ char * p;
+ size_t chars;
+ size_t cb;
l_fp offset; /* timestamp offset */
int val; /* distance */
int temp;
if (temp < 2 || temp > 9 || k + 9 >= nchar || temp !=
((up->cbuf[k + 9] >> 4) & 0xf))
temp = 0;
- sprintf(tbuf, "chuA %04x %4.0f %2d %2d %2d %2d %1d ",
- up->status, up->maxsignal, nchar, up->burdist, k,
- up->syndist, temp);
- for (i = 0; i < nchar; i++)
- sprintf(&tbuf[strlen(tbuf)], "%02x",
- up->cbuf[i]);
+ snprintf(tbuf, sizeof(tbuf),
+ "chuA %04x %4.0f %2d %2d %2d %2d %1d ", up->status,
+ up->maxsignal, nchar, up->burdist, k, up->syndist,
+ temp);
+ cb = sizeof(tbuf);
+ p = tbuf;
+ for (i = 0; i < nchar; i++) {
+ chars = strlen(p);
+ if (cb < chars + 1) {
+ msyslog(LOG_ERR, "chu_a() fatal out buffer");
+ exit(1);
+ }
+ cb -= chars;
+ p += chars;
+ snprintf(p, cb, "%02x", up->cbuf[i]);
+ }
if (pp->sloppyclockflag & CLK_FLAG4)
record_clock_stats(&peer->srcadr, tbuf);
#ifdef DEBUG
} else {
pp->leap = LEAP_NOWARNING;
}
- sprintf(pp->a_lastcode,
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
"%c%1X %04d %03d %02d:%02d:%02d %c%x %+d %d %d %s %.0f %d",
synchar, qual, pp->year, pp->day, pp->hour, pp->minute,
pp->second, leapchar, up->dst, up->dut, minset, up->gain,
*/
rval = icom_freq(up->fd_icom, peer->ttl & 0x7f, qsy[up->chan] +
TUNE);
- sprintf(up->ident, "CHU%d", up->chan);
+ snprintf(up->ident, sizeof(up->ident), "CHU%d", up->chan);
memcpy(&pp->refid, up->ident, 4);
memcpy(&peer->refid, up->ident, 4);
if (metric == 0 && up->status & METRIC) {
* Open serial port. Don't bother with CLK line discipline, since
* it's not available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
#ifdef DEBUG
if (debug)
printf ("starting Dumbclock with device %s\n",device);
/*
* Allocate and initialize unit structure
*/
- up = (struct dumbclock_unit *)emalloc(sizeof(struct dumbclock_unit));
- memset((char *)up, 0, sizeof(struct dumbclock_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = dumbclock_receive;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
pp = peer->procptr;
up = (struct dumbclock_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
return 0;
}
- if (!up) {
- msyslog(LOG_ERR, "psc_start: unit: %d, emalloc: %m", unit);
- return 0;
- }
memset(up, '\0', sizeof *up);
- sprintf(buf, DEVICE, unit); /* dev file name */
+ snprintf(buf, sizeof(buf), DEVICE, unit); /* dev file name */
fd[unit] = open(buf, O_RDONLY); /* open device file */
if (fd[unit] < 0) {
msyslog(LOG_ERR, "psc_start: unit: %d, open failed. %m", unit);
pp->io.fd = -1;
pp->unitptr = (caddr_t) up;
get_systime(&pp->lastrec);
- memcpy((char *)&pp->refid, REFID, 4);
+ memcpy(&pp->refid, REFID, 4);
peer->precision = PRECISION;
pp->clockdesc = DESCRIPTION;
up->unit = unit;
struct peer *peer
)
{
- free(peer->procptr->unitptr);
- close(fd[unit]);
+ if (NULL != peer->procptr->unitptr)
+ free(peer->procptr->unitptr);
+ if (fd[unit] > 0)
+ close(fd[unit]);
}
/* psc_poll: read, decode, and record device time */
pp->nsec = 1000000*BCD2INT3((tlo & 0x00FFF000) >> 12) +
BCD2INT3(tlo & 0x00000FFF);
- sprintf(pp->a_lastcode, "%3.3d %2.2d:%2.2d:%2.2d.%09ld %02x %08x %08x",
- pp->day, pp->hour, pp->minute, pp->second, pp->nsec, status, thi,
- tlo);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "%3.3d %2.2d:%2.2d:%2.2d.%09ld %02x %08x %08x", pp->day,
+ pp->hour, pp->minute, pp->second, pp->nsec, status, thi,
+ tlo);
pp->lencode = strlen(pp->a_lastcode);
/* compute the timecode timestamp */
/*
* Open serial port
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, speed[peer->ttl & 0x3],
LDISC_REMOTE)))
return (0);
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
return (0);
}
peer->precision = PRECISION;
peer->burst = NSTAGE;
pp->clockdesc = DESCRIPTION;
- memcpy((char *)&pp->refid, REFID, 4);
+ memcpy(&pp->refid, REFID, 4);
return (1);
}
struct refclockproc *pp;
pp = peer->procptr;
- io_closeclock(&pp->io);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
}
/*
* Allocate and initialize unit structure
*/
- up = (struct hopfclock_unit *) emalloc(sizeof(struct hopfclock_unit));
-
- if (!(up)) {
- msyslog(LOG_ERR, "hopfPCIClock(%d) emalloc: %m",unit);
-#ifdef DEBUG
- printf("hopfPCIClock(%d) emalloc\n",unit);
-#endif
- return (0);
- }
- memset((char *)up, 0, sizeof(struct hopfclock_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
#ifndef SYS_WINNT
fd = open(DEVICE,O_RDWR); /* try to open hopf clock device */
#else
- if (!OpenHopfDevice()){
- msyslog(LOG_ERR,"Start: %s unit: %d failed!",DEVICE,unit);
+ if (!OpenHopfDevice()) {
+ msyslog(LOG_ERR, "Start: %s unit: %d failed!", DEVICE, unit);
+ free(up);
return (0);
}
#endif
/*
* Initialize miscellaneous peer variables
*/
- if (pp->unitptr!=0) {
- memcpy((char *)&pp->refid, REFID, 4);
- peer->precision = PRECISION;
- pp->clockdesc = DESCRIPTION;
- up->leap_status = 0;
- up->unit = (short) unit;
- return (1);
- }
- else {
- return 0;
- }
+ memcpy((char *)&pp->refid, REFID, 4);
+ peer->precision = PRECISION;
+ pp->clockdesc = DESCRIPTION;
+ up->leap_status = 0;
+ up->unit = (short) unit;
+ return (1);
}
#else
CloseHopfDevice();
#endif
+ if (NULL != peer->procptr->unitptr)
+ free(peer->procptr->unitptr);
}
else
pp->leap = LEAP_NOWARNING;
- sprintf(pp->a_lastcode,"ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d",
- m_time.wStatus, pp->hour, pp->minute, pp->second,
- pp->nsec / 1000000, m_time.wDay, m_time.wMonth, m_time.wYear);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d",
+ m_time.wStatus, pp->hour, pp->minute, pp->second,
+ pp->nsec / 1000000, m_time.wDay, m_time.wMonth,
+ m_time.wYear);
pp->lencode = (u_short)strlen(pp->a_lastcode);
get_systime(&pp->lastrec);
int fd;
char gpsdev[20];
- (void) sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
/* LDISC_STD, LDISC_RAW
* Open serial port. Use CLK line discipline, if available.
/*
* Allocate and initialize unit structure
*/
- up = (struct hopfclock_unit *) emalloc(sizeof(struct hopfclock_unit));
-
- if (!(up)) {
- msyslog(LOG_ERR, "hopfSerialClock(%d) emalloc: %m",unit);
-#ifdef DEBUG
- printf("hopfSerialClock(%d) emalloc\n",unit);
-#endif
- (void) close(fd);
- return (0);
- }
-
- memset((char *)up, 0, sizeof(struct hopfclock_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = hopfserial_receive;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
#ifdef DEBUG
- printf("hopfSerialClock(%d) io_addclock\n",unit);
+ printf("hopfSerialClock(%d) io_addclock\n", unit);
#endif
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
pp = peer->procptr;
up = (struct hopfclock_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
/* preparation for timecode ntpq rl command ! */
#if 0
- wsprintf(pp->a_lastcode,
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
"STATUS: %1X%1X, DATE: %02d.%02d.%04d TIME: %02d:%02d:%02d",
synch,
DoW,
* Open serial port. Use CLK line discipline, if available.
* Default is HP 58503A, mode arg selects HP Z3801A
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
/* mode parameter to server config line shares ttl slot */
if ((peer->ttl == 1)) {
if (!(fd = refclock_open(device, SPEED232Z,
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct hpgpsunit *)
- emalloc(sizeof(struct hpgpsunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct hpgpsunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = hpgps_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
pp = peer->procptr;
up = (struct hpgpsunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct irigunit *)
- emalloc(sizeof(struct irigunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct irigunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = irig_receive;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void)close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
for (i = 3; i < OFFSET; i++) {
up->comp[i] = up->comp[i - 1] + step;
up->comp[OFFSET + i] = -up->comp[i];
- if (i % 16 == 0)
+ if (i % 16 == 0)
step *= 2.;
}
DTOLFP(1. / SECOND, &up->tick);
pp = peer->procptr;
up = (struct irigunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
refclock_report(peer,
CEVNT_BADTIME);
}
- sprintf(pp->a_lastcode,
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
"%02x %02d %03d %02d:%02d:%02d %4.0f %3d %6.3f %2d %6.2f %6.1f %s",
up->errflg, pp->year, pp->day,
pp->hour, pp->minute, pp->second,
/*
* Open serial port
*/
- if ( ! ( pDeviceName = (char*) emalloc ( strlen(DEVICE) + 10 ) ) ) {
- return RC_START_ERROR ;
- }
- sprintf ( pDeviceName, DEVICE, unit ) ;
+ pDeviceName = emalloc ( strlen(DEVICE) + 10 );
+ snprintf ( pDeviceName, strlen(DEVICE) + 10, DEVICE, unit ) ;
/*
* peer->ttl is a mode number specified by "127.127.40.X mode N" in the ntp.conf
/*
* Allocate and initialize unit structure
*/
- if ( ! ( up = (struct jjyunit *) emalloc (sizeof(struct jjyunit)) ) ) {
- close ( fd ) ;
- return RC_START_ERROR ;
- }
-
- memset ( (char*)up, 0, sizeof(struct jjyunit) ) ;
+ up = emalloc (sizeof(*up));
+ memset ( up, 0, sizeof(*up) ) ;
up->linediscipline = iDiscipline ;
/*
up->unittype = UNITTYPE_ECHOKEISOKUKI_LT2000 ;
up->operationmode = 2 ; /* Mode 2 : Continuous mode */
up->lineexpect = 1 ;
- switch ( up->operationmode ) {
- case 1 :
+ switch ( up->operationmode ) {
+ case 1 :
up->charexpect[0] = 15 ; /* YYMMDDWHHMMSS<BCC1><BCC2><CR> */
break ;
case 2 :
break ;
}
break ;
- case 4 :
- up->unittype = UNITTYPE_CITIZENTIC_JJY200 ;
- up->lineexpect = 1 ;
- up->charexpect[0] = 23 ; /* 'XX YY/MM/DD W HH:MM:SS<CR> */
- break ;
+ case 4 :
+ up->unittype = UNITTYPE_CITIZENTIC_JJY200 ;
+ up->lineexpect = 1 ;
+ up->charexpect[0] = 23 ; /* 'XX YY/MM/DD W HH:MM:SS<CR> */
+ break ;
default :
msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
ntoa(&peer->srcadr), peer->ttl ) ;
pp->io.fd = fd ;
if ( ! io_addclock(&pp->io) ) {
close ( fd ) ;
- free ( (void*) up ) ;
+ pp->io.fd = -1 ;
+ free ( up ) ;
+ pp->unitptr = NULL ;
return RC_START_ERROR ;
}
pp = peer->procptr ;
up = (struct jjyunit *) pp->unitptr ;
- io_closeclock ( &pp->io ) ;
- free ( (void*) up ) ;
+ if ( -1 != pp->io.fd )
+ io_closeclock ( &pp->io ) ;
+ if ( NULL != up )
+ free ( up ) ;
}
* timecode timestamp.
*/
- sprintf ( sLogText, "%04d/%02d/%02d %02d:%02d:%02d.%1d JST",
- up->year, up->month, up->day, up->hour, up->minute, up->second, up->msecond/100 ) ;
+ snprintf ( sLogText, sizeof(sLogText),
+ "%04d/%02d/%02d %02d:%02d:%02d.%1d JST",
+ up->year, up->month, up->day,
+ up->hour, up->minute, up->second, up->msecond/100 ) ;
record_clock_stats ( &peer->srcadr, sLogText ) ;
if ( ! refclock_process ( pp ) ) {
/*
* Open serial port
*/
- (void)sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
fd = refclock_open(gpsdev, SPEED232, LDISC_RAW);
if (fd == 0) {
jupiter_debug(peer, "jupiter_start", "open %s: %s",
}
/* Allocate unit structure */
- if ((instance = (struct instance *)
- emalloc(sizeof(struct instance))) == NULL) {
- (void) close(fd);
- return (0);
- }
- memset((char *)instance, 0, sizeof(struct instance));
+ instance = emalloc(sizeof(*instance));
+ memset(instance, 0, sizeof(*instance));
instance->peer = peer;
pp = peer->procptr;
pp->io.clock_recv = jupiter_receive;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
free(instance);
return (0);
}
}
if ((cc = write(instance->peer->procptr->io.fd, (char *)hp, size)) < 0) {
- (void)sprintf(errstr, "write: %s", strerror(errno));
+ snprintf(errstr, sizeof(errstr), "write: %s", strerror(errno));
return (errstr);
} else if (cc != size) {
- (void)sprintf(errstr, "short write (%d != %d)", cc, size);
+ snprintf(errstr, sizeof(errstr), "short write (%d != %d)", cc, size);
return (errstr);
}
return (NULL);
struct peer *peer
)
{
+ struct leitchunit *leitch;
+
+ if (unit >= MAXUNITS) {
+ return;
+ }
+ leitch = &leitchunits[unit];
+ if (-1 != leitch->leitchio.fd)
+ io_closeclock(&leitch->leitchio);
#ifdef DEBUG
if (debug)
- fprintf(stderr, "leitch_shutdown()\n");
+ fprintf(stderr, "leitch_shutdown()\n");
#endif
}
/*
* Open serial port.
*/
- (void) sprintf(leitchdev, LEITCH232, unit);
+ snprintf(leitchdev, sizeof(leitchdev), LEITCH232, unit);
fd232 = open(leitchdev, O_RDWR, 0777);
if (fd232 == -1) {
msyslog(LOG_ERR,
}
leitch = &leitchunits[unit];
- memset((char*)leitch, 0, sizeof(*leitch));
+ memset(leitch, 0, sizeof(*leitch));
#if defined(HAVE_SYSV_TTYS)
/*
leitch->leitchio.datalen = 0;
leitch->leitchio.fd = fd232;
if (!io_addclock(&leitch->leitchio)) {
+ leitch->leitchio.fd = -1;
goto screwed;
}
int i;
register char *ptr = buff;
- sprintf(ptr, text);
- for (i=from; i<to; i++)
- { while (*ptr) ptr++;
- if ((ptr-buff) > DUMP_BUF_SIZE) msyslog(LOG_DEBUG, "D: %s", ptr=buff);
- sprintf(ptr, " %06d", ((int)coffs[i].l_f) / 4295);
+ snprintf(buff, sizeof(buff), text);
+ for (i = from; i < to; i++) {
+ ptr += strlen(ptr);
+ if ((ptr - buff) > DUMP_BUF_SIZE) {
+ msyslog(LOG_DEBUG, "D: %s", buff);
+ ptr = buff;
+ }
+ snprintf(ptr, sizeof(buff) - (ptr - buff),
+ " %06d", ((int)coffs[i].l_f) / 4295);
}
msyslog(LOG_DEBUG, "D: %s", buff);
}
/* Unit okay, attempt to open the devices. We do them both at
* once to make sure we can */
- (void) sprintf(eesdev, EES232, unit);
+ snprintf(eesdev, sizeof(eesdev), EES232, unit);
fd232 = open(eesdev, O_RDWR, 0777);
if (fd232 == -1) {
/* Dump the deltas each minute */
if (dbg & DB_DUMP_DELTAS)
- { if (/*0 <= ees->second && */
- ees->second < ((sizeof deltas) / (sizeof deltas[0]))) deltas[ees->second] = delta_sfsec;
+ {
+ if (/*0 <= ees->second && */
+ ees->second < COUNTOF(deltas))
+ deltas[ees->second] = delta_sfsec;
/* Dump on second 1, as second 0 sometimes missed */
if (ees->second == 1) {
- char text[16 * ((sizeof deltas) / (sizeof deltas[0]))];
+ char text[16 * COUNTOF(deltas)];
char *cptr=text;
int i;
- for (i=0; i<((sizeof deltas) / (sizeof deltas[0])); i++) {
- sprintf(cptr, " %d.%04d",
- msec(deltas[i]), subms(deltas[i]));
- while (*cptr) cptr++;
+ for (i = 0; i < COUNTOF(deltas); i++) {
+ snprintf(cptr, sizeof(text) / COUNTOF(deltas),
+ " %d.%04d", msec(deltas[i]),
+ subms(deltas[i]));
+ cptr += strlen(cptr);
}
msyslog(LOG_ERR, "Deltas: %d.%04d<->%d.%04d: %s",
msec(EES_STEP_F - EES_STEP_F_GRACE), subms(EES_STEP_F - EES_STEP_F_GRACE),
/*
* Open serial port
*/
- (void)sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
if (!(fd = refclock_open(gpsdev, SPEED232, LDISC_PPS))) {
return (0);
}
/*
* Allocate unit structure
*/
- if (!(up = (struct mx4200unit *) emalloc(sizeof(struct mx4200unit)))) {
- perror("emalloc");
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct mx4200unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = mx4200_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
pp = peer->procptr;
up = (struct mx4200unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
}
alt = up->avg_alt;
minute = (lat - (double)(int)lat) * 60.0;
- sprintf(lats,"%02d%02.4f", (int)lat, minute);
+ snprintf(lats, sizeof(lats), "%02d%02.4f", (int)lat, minute);
minute = (lon - (double)(int)lon) * 60.0;
- sprintf(lons,"%03d%02.4f", (int)lon, minute);
+ snprintf(lons, sizeof(lons), "%03d%02.4f", (int)lon, minute);
mx4200_send(peer, "%s,%03d,,,,,%s,%c,%s,%c,%.2f,%d", pmvxg,
PMVXG_S_INITMODEA,
char gpsdev[20];
struct termios tio;
- (void) sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
/*
* Open serial port.
#ifdef DEBUG
printf("Palisade(%d) io_addclock\n",unit);
#endif
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
struct refclockproc *pp;
pp = peer->procptr;
up = (struct palisade_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
* report and process
*/
- (void) sprintf(pp->a_lastcode,"%4d %03d %02d:%02d:%02d.%06ld",
- pp->year,pp->day,pp->hour,pp->minute, pp->second,pp->nsec);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "%4d %03d %02d:%02d:%02d.%06ld",
+ pp->year, pp->day,
+ pp->hour,pp->minute, pp->second, pp->nsec);
pp->lencode = 24;
if (!refclock_process(pp)) {
)
{
char *b = buffer;
- char *endb = (char *)0;
+ char *endb = NULL;
if (blen < 4)
- return (char *)0; /* don't bother with mini buffers */
+ return NULL; /* don't bother with mini buffers */
endb = buffer + blen - 4;
}
else
{
- sprintf(buffer, "\\x%02x", *src++);
+ snprintf(buffer, blen, "\\x%02x", *src++);
blen -= 4;
buffer += 4;
}
/*
* Open device file for reading.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = open(device, O_RDONLY);
if (fd == -1) {
- (void)sprintf(device, OLDDEVICE, unit);
+ snprintf(device, sizeof(device), OLDDEVICE, unit);
fd = open(device, O_RDONLY);
}
#ifdef DEBUG
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct pstunit *)emalloc(sizeof(struct pstunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct pstunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = pst_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
pp = peer->procptr;
up = (struct pstunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
HANDLE shmid=0;
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
- sprintf (buf,"NTP%d",unit);
- if (unit>=2) { /* world access */
+ snprintf(buf, sizeof(buf), "NTP%d", unit);
+ if (unit >= 2) { /* world access */
if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) {
msyslog(LOG_ERR,"SHM InitializeSecurityDescriptor (unit %d): %m",unit);
return 0;
pp->io.datalen = 0;
pp->io.fd = -1;
- up = (struct shmunit *) emalloc(sizeof(*up));
- if (up == NULL)
- return (FALSE);
- memset((char *)up, 0, sizeof(*up));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp->unitptr = (caddr_t)up;
up->shm = getShmTime(unit);
pp = peer->procptr;
up = (struct shmunit *)pp->unitptr;
+
+ if (NULL == up)
+ return;
#ifndef SYS_WINNT
/* HMS: shmdt()wants char* or const void * */
(void) shmdt ((char *)up->shm);
#else
UnmapViewOfFile (up->shm);
#endif
+ free(up);
}
/*
* Open TPRO device
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = open(device, O_RDONLY | O_NDELAY, 0777);
if (fd == -1) {
msyslog(LOG_ERR, "tpro_start: open of %s: %m", device);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct tprounit *) emalloc(sizeof(struct tprounit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct tprounit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = noentry;
pp->io.srcclock = (caddr_t)peer;
pp = peer->procptr;
up = (struct tprounit *)pp->unitptr;
io_closeclock(&pp->io);
- free(up);
+ if (NULL != up)
+ free(up);
}
* we could pad the written string appropriately and read the
* resulting value in already scaled.
*/
- sprintf(pp->a_lastcode,
- "%1x%1x%1x %1x%1x:%1x%1x:%1x%1x.%1x%1x%1x%1x%1x%1x %1x",
- tp->day100, tp->day10, tp->day1, tp->hour10, tp->hour1,
- tp->min10, tp->min1, tp->sec10, tp->sec1, tp->ms100,
- tp->ms10, tp->ms1, tp->usec100, tp->usec10, tp->usec1,
- tp->status);
- pp->lencode = strlen(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->day100, tp->day10, tp->day1, tp->hour10, tp->hour1,
+ tp->min10, tp->min1, tp->sec10, tp->sec1, tp->ms100,
+ tp->ms10, tp->ms1, tp->usec100, tp->usec10, tp->usec1,
+ tp->status);
+ pp->lencode = strlen(pp->a_lastcode);
#ifdef DEBUG
if (debug)
printf("tpro: time %s timecode %d %s\n",
* timestamp following the "*" on-time character of the
* timecode.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (
#ifdef PPS
!(fd = refclock_open(device, SPEED232, LDISC_CLK))
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct trakunit *)
- emalloc(sizeof(struct trakunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct trakunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = trak_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
(void) close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
pp = peer->procptr;
up = (struct trakunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
/*
* Open serial port. Use CLK line discipline, if available.
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (-1 == (fd = refclock_open(device, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- up = (struct wwvbunit *)emalloc(sizeof(struct wwvbunit));
- memset((char *)up, 0, sizeof(struct wwvbunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = wwvb_receive;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
*/
peer->precision = PRECISION;
pp->clockdesc = DESCRIPTION;
- memcpy((char *)&pp->refid, REFID, 4);
+ memcpy(&pp->refid, REFID, 4);
return (1);
}
pp = peer->procptr;
up = (struct wwvbunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
static void pstatus (struct parse *, FILE *);
static long when (l_fp *, l_fp *, l_fp *);
-static char * prettyinterval (char *, long);
+static char * prettyinterval (char *, size_t, long);
static int doprintpeers (struct varlist *, int, int, int, char *, FILE *, int);
static int dogetpeers (struct varlist *, int, FILE *, int);
static void dopeers (int, FILE *, int);
break;
}
cnt = uinttoa(event_count);
- sprintf(buf,
- "%3d %5u %04x %3.3s %4s %4.4s %9.9s %11s %2s",
- i + 1, assoc_cache[i].assid, assoc_cache[i].status,
- conf, reach, auth, condition, last_event, cnt);
- bp = &buf[strlen(buf)];
- while (bp > buf && *(bp-1) == ' ')
- *(--bp) = '\0';
- (void) fprintf(fp, "%s\n", buf);
+ snprintf(buf, sizeof(buf),
+ "%3d %5u %04x %3.3s %4s %4.4s %9.9s %11s %2s",
+ i + 1, assoc_cache[i].assid,
+ assoc_cache[i].status, conf, reach, auth,
+ condition, last_event, cnt);
+ bp = buf + strlen(buf);
+ while (bp > buf && ' ' == bp[-1])
+ --bp;
+ bp[0] = '\0';
+ fprintf(fp, "%s\n", buf);
}
}
static char *
prettyinterval(
char *buf,
+ size_t cb,
long diff
)
{
}
if (diff <= 2048) {
- (void) sprintf(buf, "%ld", (long int)diff);
+ snprintf(buf, cb, "%ld", diff);
return buf;
}
diff = (diff + 29) / 60;
if (diff <= 300) {
- (void) sprintf(buf, "%ldm", (long int)diff);
+ snprintf(buf, cb, "%ldm", diff);
return buf;
}
diff = (diff + 29) / 60;
if (diff <= 96) {
- (void) sprintf(buf, "%ldh", (long int)diff);
+ snprintf(buf, cb, "%ldh", diff);
return buf;
}
diff = (diff + 11) / 24;
- (void) sprintf(buf, "%ldd", (long int)diff);
+ snprintf(buf, cb, "%ldd", diff);
return buf;
}
else
c = flash2[CTL_PEER_STATVAL(rstatus) & 0x3];
if (numhosts > 1)
- (void) fprintf(fp, "%-*s ", maxhostlen, currenthost);
+ fprintf(fp, "%-*s ", maxhostlen, currenthost);
if (af == 0 || AF(&srcadr) == af) {
- strcpy(clock_name, nntohost(&srcadr));
-
- (void) fprintf(fp,
+ strncpy(clock_name, nntohost(&srcadr), sizeof(clock_name));
+ fprintf(fp,
"%c%-15.15s %-15.15s %2ld %c %4.4s %4.4s %3lo %7.7s %8.7s %7.7s\n",
c, clock_name, dstadr_refid, stratum, type,
- prettyinterval(whenbuf, when(&ts, &rec, &reftime)),
- prettyinterval(pollbuf, (int)poll_sec), reach,
- lfptoms(&estdelay, 3), lfptoms(&estoffset, 3),
- havevar[HAVE_JITTER] ? lfptoms(&estjitter, 3) :
- lfptoms(&estdisp, 3));
+ prettyinterval(whenbuf, sizeof(whenbuf),
+ when(&ts, &rec, &reftime)),
+ prettyinterval(pollbuf, sizeof(pollbuf),
+ (int)poll_sec),
+ reach, lfptoms(&estdelay, 3),
+ lfptoms(&estoffset, 3),
+ (havevar[HAVE_JITTER])
+ ? lfptoms(&estjitter, 3)
+ : lfptoms(&estdisp, 3));
return (1);
}
else
u_long val
)
{
- register char *cb, *s;
+ register char *cp, *s;
+ size_t cb;
register int i;
register const char *sep;
sep = "";
i = 0;
- s = cb = &circ_buf[nextcb][0];
+ s = cp = circ_buf[nextcb];
if (++nextcb >= NUMCB)
- nextcb = 0;
+ nextcb = 0;
+ cb = sizeof(circ_buf[0]);
- sprintf(cb, "%02lx", val);
- cb += strlen(cb);
+ snprintf(cp, cb, "%02lx", val);
+ cp += strlen(cp);
+ cb -= strlen(cp);
if (!val) {
- strcat(cb, " ok");
- cb += strlen(cb);
+ strncat(cp, " ok", cb);
+ cp += strlen(cp);
+ cb -= strlen(cp);
} else {
- *cb++ = ' ';
- for (i = 0; i < 13; i++) {
+ if (cb) {
+ *cp++ = ' ';
+ cb--;
+ }
+ for (i = 0; i < COUNTOF(tstflagnames); i++) {
if (val & 0x1) {
- sprintf(cb, "%s%s", sep, tstflagnames[i]);
+ snprintf(cp, cb, "%s%s", sep,
+ tstflagnames[i]);
sep = ", ";
- cb += strlen(cb);
+ cp += strlen(cp);
+ cb -= strlen(cp);
}
val >>= 1;
}
}
- *cb = '\0';
+ if (cb)
+ *cp = '\0';
+
return s;
}
* Ignore nonstandard extension warning.
* This happens when including winioctl.h
*/
-#pragma warning( disable : 4201)
+#pragma warning(disable: 4201)
#define _FILESYSTEMFSCTL_
#include <config.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <winioctl.h>
#include "hopf_PCI_io.h"
-#include <stddef.h>
-#define ATL_PASSTHROUGH_READ_TOSIZE 3*sizeof(ULONG)
-#define ATL_PASSTHROUGH_READ_FROMSIZE 0
-#define IOCTL_ATLSOFT_PASSTHROUGH_READ CTL_CODE( \
+#define ATL_PASSTHROUGH_READ_TOSIZE (3 * sizeof(ULONG))
+#define ATL_PASSTHROUGH_READ_FROMSIZE 0
+#define IOCTL_ATLSOFT_PASSTHROUGH_READ CTL_CODE( \
FILE_DEVICE_UNKNOWN, \
0x805, \
METHOD_BUFFERED, \
HANDLE hDevice = NULL; // this is the handle to the PCI Device
-HANDLE hRdEvent;
-OVERLAPPED Rdoverlapped;
-OVERLAPPED *pRdOverlapped;
+HANDLE hRdEvent;
+OVERLAPPED Rdoverlapped;
+OVERLAPPED * pRdOverlapped;
-ULONG iobuffer[256];
-DWORD cbReturned;
-BOOL HaveBoard = FALSE;
-struct{
+ULONG iobuffer[256];
+DWORD cbReturned;
+BOOL HaveBoard = FALSE;
+
+struct {
ULONG region;
ULONG offset;
ULONG count;
- }io_params;
+} io_params;
-BOOL OpenHopfDevice()
+BOOL
+OpenHopfDevice(void)
{
- OSVERSIONINFO VersionInfo;
- ULONG deviceNumber;
- CHAR deviceName[255];
-
- VersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
- GetVersionEx(&VersionInfo);
- switch(VersionInfo.dwPlatformId)
- {
- case VER_PLATFORM_WIN32_WINDOWS: // Win95/98
- return(FALSE); // "NTP does not support Win 95-98."
- break;
-
- case VER_PLATFORM_WIN32_NT: // WinNT
- deviceNumber=0;
- sprintf(deviceName,"\\\\.\\hclk6039%d",deviceNumber+1);
- hDevice=CreateFile(
- deviceName,
- GENERIC_WRITE|GENERIC_READ,
- FILE_SHARE_WRITE|FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_OVERLAPPED,
- NULL);
- break;
-
- default:
- hDevice=INVALID_HANDLE_VALUE;
- break;
-
- } // end switch
-
- if ( hDevice == INVALID_HANDLE_VALUE ) // the system didn't return a handle
- {
- return(FALSE); //"A handle to the driver could not be obtained properly"
- }
-
- hRdEvent=CreateEvent(NULL, // an event to be used for async transfers
- TRUE,
- FALSE,
- NULL);
-
- if ( hRdEvent == INVALID_HANDLE_VALUE )
- return(FALSE); // the system didn't return a handle
-
- pRdOverlapped=&Rdoverlapped;
- pRdOverlapped->hEvent=hRdEvent;
+ OSVERSIONINFO VersionInfo;
+ ULONG deviceNumber;
+ CHAR deviceName[255];
+
+ VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&VersionInfo);
+ switch (VersionInfo.dwPlatformId) {
+
+ case VER_PLATFORM_WIN32_WINDOWS: // Win95/98
+ return FALSE; // "NTP does not support Win 95-98."
+ break;
+
+ case VER_PLATFORM_WIN32_NT: // WinNT
+ deviceNumber = 0;
+ snprintf(deviceName, sizeof(deviceName),
+ "\\\\.\\hclk6039%d", deviceNumber + 1);
+ hDevice = CreateFile(
+ deviceName,
+ GENERIC_WRITE | GENERIC_READ,
+ FILE_SHARE_WRITE | FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_OVERLAPPED,
+ NULL);
+ break;
+
+ default:
+ hDevice = INVALID_HANDLE_VALUE;
+ break;
+ } // end switch
+
+ if (INVALID_HANDLE_VALUE == hDevice) // the system didn't return a handle
+ return FALSE; //"A handle to the driver could not be obtained properly"
+
+ // an event to be used for async transfers
+ hRdEvent = CreateEvent(
+ NULL,
+ TRUE,
+ FALSE,
+ NULL);
+
+ if (INVALID_HANDLE_VALUE == hRdEvent)
+ return FALSE; // the system didn't return a handle
+
+ pRdOverlapped = &Rdoverlapped;
+ pRdOverlapped->hEvent = hRdEvent;
HaveBoard = TRUE; // board installed and we have access
} // end of OpenHopfDevice()
-BOOL CloseHopfDevice(){
-
+BOOL
+CloseHopfDevice(void)
+{
CloseHandle(hRdEvent);// When done, close the handle to the driver
- if (CloseHandle(hDevice)==TRUE) // unlink the driver using a CloseHandle call
- {
- return TRUE;
- }
- return FALSE; // "The driver handle could not be unlinked properly"
+ return CloseHandle(hDevice);
} // end of CloseHopfDevice()
-void ReadHopfDevice(){
-
- if (HaveBoard){
- DeviceIoControl(hDevice, IOCTL_ATLSOFT_PASSTHROUGH_READ, &io_params,ATL_PASSTHROUGH_READ_TOSIZE,
- iobuffer,ATL_PASSTHROUGH_READ_FROMSIZE+io_params.count*sizeof(ULONG),&cbReturned, pRdOverlapped);
- }
+void
+ReadHopfDevice(void)
+{
+ if (!HaveBoard)
+ return;
+
+ DeviceIoControl(
+ hDevice,
+ IOCTL_ATLSOFT_PASSTHROUGH_READ,
+ &io_params,
+ ATL_PASSTHROUGH_READ_TOSIZE,
+ iobuffer,
+ ATL_PASSTHROUGH_READ_FROMSIZE
+ + io_params.count * sizeof(ULONG),
+ &cbReturned,
+ pRdOverlapped
+ );
}
-
-
-void GetHardwareData(LPDWORD Data32,WORD Ofs)
+void
+GetHardwareData(
+ LPDWORD Data32,
+ WORD Ofs
+ )
{
io_params.region = 1;
io_params.offset = Ofs;
- io_params.count =1;
+ io_params.count = 1;
ReadHopfDevice();
*Data32 = iobuffer[0];
- return;
}
-void GetHopfTime(LPHOPFTIME Data,DWORD Offset)
+void
+GetHopfTime(
+ LPHOPFTIME Data,
+ DWORD Offset
+ )
{
io_params.region = 1;
io_params.offset = Offset;
- io_params.count =4;
+ io_params.count = 4;
ReadHopfDevice();
Data->wHour = 0;
Data->wMinute = 0;
Data->wSecond = 0;
- while (iobuffer[0] >= (60 * 60 * 1000)) {
- iobuffer[0] = iobuffer[0] - 60*60 *1000;
+ while (iobuffer[0] >= 60 * 60 * 1000) {
+ iobuffer[0] = iobuffer[0] - 60 * 60 * 1000;
Data->wHour++;
- }
- while (iobuffer[0] >= (60 * 1000)) {
- iobuffer[0] = iobuffer[0] - 60 *1000;
+ }
+ while (iobuffer[0] >= 60 * 1000) {
+ iobuffer[0] = iobuffer[0] - 60 * 1000;
Data->wMinute++;
- }
- while (iobuffer[0] >= (1000)) {
+ }
+ while (iobuffer[0] >= 1000) {
iobuffer[0] = iobuffer[0] - 1000;
Data->wSecond++;
- }
+ }
Data->wMilliseconds = LOWORD(iobuffer[0]);
Data->wDay = HIBYTE(HIWORD(iobuffer[1]));
Data->wMonth = LOBYTE(HIWORD(iobuffer[1]));
io_params.region = 1;
io_params.offset += 0x08;
- io_params.count =1;
+ io_params.count = 1;
ReadHopfDevice();
Data->wStatus = LOBYTE(HIWORD(iobuffer[0]));
- return;
}
-void GetHopfLocalTime(LPHOPFTIME Data)
+void
+GetHopfLocalTime(
+ LPHOPFTIME Data
+ )
{
DWORD Offset = 0;
- GetHopfTime(Data,Offset);
- return;
+
+ GetHopfTime(Data, Offset);
}
-void GetHopfSystemTime(LPHOPFTIME Data)
+void
+GetHopfSystemTime(
+ LPHOPFTIME Data
+ )
{
DWORD Offset = 0x10;
- GetHopfTime(Data,Offset);
- return;
+
+ GetHopfTime(Data,Offset);
}
-void GetSatData(LPSATSTAT Data)
+void
+GetSatData(
+ LPSATSTAT Data
+ )
{
io_params.region = 1;
io_params.offset = 0xb0;
- io_params.count =5;
+ io_params.count = 5;
ReadHopfDevice();
- Data->wVisible= HIBYTE(HIWORD(iobuffer[0]));
- Data->wMode = LOBYTE(LOWORD(iobuffer[0]));
- Data->wSat0 = HIBYTE(HIWORD(iobuffer[1]));
- Data->wRat0 = LOBYTE(HIWORD(iobuffer[1]));
- Data->wSat1 = HIBYTE(LOWORD(iobuffer[1]));
- Data->wRat1 = LOBYTE(LOWORD(iobuffer[1]));
- Data->wSat2 = HIBYTE(HIWORD(iobuffer[2]));
- Data->wRat2 = LOBYTE(HIWORD(iobuffer[2]));
- Data->wSat3 = HIBYTE(LOWORD(iobuffer[2]));
- Data->wRat3 = LOBYTE(LOWORD(iobuffer[2]));
- Data->wSat4 = HIBYTE(HIWORD(iobuffer[3]));
- Data->wRat4 = LOBYTE(HIWORD(iobuffer[3]));
- Data->wSat5 = HIBYTE(LOWORD(iobuffer[3]));
- Data->wRat5 = LOBYTE(LOWORD(iobuffer[3]));
- Data->wSat6 = HIBYTE(HIWORD(iobuffer[4]));
- Data->wRat6 = LOBYTE(HIWORD(iobuffer[4]));
- Data->wSat7 = HIBYTE(LOWORD(iobuffer[4]));
- Data->wRat7 = LOBYTE(LOWORD(iobuffer[4]));
-
- return;
+ Data->wVisible = HIBYTE(HIWORD(iobuffer[0]));
+ Data->wMode = LOBYTE(LOWORD(iobuffer[0]));
+ Data->wSat0 = HIBYTE(HIWORD(iobuffer[1]));
+ Data->wRat0 = LOBYTE(HIWORD(iobuffer[1]));
+ Data->wSat1 = HIBYTE(LOWORD(iobuffer[1]));
+ Data->wRat1 = LOBYTE(LOWORD(iobuffer[1]));
+ Data->wSat2 = HIBYTE(HIWORD(iobuffer[2]));
+ Data->wRat2 = LOBYTE(HIWORD(iobuffer[2]));
+ Data->wSat3 = HIBYTE(LOWORD(iobuffer[2]));
+ Data->wRat3 = LOBYTE(LOWORD(iobuffer[2]));
+ Data->wSat4 = HIBYTE(HIWORD(iobuffer[3]));
+ Data->wRat4 = LOBYTE(HIWORD(iobuffer[3]));
+ Data->wSat5 = HIBYTE(LOWORD(iobuffer[3]));
+ Data->wRat5 = LOBYTE(LOWORD(iobuffer[3]));
+ Data->wSat6 = HIBYTE(HIWORD(iobuffer[4]));
+ Data->wRat6 = LOBYTE(HIWORD(iobuffer[4]));
+ Data->wSat7 = HIBYTE(LOWORD(iobuffer[4]));
+ Data->wRat7 = LOBYTE(LOWORD(iobuffer[4]));
}
-void GetDiffTime(LPLONG Data)
+
+void
+GetDiffTime(
+ LPLONG Data
+ )
{
io_params.region = 1;
io_params.offset = 0x0c;
- io_params.count =1;
+ io_params.count = 1;
ReadHopfDevice();
- *Data = iobuffer[0];
- return;
+ *Data = iobuffer[0];
}
-void GetPosition(LPGPSPOS Data){
+
+void
+GetPosition(
+ LPGPSPOS Data
+ )
+{
io_params.region = 1;
io_params.offset = 0x90; // Positionsdaten Länge
io_params.count = 1;
ReadHopfDevice();
- Data->wLongitude = iobuffer[0]; //in Millisekunden
+ Data->wLongitude = iobuffer[0]; //in Millisekunden
io_params.region = 1;
io_params.offset = 0xa0; // Positionsdaten Breite
io_params.count = 1;
Data->wLatitude = iobuffer[0];
Data->wAltitude = 0;
- return;
}
-void GetHardwareVersion(LPCLOCKVER Data){
-int i;
+
+void
+GetHardwareVersion(
+ LPCLOCKVER Data
+ )
+{
+ int i;
+
io_params.region = 1;
io_params.offset = 0x50;
- io_params.count =12;
+ io_params.count = 12;
ReadHopfDevice();
- strcpy(Data->cVersion,"");
- iobuffer[13] =0;
- for (i=0; i < 13; i++){
+ Data->cVersion[0] = '\0';
+ iobuffer[13] = 0;
+ for (i = 0; i < 13; i++) {
Data->cVersion[i * 4 ] = HIBYTE(HIWORD(iobuffer[i]));
Data->cVersion[i * 4 + 1] = LOBYTE(HIWORD(iobuffer[i]));
Data->cVersion[i * 4 + 2] = HIBYTE(LOWORD(iobuffer[i]));
}
}
-void GetDCFAntenne(LPDCFANTENNE Data){
+
+void
+GetDCFAntenne(
+ LPDCFANTENNE Data
+ )
+{
io_params.region = 1;
- io_params.offset = 0xcc; //
+ io_params.offset = 0xcc;
io_params.count = 1;
ReadHopfDevice();
- Data->bStatus1 = HIBYTE(HIWORD(iobuffer[0])); //
- Data->bStatus = LOBYTE(HIWORD(iobuffer[0])); //
- Data->wAntValue = LOWORD(iobuffer[0]);
- return;
+ Data->bStatus1 = HIBYTE(HIWORD(iobuffer[0]));
+ Data->bStatus = LOBYTE(HIWORD(iobuffer[0]));
+ Data->wAntValue = LOWORD(iobuffer[0]);
}
-
RelativePath="..\..\..\..\libntp\atouint.c"
>
</File>
+ <File
+ RelativePath="..\..\..\..\libntp\audio.c"
+ >
+ </File>
<File
RelativePath="..\..\..\..\libntp\authkeys.c"
>
>
</File>
<File
- RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
+ RelativePath="..\..\include\sys\time.h"
>
</File>
<File
- RelativePath="..\..\include\sys\time.h"
+ RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
>
</File>
<File