summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2022-08-26 15:58:33 +0200
committerMartin Burnicki <martin.burnicki@meinberg.de>2022-08-26 15:58:33 +0200
commit422d45124dc10c8657399b3898622a3b14dda4c2 (patch)
tree2b1244bf00844b825cdbe5e9a1a8956ef0a7582d
parenteaa66d56becdcf0e671f1b2e3dc2a5edb68b30cb (diff)
downloadmbgtools-lx-422d45124dc10c8657399b3898622a3b14dda4c2.tar.gz
mbgtools-lx-422d45124dc10c8657399b3898622a3b14dda4c2.zip
Change the return type of some snprint_... functions from size_t to int
-rw-r--r--mbglib/common/gpsutils.c24
-rw-r--r--mbglib/common/gpsutils.h14
-rw-r--r--mbglib/common/lan_util.c43
-rw-r--r--mbglib/common/lan_util.h20
4 files changed, 56 insertions, 45 deletions
diff --git a/mbglib/common/gpsutils.c b/mbglib/common/gpsutils.c
index c953acd..6194907 100644
--- a/mbglib/common/gpsutils.c
+++ b/mbglib/common/gpsutils.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: gpsutils.c 1.11 2019/06/25 15:20:01 martin REL_M $
+ * $Id: gpsutils.c 1.12 2022/08/26 11:01:27 martin.burnicki REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,9 @@
*
* -----------------------------------------------------------------------
* $Log: gpsutils.c $
+ * Revision 1.12 2022/08/26 11:01:27 martin.burnicki
+ * Changed the return value of some snprint_... functions from size_t to int.
+ * Also quieted some potential compiler warnings.
* Revision 1.11 2019/06/25 15:20:01 martin
* Fixed unprintable prefix in snprint_dms() in case the position is uninitialized.
* Revision 1.10 2017/07/05 13:57:06 martin
@@ -299,7 +302,7 @@ void swap_pos_doubles( POS *p )
* @see snprint_pos_geo
* @see snprint_fixed_freq
*/
-size_t snprint_dms( char *s, size_t max_len, const DMS *p, int prec )
+int snprint_dms( char *s, size_t max_len, const DMS *p, int prec )
{
// If the position is unknown / uninitialized,
// the prefix character can be invalid, so print
@@ -309,7 +312,7 @@ size_t snprint_dms( char *s, size_t max_len, const DMS *p, int prec )
if ( ( prefix < ' ' ) || ( prefix >= '\x7F' ) )
prefix = ' ';
- size_t n = snprintf_safe( s, max_len, "%c %i" DEG "%02i'%02.*f\"",
+ int n = snprintf_safe( s, max_len, "%c %i" DEG "%02i'%02.*f\"",
prefix, p->deg, p->min,
prec, p->sec );
@@ -333,9 +336,9 @@ size_t snprint_dms( char *s, size_t max_len, const DMS *p, int prec )
* @see snprint_pos_geo
* @see snprint_fixed_freq
*/
-size_t snprint_alt( char *s, size_t max_len, double alt )
+int snprint_alt( char *s, size_t max_len, double alt )
{
- size_t n = snprintf_safe( s, max_len, "%.0fm", alt );
+ int n = snprintf_safe( s, max_len, "%.0fm", alt );
return n;
@@ -359,9 +362,9 @@ size_t snprint_alt( char *s, size_t max_len, double alt )
* @see snprint_alt
* @see snprint_fixed_freq
*/
-size_t snprint_pos_geo( char *s, size_t max_len, const POS *p, char sep, int prec )
+int snprint_pos_geo( char *s, size_t max_len, const POS *p, char sep, int prec )
{
- size_t n = 0;
+ int n = 0;
if ( p->lla[LON] && p->lla[LAT] && p->lla[ALT] )
{
@@ -398,12 +401,12 @@ size_t snprint_pos_geo( char *s, size_t max_len, const POS *p, char sep, int pre
* @see snprint_alt
* @see snprint_pos_geo
*/
-size_t snprint_fixed_freq( char *s, size_t max_len, FIXED_FREQ_INFO *p_ff )
+int snprint_fixed_freq( char *s, size_t max_len, FIXED_FREQ_INFO *p_ff )
{
double freq;
int range;
- ushort unit;
- ushort format;
+ uint unit;
+ uint format;
size_t n = 0;
// Before re-calculating frequency, range is the base 10 exponent
@@ -456,6 +459,7 @@ size_t snprint_fixed_freq( char *s, size_t max_len, FIXED_FREQ_INFO *p_ff )
"MHz"
};
+ (void) n; // Avoid warning "never used".
if ( p_ff->khz_val )
{
diff --git a/mbglib/common/gpsutils.h b/mbglib/common/gpsutils.h
index fd25e3e..0f1494a 100644
--- a/mbglib/common/gpsutils.h
+++ b/mbglib/common/gpsutils.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: gpsutils.h 1.8 2017/07/05 13:58:25 martin REL_M $
+ * $Id: gpsutils.h 1.9 2022/08/26 11:00:48 martin.burnicki REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,7 +10,9 @@
*
* -----------------------------------------------------------------------
* $Log: gpsutils.h $
- * Revision 1.8 2017/07/05 13:58:25 martin
+ * Revision 1.9 2022/08/26 11:00:48 martin.burnicki
+ * Changed the return value of some snprint_... functions from size_t to int.
+ * Revision 1.8 2017/07/05 13:58:25Z martin
* Include stddef.h.
* Updated function prototypes.
* Revision 1.7 2010/07/15 09:32:09 martin
@@ -169,7 +171,7 @@ extern "C" {
* @see snprint_pos_geo
* @see snprint_fixed_freq
*/
- size_t snprint_dms( char *s, size_t max_len, const DMS *p, int prec ) ;
+ int snprint_dms( char *s, size_t max_len, const DMS *p, int prec ) ;
/**
* @brief Print the altitude part of a geo position into a string buffer
@@ -184,7 +186,7 @@ extern "C" {
* @see snprint_pos_geo
* @see snprint_fixed_freq
*/
- size_t snprint_alt( char *s, size_t max_len, double alt ) ;
+ int snprint_alt( char *s, size_t max_len, double alt ) ;
/**
* @brief Print a geo position in ::POS format into a string buffer
@@ -201,7 +203,7 @@ extern "C" {
* @see snprint_alt
* @see snprint_fixed_freq
*/
- size_t snprint_pos_geo( char *s, size_t max_len, const POS *p, char sep, int prec ) ;
+ int snprint_pos_geo( char *s, size_t max_len, const POS *p, char sep, int prec ) ;
/**
* @brief Print a formatted ::FIXED_FREQ_INFO into a string buffer
@@ -216,7 +218,7 @@ extern "C" {
* @see snprint_alt
* @see snprint_pos_geo
*/
- size_t snprint_fixed_freq( char *s, size_t max_len, FIXED_FREQ_INFO *p_ff ) ;
+ int snprint_fixed_freq( char *s, size_t max_len, FIXED_FREQ_INFO *p_ff ) ;
/* ----- function prototypes end ----- */
diff --git a/mbglib/common/lan_util.c b/mbglib/common/lan_util.c
index 666b4c3..8615e74 100644
--- a/mbglib/common/lan_util.c
+++ b/mbglib/common/lan_util.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: lan_util.c 1.23 2021/07/20 10:27:30 daniel REL_M $
+ * $Id: lan_util.c 1.24 2022/08/26 13:55:28 martin.burnicki REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,8 +10,11 @@
*
* -----------------------------------------------------------------------
* $Log: lan_util.c $
+ * Revision 1.24 2022/08/26 13:55:28 martin.burnicki
+ * Changed the return type of some snprint_... functions from size_t to int.
* Revision 1.23 2021/07/20 10:27:30 daniel
- * On SOC platforms use alternative method via proc interface to retrieve current IP address of the IPv4 default gateway.
+ * On SOC platforms use alternative method via proc interface
+ * to retrieve current IP address of the IPv4 default gateway.
* Revision 1.22 2021/05/18 14:13:48 daniel
* Fixed NUM_WORDS bug again
* Revision 1.21 2021/05/17 13:23:22 daniel
@@ -166,7 +169,7 @@
/**
* @brief Maximum size of an IPv4 address string in dotted quad format.
- *
+ *
* Includes a terminating 0, so the required minimum size
* for a buffer to take such a string. i.e. "aaa.bbb.ccc.ddd\0".
*/
@@ -235,9 +238,9 @@ int get_ip4_net_mask_bits( const IP4_ADDR *p_mask )
* @see ::str_to_ip4_addr
* @see ::cidr_str_to_ip4_addr_and_net_mask
*/
-size_t snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *p_addr, const char *info )
+int snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *p_addr, const char *info )
{
- size_t n = 0;
+ int n = 0;
ulong ul = *p_addr;
if ( info )
@@ -274,8 +277,8 @@ size_t snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *p_addr, const
* @see ::str_to_ip4_addr
* @see ::cidr_str_to_ip4_addr_and_net_mask
*/
-size_t snprint_ip4_cidr_addr( char *s, size_t max_len, const IP4_ADDR *p_addr,
- const IP4_ADDR *p_mask, const char *info )
+int snprint_ip4_cidr_addr( char *s, size_t max_len, const IP4_ADDR *p_addr,
+ const IP4_ADDR *p_mask, const char *info )
{
int cidr_mask_bits;
size_t n = snprint_ip4_addr( s, max_len, p_addr, info );
@@ -483,7 +486,7 @@ int get_ip6_net_mask_bits( const IP6_ADDR *p_mask )
* @see ::cidr_str_to_ip6_addr_and_cidr_bits
* @see ::cidr_str_to_ip6_addr_and_net_mask
*/
-size_t snprint_ip6_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const char *info )
+int snprint_ip6_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const char *info )
{
// Copied from inet_ntop.c, and reversed byte order.
@@ -492,7 +495,7 @@ size_t snprint_ip6_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const
#define NUM_WORDS ( (int) ( IP6_ADDR_BYTES / sizeof( uint16_t ) ) )
uint16_t words[NUM_WORDS] = { 0 };
int i;
- size_t n = 0;
+ int n = 0;
struct
{
int base;
@@ -613,10 +616,10 @@ size_t snprint_ip6_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const
* @see ::cidr_str_to_ip6_addr_and_cidr_bits
* @see ::cidr_str_to_ip6_addr_and_net_mask
*/
-size_t snprint_ip6_cidr_addr( char *s, size_t max_len, const IP6_ADDR *p_addr,
- const IP6_ADDR *p_mask, const char *info )
+int snprint_ip6_cidr_addr( char *s, size_t max_len, const IP6_ADDR *p_addr,
+ const IP6_ADDR *p_mask, const char *info )
{
- size_t n = snprint_ip6_addr( s, max_len, p_addr, info );
+ int n = snprint_ip6_addr( s, max_len, p_addr, info );
int cidr_mask_bits = get_ip6_net_mask_bits( p_mask );
@@ -651,10 +654,10 @@ size_t snprint_ip6_cidr_addr( char *s, size_t max_len, const IP6_ADDR *p_addr,
* @see ::cidr_str_to_ip6_addr_and_cidr_bits
* @see ::cidr_str_to_ip6_addr_and_net_mask
*/
-size_t snprint_ip6_cidr_mask_addr( char *s, size_t max_len, const IP6_ADDR *p_addr,
- const int cidr_mask_bits, const char* info )
+int snprint_ip6_cidr_mask_addr( char *s, size_t max_len, const IP6_ADDR *p_addr,
+ const int cidr_mask_bits, const char* info )
{
- size_t n;
+ int n;
IP6_ADDR mask;
ip6_net_mask_from_cidr( &mask, cidr_mask_bits );
@@ -1013,10 +1016,10 @@ void ip6_net_part_from_addr( IP6_ADDR *p_net_part, const IP6_ADDR *p_addr,
* @see ::str_to_octets
* @see ::octets_are_all_zero
*/
-size_t snprint_octets( char *s, size_t max_len, const uint8_t *octets,
- int num_octets, char sep, const char *info )
+int snprint_octets( char *s, size_t max_len, const uint8_t *octets,
+ int num_octets, char sep, const char *info )
{
- size_t n = 0;
+ int n = 0;
int i;
if ( info )
@@ -1051,7 +1054,7 @@ size_t snprint_octets( char *s, size_t max_len, const uint8_t *octets,
*
* @see ::snprint_octets
*/
-size_t snprint_ptp_clock_id( char *s, size_t max_len, const PTP_CLOCK_ID *p )
+int snprint_ptp_clock_id( char *s, size_t max_len, const PTP_CLOCK_ID *p )
{
return snprint_octets( s, max_len, p->b, sizeof( *p ), ':', NULL );
@@ -1074,7 +1077,7 @@ size_t snprint_ptp_clock_id( char *s, size_t max_len, const PTP_CLOCK_ID *p )
* @see ::str_to_octets
* @see ::octets_are_all_zero
*/
-size_t snprint_mac_addr( char *s, size_t max_len, const MBG_MAC_ADDR *p_mac_addr )
+int snprint_mac_addr( char *s, size_t max_len, const MBG_MAC_ADDR *p_mac_addr )
{
return snprint_octets( s, max_len, p_mac_addr->b, sizeof( *p_mac_addr ), MAC_SEP_CHAR, NULL );
diff --git a/mbglib/common/lan_util.h b/mbglib/common/lan_util.h
index cb54f6d..bdc7992 100644
--- a/mbglib/common/lan_util.h
+++ b/mbglib/common/lan_util.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: lan_util.h 1.10 2021/03/22 18:07:28 martin REL_M $
+ * $Id: lan_util.h 1.11 2022/08/26 13:55:30 martin.burnicki REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,8 @@
*
* -----------------------------------------------------------------------
* $Log: lan_util.h $
+ * Revision 1.11 2022/08/26 13:55:30 martin.burnicki
+ * Changed the return type of some snprint_... functions from size_t to int.
* Revision 1.10 2021/03/22 18:07:28 martin
* Updated a bunch of comments.
* Revision 1.9 2018/02/28 16:55:31 martin
@@ -241,7 +243,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
* @see ::str_to_ip4_addr
* @see ::cidr_str_to_ip4_addr_and_net_mask
*/
- size_t snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *p_addr, const char *info ) ;
+ int snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *p_addr, const char *info ) ;
/**
* @brief Print an IPv4 address plus net mask in CIDR notation to a string.
@@ -261,7 +263,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
* @see ::str_to_ip4_addr
* @see ::cidr_str_to_ip4_addr_and_net_mask
*/
- size_t snprint_ip4_cidr_addr( char *s, size_t max_len, const IP4_ADDR *p_addr, const IP4_ADDR *p_mask, const char *info ) ;
+ int snprint_ip4_cidr_addr( char *s, size_t max_len, const IP4_ADDR *p_addr, const IP4_ADDR *p_mask, const char *info ) ;
/**
* @brief Convert a string to an ::IP4_ADDR.
@@ -335,7 +337,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
* @see ::cidr_str_to_ip6_addr_and_cidr_bits
* @see ::cidr_str_to_ip6_addr_and_net_mask
*/
- size_t snprint_ip6_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const char *info ) ;
+ int snprint_ip6_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const char *info ) ;
/**
* @brief Print an IPv6 address plus net mask to string in CIDR notation.
@@ -357,7 +359,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
* @see ::cidr_str_to_ip6_addr_and_cidr_bits
* @see ::cidr_str_to_ip6_addr_and_net_mask
*/
- size_t snprint_ip6_cidr_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const IP6_ADDR *p_mask, const char *info ) ;
+ int snprint_ip6_cidr_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const IP6_ADDR *p_mask, const char *info ) ;
/**
* @brief Print an IPv6 address plus number of net mask bits to string in CIDR notation.
@@ -379,7 +381,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
* @see ::cidr_str_to_ip6_addr_and_cidr_bits
* @see ::cidr_str_to_ip6_addr_and_net_mask
*/
- size_t snprint_ip6_cidr_mask_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const int cidr_mask_bits, const char* info ) ;
+ int snprint_ip6_cidr_mask_addr( char *s, size_t max_len, const IP6_ADDR *p_addr, const int cidr_mask_bits, const char* info ) ;
/**
* @brief Convert a string to an ::IP6_ADDR.
@@ -489,7 +491,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
* @see ::str_to_octets
* @see ::octets_are_all_zero
*/
- size_t snprint_octets( char *s, size_t max_len, const uint8_t *octets, int num_octets, char sep, const char *info ) ;
+ int snprint_octets( char *s, size_t max_len, const uint8_t *octets, int num_octets, char sep, const char *info ) ;
/**
* @brief Print a ::PTP_CLOCK_ID to a string.
@@ -505,7 +507,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
*
* @see ::snprint_octets
*/
- size_t snprint_ptp_clock_id( char *s, size_t max_len, const PTP_CLOCK_ID *p ) ;
+ int snprint_ptp_clock_id( char *s, size_t max_len, const PTP_CLOCK_ID *p ) ;
/**
* @brief Print a MAC address to a string.
@@ -521,7 +523,7 @@ int ip4_net_part_matches( const IP4_ADDR *p_addr1, const IP4_ADDR *p_addr2,
* @see ::str_to_octets
* @see ::octets_are_all_zero
*/
- size_t snprint_mac_addr( char *s, size_t max_len, const MBG_MAC_ADDR *p_mac_addr ) ;
+ int snprint_mac_addr( char *s, size_t max_len, const MBG_MAC_ADDR *p_mac_addr ) ;
/**
* @brief Set a MAC ID or a similar array of octets from a string.