[Git][NTPsec/ntpsec][master] 8 commits: libntp: make errno_to_str() and addto_syslog() static.
Gary E. Miller
gitlab at mg.gitlab.com
Tue May 23 00:54:39 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
362c7dea by Gary E. Miller at 2017-05-22T16:50:30-07:00
libntp: make errno_to_str() and addto_syslog() static.
Bonus errno_to_str() is only needed ifndef VSNPRINTF_PERCENT_M.
- - - - -
886dc8f8 by Gary E. Miller at 2017-05-22T16:56:41-07:00
libntp: make mvfprintf(0 static
- - - - -
7ae1b84e by Gary E. Miller at 2017-05-22T16:59:15-07:00
libntp: remove unused mfprintf()
- - - - -
dcdba8a4 by Gary E. Miller at 2017-05-22T17:07:13-07:00
libntp: move msnprintf() to tests. It was only a test helper.
- - - - -
2571db58 by Gary E. Miller at 2017-05-22T17:09:32-07:00
tests: rearrange to eliminate an #ifndef.
- - - - -
13089764 by Gary E. Miller at 2017-05-22T17:24:57-07:00
libntp: move mstolfp() to be a test local.
No need for a large test only fuinction in libntp.
- - - - -
e44e36fc by Gary E. Miller at 2017-05-22T17:32:55-07:00
libntp: remove emalloc() which has been commented out for a while.
- - - - -
c2514334 by Gary E. Miller at 2017-05-22T17:52:57-07:00
libntp: remove unused ntp_gettime().
ntptime.s has had its own private copy.
- - - - -
11 changed files:
- include/ntp_fp.h
- include/ntp_stdlib.h
- include/ntp_syscall.h
- libntp/clockwork.c
- libntp/emalloc.c
- − libntp/mstolfp.c
- libntp/msyslog.c
- libntp/wscript
- ntptime/ntptime.c
- tests/libntp/msyslog.c
- tests/libntp/strtolfp.c
Changes:
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -191,7 +191,6 @@ extern char * mfptoms (l_fp, short);
extern bool atolfp (const char *, l_fp *);
extern bool hextolfp (const char *, l_fp *);
extern void gpstolfp (int, int, unsigned long, l_fp *);
-extern bool mstolfp (const char *, l_fp *);
extern char * prettydate (const l_fp);
extern char * gmprettydate (const l_fp);
extern char * rfc3339date (const l_fp);
=====================================
include/ntp_stdlib.h
=====================================
--- a/include/ntp_stdlib.h
+++ b/include/ntp_stdlib.h
@@ -29,18 +29,13 @@
extern const char *ntpd_version(void);
extern int mprintf(const char *, ...) NTP_PRINTF(1, 2);
-extern int mfprintf(FILE *, const char *, ...) NTP_PRINTF(2, 3);
-extern int mvfprintf(FILE *, const char *, va_list) NTP_PRINTF(2, 0);
extern int mvsnprintf(char *, size_t, const char *, va_list)
NTP_PRINTF(3, 0);
-extern int msnprintf(char *, size_t, const char *, ...)
- NTP_PRINTF(3, 4);
extern void msyslog(int, const char *, ...) NTP_PRINTF(2, 3);
extern void init_logging (const char *, uint32_t, int);
extern int change_logfile (const char *, int);
extern void reopen_logfile (void);
extern void setup_logfile (const char *);
-extern void errno_to_str(int, char *, size_t);
/* authkeys.c */
extern void auth_delkeys (void);
=====================================
include/ntp_syscall.h
=====================================
--- a/include/ntp_syscall.h
+++ b/include/ntp_syscall.h
@@ -1,11 +1,9 @@
/*
- * ntp_syscall.h - various ways to perform the ntp_adjtime() and ntp_gettime()
- * system calls.
+ * ntp_syscall.h - various ways to perform the ntp_adjtime() system calls.
*
* On most systems including <sys/timex.h> will bring in declarations
- * for the BSD functions ntp_gettime(2) and ntp_adjtime(2). (Linux
- * using glibc has these, though they're not visible in the manual
- * pages.)
+ * for the BSD function ntp_adjtime(2). (Linux using glibc has these,
+ * though they're not visible in the manual pages.)
*/
#ifndef GUARD_NTP_SYSCALL_H
@@ -17,17 +15,6 @@
extern int ntp_adjtime_ns(struct timex *);
#endif
-#ifndef HAVE_STRUCT_NTPTIMEVAL
-struct ntptimeval
-{
- struct timeval time; /* current time (ro) */
- long int maxerror; /* maximum error (us) (ro) */
- long int esterror; /* estimated error (us) (ro) */
-};
-
-int ntp_gettime(struct ntptimeval *);
-#endif /* !HAVE_STRUCT_NTPTIMEVAL */
-
/*
* The units of the maxerror and esterror fields vary by platform. If
* STA_NANO is defined, they're in nanoseconds; otherwise in
=====================================
libntp/clockwork.c
=====================================
--- a/libntp/clockwork.c
+++ b/libntp/clockwork.c
@@ -109,24 +109,6 @@ int ntp_adjtime_ns(struct timex *ntx)
}
#endif /* HAVE_SYS_TIMEX_H */
-#if !defined(HAVE_NTP_GETTIME) && defined(HAVE_NTP_ADJTIME)
-int ntp_gettime(struct ntptimeval *ntv)
-{
- struct timex tntx;
- int result;
-
- ZERO(tntx);
- result = ntp_adjtime(&tntx);
- ntv->time = tntx.time;
- ntv->maxerror = tntx.maxerror;
- ntv->esterror = tntx.esterror;
-#if defined(HAVE_STRUCT_NTPTIMEVAL_TAI)
- ntv->tai = tntx.tai;
-#endif
- return result;
-}
-#endif /* !HAVE_NTP_GETTIME */
-
int
ntp_set_tod(
struct timespec *tvs
=====================================
libntp/emalloc.c
=====================================
--- a/libntp/emalloc.c
+++ b/libntp/emalloc.c
@@ -138,14 +138,3 @@ estrdup_impl(
return copy;
}
-
-#if 0
-#ifndef EREALLOC_CALLSITE
-void *
-emalloc(size_t newsz)
-{
- return ereallocz(NULL, newsz, 0, false);
-}
-#endif
-#endif
-
=====================================
libntp/mstolfp.c deleted
=====================================
--- a/libntp/mstolfp.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * mstolfp - convert an ascii string in milliseconds to an l_fp number
- */
-#include "config.h"
-#include <stdio.h>
-#include <ctype.h>
-
-#include "ntp_fp.h"
-#include "ntp_stdlib.h"
-
-bool
-mstolfp(
- const char *str,
- l_fp *lfp
- )
-{
- register const char *cp;
- register char *bp;
- register const char *cpdec;
- char buf[100];
-
- /*
- * We understand numbers of the form:
- *
- * [spaces][-][digits][.][digits][spaces|\n|\0]
- *
- * This is one enormous hack. Since I didn't feel like
- * rewriting the decoding routine for milliseconds, what
- * is essentially done here is to make a copy of the string
- * with the decimal moved over three places so the seconds
- * decoding routine can be used.
- */
- bp = buf;
- cp = str;
- while (isspace((unsigned char)*cp))
- cp++;
-
- if (*cp == '-') {
- *bp++ = '-';
- cp++;
- }
-
- if (*cp != '.' && !isdigit((unsigned char)*cp))
- return false;
-
-
- /*
- * Search forward for the decimal point or the end of the string.
- */
- cpdec = cp;
- while (isdigit((unsigned char)*cpdec))
- cpdec++;
-
- /*
- * Found something. If we have more than three digits copy the
- * excess over, else insert a leading 0.
- */
- if ((cpdec - cp) > 3) {
- do {
- *bp++ = (char)*cp++;
- } while ((cpdec - cp) > 3);
- } else {
- *bp++ = '0';
- }
-
- /*
- * Stick the decimal in. If we've got less than three digits in
- * front of the millisecond decimal we insert the appropriate number
- * of zeros.
- */
- *bp++ = '.';
- if ((cpdec - cp) < 3) {
- register int i = 3 - (cpdec - cp);
-
- do {
- *bp++ = '0';
- } while (--i > 0);
- }
-
- /*
- * Copy the remainder up to the millisecond decimal. If cpdec
- * is pointing at a decimal point, copy in the trailing number too.
- */
- while (cp < cpdec)
- *bp++ = (char)*cp++;
-
- if (*cp == '.') {
- cp++;
- while (isdigit((unsigned char)*cp))
- *bp++ = (char)*cp++;
- }
- *bp = '\0';
-
- /*
- * Check to make sure the string is properly terminated. If
- * so, give the buffer to the decoding routine.
- */
- if (*cp != '\0' && !isspace((unsigned char)*cp))
- return false;
- return atolfp(buf, lfp);
-}
=====================================
libntp/msyslog.c
=====================================
--- a/libntp/msyslog.c
+++ b/libntp/msyslog.c
@@ -31,8 +31,10 @@ uint32_t ntp_syslogmask = INIT_NTP_SYSLOGMASK;
extern char * progname;
/* Declare the local functions */
-void addto_syslog (int, const char *);
+static int mvfprintf(FILE *, const char *, va_list) NTP_PRINTF(2, 0);
+static void addto_syslog (int, const char *);
#ifndef VSNPRINTF_PERCENT_M
+static void errno_to_str(int, char *, size_t);
void format_errmsg (char *, size_t, const char *, int);
/* format_errmsg() is under #ifndef VSNPRINTF_PERCENT_M above */
@@ -75,14 +77,13 @@ format_errmsg(
}
*n = '\0';
}
-#endif /* VSNPRINTF_PERCENT_M */
/*
* errno_to_str() - a thread-safe strerror() replacement.
* Hides the varied signatures of strerror_r().
*/
-void
+static void
errno_to_str(
int err,
char * buf,
@@ -100,6 +101,7 @@ errno_to_str(
snprintf(buf, bufsiz, "strerror_r(%d): errno %d",
err, errno);
}
+#endif /* VSNPRINTF_PERCENT_M */
/*
@@ -107,7 +109,7 @@ errno_to_str(
* This routine adds the contents of a buffer to the syslog or an
* application-specific logfile.
*/
-void
+static void
addto_syslog(
int level,
const char * msg
@@ -215,7 +217,7 @@ mvsnprintf(
}
-int
+static int
mvfprintf(
FILE * fp,
const char * fmt,
@@ -242,25 +244,6 @@ mvfprintf(
return vfprintf(fp, nfmt, ap);
}
-
-int
-mfprintf(
- FILE * fp,
- const char * fmt,
- ...
- )
-{
- va_list ap;
- int rc;
-
- va_start(ap, fmt);
- rc = mvfprintf(fp, fmt, ap);
- va_end(ap);
-
- return rc;
-}
-
-
int
mprintf(
const char * fmt,
@@ -278,25 +261,6 @@ mprintf(
}
-int
-msnprintf(
- char * buf,
- size_t bufsiz,
- const char * fmt,
- ...
- )
-{
- va_list ap;
- int rc;
-
- va_start(ap, fmt);
- rc = mvsnprintf(buf, bufsiz, fmt, ap);
- va_end(ap);
-
- return rc;
-}
-
-
void
msyslog(
int level,
=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -11,7 +11,6 @@ def build(ctx):
"getopt.c",
"initnetwork.c",
"macencrypt.c",
- "mstolfp.c",
"netof.c",
"ntp_endian.c",
"ntp_random.c",
=====================================
ntptime/ntptime.c
=====================================
--- a/ntptime/ntptime.c
+++ b/ntptime/ntptime.c
@@ -35,6 +35,16 @@
/* nano seconds per micro second */
#define NS_PER_US_FLOAT 1000.0
+#ifndef HAVE_STRUCT_NTPTIMEVAL
+struct ntptimeval
+{
+ struct timeval time; /* current time (ro) */
+ long int maxerror; /* maximum error (us) (ro) */
+ long int esterror; /* estimated error (us) (ro) */
+};
+
+#endif /* !HAVE_STRUCT_NTPTIMEVAL */
+
/* MUSL port shim */
#ifndef HAVE_NTP_GETTIME
int ntp_gettime(struct ntptimeval *ntv)
=====================================
tests/libntp/msyslog.c
=====================================
--- a/tests/libntp/msyslog.c
+++ b/tests/libntp/msyslog.c
@@ -15,9 +15,40 @@ TEST_TEAR_DOWN(msyslog) {}
#include <string.h>
#include <errno.h>
+static int msnprintf(char *, size_t, const char *, ...) NTP_PRINTF(3, 4);
+
+static int
+msnprintf(
+ char * buf,
+ size_t bufsiz,
+ const char * fmt,
+ ...
+ )
+{
+ va_list ap;
+ int rc;
+
+ va_start(ap, fmt);
+ rc = mvsnprintf(buf, bufsiz, fmt, ap);
+ va_end(ap);
+
+ return rc;
+}
+
#ifndef VSNPRINTF_PERCENT_M
// format_errmsg() is normally private to msyslog.c
void format_errmsg (char *, size_t, const char *, int);
+
+TEST(msyslog, format_errmsgHangingPercent)
+{
+ static char fmt[] = "percent then nul term then non-nul %\0oops!";
+ char act_buf[64];
+
+ ZERO(act_buf);
+ format_errmsg(act_buf, sizeof(act_buf), fmt, ENOENT);
+ TEST_ASSERT_EQUAL_STRING(fmt, act_buf);
+ TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf));
+}
#endif
// msnprintf()
@@ -80,19 +111,6 @@ TEST(msyslog, msnprintfBackslashPercent)
TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
}
-#ifndef VSNPRINTF_PERCENT_M
-TEST(msyslog, format_errmsgHangingPercent)
-{
- static char fmt[] = "percent then nul term then non-nul %\0oops!";
- char act_buf[64];
-
- ZERO(act_buf);
- format_errmsg(act_buf, sizeof(act_buf), fmt, ENOENT);
- TEST_ASSERT_EQUAL_STRING(fmt, act_buf);
- TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf));
-}
-#endif
-
TEST(msyslog, msnprintfNullTarget)
{
int exp_cnt;
=====================================
tests/libntp/strtolfp.c
=====================================
--- a/tests/libntp/strtolfp.c
+++ b/tests/libntp/strtolfp.c
@@ -1,9 +1,108 @@
#include "config.h"
#include "ntp_stdlib.h"
+#include "ntp_fp.h"
+#include <stdio.h>
+#include <ctype.h>
#include "unity.h"
#include "unity_fixture.h"
+static bool mstolfp (const char *, l_fp *);
+
+/*
+ * mstolfp - convert an ascii string in milliseconds to an l_fp number
+ */
+static bool
+mstolfp(
+ const char *str,
+ l_fp *lfp
+ )
+{
+ register const char *cp;
+ register char *bp;
+ register const char *cpdec;
+ char buf[100];
+
+ /*
+ * We understand numbers of the form:
+ *
+ * [spaces][-][digits][.][digits][spaces|\n|\0]
+ *
+ * This is one enormous hack. Since I didn't feel like
+ * rewriting the decoding routine for milliseconds, what
+ * is essentially done here is to make a copy of the string
+ * with the decimal moved over three places so the seconds
+ * decoding routine can be used.
+ */
+ bp = buf;
+ cp = str;
+ while (isspace((unsigned char)*cp))
+ cp++;
+
+ if (*cp == '-') {
+ *bp++ = '-';
+ cp++;
+ }
+
+ if (*cp != '.' && !isdigit((unsigned char)*cp))
+ return false;
+
+
+ /*
+ * Search forward for the decimal point or the end of the string.
+ */
+ cpdec = cp;
+ while (isdigit((unsigned char)*cpdec))
+ cpdec++;
+
+ /*
+ * Found something. If we have more than three digits copy the
+ * excess over, else insert a leading 0.
+ */
+ if ((cpdec - cp) > 3) {
+ do {
+ *bp++ = (char)*cp++;
+ } while ((cpdec - cp) > 3);
+ } else {
+ *bp++ = '0';
+ }
+
+ /*
+ * Stick the decimal in. If we've got less than three digits in
+ * front of the millisecond decimal we insert the appropriate number
+ * of zeros.
+ */
+ *bp++ = '.';
+ if ((cpdec - cp) < 3) {
+ register int i = 3 - (cpdec - cp);
+
+ do {
+ *bp++ = '0';
+ } while (--i > 0);
+ }
+
+ /*
+ * Copy the remainder up to the millisecond decimal. If cpdec
+ * is pointing at a decimal point, copy in the trailing number too.
+ */
+ while (cp < cpdec)
+ *bp++ = (char)*cp++;
+
+ if (*cp == '.') {
+ cp++;
+ while (isdigit((unsigned char)*cp))
+ *bp++ = (char)*cp++;
+ }
+ *bp = '\0';
+
+ /*
+ * Check to make sure the string is properly terminated. If
+ * so, give the buffer to the decoding routine.
+ */
+ if (*cp != '\0' && !isspace((unsigned char)*cp))
+ return false;
+ return atolfp(buf, lfp);
+}
TEST_GROUP(strtolfp);
TEST_SETUP(strtolfp) {}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c162ad865b680e08c1d1c8714557fd99b5346d2a...c25143342a93538fcbab825fc3aae002cec4e450
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c162ad865b680e08c1d1c8714557fd99b5346d2a...c25143342a93538fcbab825fc3aae002cec4e450
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170523/af299196/attachment.html>
More information about the vc
mailing list