mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
src: replace use of INT_BUFSIZE_BOUND macros
Introduce a vastly simpler VIR_INT64_STR_BUFLEN constant which is large enough for all cases where we currently use INT_BUFSIZE_BOUND. This eliminates most use of the gnulib intprops.h header. Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
a1cd25b919
commit
117353f9e5
@ -36,7 +36,6 @@
|
||||
#include "openwsman.h"
|
||||
#include "virstring.h"
|
||||
#include "virkeycode.h"
|
||||
#include "intprops.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_HYPERV
|
||||
|
||||
@ -1339,7 +1338,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
|
||||
Msvm_Keyboard *keyboard = NULL;
|
||||
virBuffer query = VIR_BUFFER_INITIALIZER;
|
||||
hypervInvokeParamsListPtr params = NULL;
|
||||
char keycodeStr[INT_BUFSIZE_BOUND(int)];
|
||||
char keycodeStr[VIR_INT64_STR_BUFLEN];
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "virfile.h"
|
||||
#include "vircommand.h"
|
||||
#include "configmake.h"
|
||||
#include "intprops.h"
|
||||
#include "virstring.h"
|
||||
#include "virfirewall.h"
|
||||
|
||||
@ -820,10 +819,9 @@ iptablesHandleIPHdr(virFirewallPtr fw,
|
||||
bool directionIn,
|
||||
bool *skipRule, bool *skipMatch)
|
||||
{
|
||||
char ipaddr[INET6_ADDRSTRLEN],
|
||||
ipaddralt[INET6_ADDRSTRLEN],
|
||||
number[MAX(INT_BUFSIZE_BOUND(uint32_t),
|
||||
INT_BUFSIZE_BOUND(int))];
|
||||
char ipaddr[INET6_ADDRSTRLEN];
|
||||
char ipaddralt[INET6_ADDRSTRLEN];
|
||||
char number[VIR_INT64_STR_BUFLEN];
|
||||
const char *src = "--source";
|
||||
const char *dst = "--destination";
|
||||
const char *srcrange = "--src-range";
|
||||
@ -968,8 +966,7 @@ iptablesHandleIPHdrAfterStateMatch(virFirewallPtr fw,
|
||||
ipHdrDataDefPtr ipHdr,
|
||||
bool directionIn)
|
||||
{
|
||||
char number[MAX(INT_BUFSIZE_BOUND(uint32_t),
|
||||
INT_BUFSIZE_BOUND(int))];
|
||||
char number[VIR_INT64_STR_BUFLEN];
|
||||
char str[MAX_IPSET_NAME_LENGTH];
|
||||
|
||||
if (HAS_ENTRY_ITEM(&ipHdr->dataIPSet) &&
|
||||
@ -1152,10 +1149,8 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
|
||||
bool maySkipICMP)
|
||||
{
|
||||
char chain[MAX_CHAINNAME_LENGTH];
|
||||
char number[MAX(INT_BUFSIZE_BOUND(uint32_t),
|
||||
INT_BUFSIZE_BOUND(int))];
|
||||
char numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t),
|
||||
INT_BUFSIZE_BOUND(int))];
|
||||
char number[VIR_INT64_STR_BUFLEN];
|
||||
char numberalt[VIR_INT64_STR_BUFLEN];
|
||||
const char *target;
|
||||
bool srcMacSkipped = false;
|
||||
bool skipRule = false;
|
||||
@ -1789,16 +1784,14 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
|
||||
virNWFilterVarCombIterPtr vars,
|
||||
bool reverse)
|
||||
{
|
||||
char macaddr[VIR_MAC_STRING_BUFLEN],
|
||||
ipaddr[INET_ADDRSTRLEN],
|
||||
ipmask[INET_ADDRSTRLEN],
|
||||
ipv6addr[INET6_ADDRSTRLEN],
|
||||
number[MAX(INT_BUFSIZE_BOUND(uint32_t),
|
||||
INT_BUFSIZE_BOUND(int))],
|
||||
numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t),
|
||||
INT_BUFSIZE_BOUND(int))],
|
||||
field[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)],
|
||||
fieldalt[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)];
|
||||
char macaddr[VIR_MAC_STRING_BUFLEN];
|
||||
char ipaddr[INET_ADDRSTRLEN];
|
||||
char ipmask[INET_ADDRSTRLEN];
|
||||
char ipv6addr[INET6_ADDRSTRLEN];
|
||||
char number[VIR_INT64_STR_BUFLEN];
|
||||
char numberalt[VIR_INT64_STR_BUFLEN];
|
||||
char field[VIR_INT64_STR_BUFLEN];
|
||||
char fieldalt[VIR_INT64_STR_BUFLEN];
|
||||
char chain[MAX_CHAINNAME_LENGTH];
|
||||
const char *target;
|
||||
bool hasMask = false;
|
||||
|
@ -39,7 +39,6 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include "intprops.h"
|
||||
#include "virbuffer.h"
|
||||
#include "viralloc.h"
|
||||
#include "virlog.h"
|
||||
@ -59,10 +58,6 @@
|
||||
|
||||
VIR_LOG_INIT("nwfilter.nwfilter_learnipaddr");
|
||||
|
||||
#define IFINDEX2STR(VARNAME, ifindex) \
|
||||
char VARNAME[INT_BUFSIZE_BOUND(ifindex)]; \
|
||||
g_snprintf(VARNAME, sizeof(VARNAME), "%d", ifindex);
|
||||
|
||||
#define PKT_TIMEOUT_MS 500 /* ms */
|
||||
|
||||
/* structure of an ARP request/reply message */
|
||||
@ -239,7 +234,7 @@ static int
|
||||
virNWFilterRegisterLearnReq(virNWFilterIPAddrLearnReqPtr req)
|
||||
{
|
||||
int res = -1;
|
||||
IFINDEX2STR(ifindex_str, req->ifindex);
|
||||
g_autofree char *ifindex_str = g_strdup_printf("%d", req->ifindex);
|
||||
|
||||
virMutexLock(&pendingLearnReqLock);
|
||||
|
||||
@ -260,6 +255,7 @@ virNWFilterTerminateLearnReq(const char *ifname)
|
||||
int rc = -1;
|
||||
int ifindex;
|
||||
virNWFilterIPAddrLearnReqPtr req;
|
||||
g_autofree char *ifindex_str = NULL;
|
||||
|
||||
/* It's possible that it's already been removed as a result of
|
||||
* virNWFilterDeregisterLearnReq during learnIPAddressThread() exit
|
||||
@ -274,7 +270,7 @@ virNWFilterTerminateLearnReq(const char *ifname)
|
||||
return rc;
|
||||
}
|
||||
|
||||
IFINDEX2STR(ifindex_str, ifindex);
|
||||
ifindex_str = g_strdup_printf("%d", ifindex);
|
||||
|
||||
virMutexLock(&pendingLearnReqLock);
|
||||
|
||||
@ -294,7 +290,7 @@ bool
|
||||
virNWFilterHasLearnReq(int ifindex)
|
||||
{
|
||||
void *res;
|
||||
IFINDEX2STR(ifindex_str, ifindex);
|
||||
g_autofree char *ifindex_str = g_strdup_printf("%d", ifindex);
|
||||
|
||||
virMutexLock(&pendingLearnReqLock);
|
||||
|
||||
@ -319,7 +315,7 @@ static virNWFilterIPAddrLearnReqPtr
|
||||
virNWFilterDeregisterLearnReq(int ifindex)
|
||||
{
|
||||
virNWFilterIPAddrLearnReqPtr res;
|
||||
IFINDEX2STR(ifindex_str, ifindex);
|
||||
g_autofree char *ifindex_str = g_strdup_printf("%d", ifindex);
|
||||
|
||||
virMutexLock(&pendingLearnReqLock);
|
||||
|
||||
|
@ -68,7 +68,6 @@
|
||||
#endif
|
||||
|
||||
#include "configmake.h"
|
||||
#include "intprops.h"
|
||||
#include "viralloc.h"
|
||||
#include "vircommand.h"
|
||||
#include "virerror.h"
|
||||
@ -4067,7 +4066,7 @@ virFileReadValueInt(int *value, const char *format, ...)
|
||||
if (!virFileExists(path))
|
||||
return -2;
|
||||
|
||||
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0)
|
||||
if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
|
||||
return -1;
|
||||
|
||||
virStringTrimOptionalNewline(str);
|
||||
@ -4107,7 +4106,7 @@ virFileReadValueUint(unsigned int *value, const char *format, ...)
|
||||
if (!virFileExists(path))
|
||||
return -2;
|
||||
|
||||
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0)
|
||||
if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
|
||||
return -1;
|
||||
|
||||
virStringTrimOptionalNewline(str);
|
||||
@ -4147,7 +4146,7 @@ virFileReadValueUllong(unsigned long long *value, const char *format, ...)
|
||||
if (!virFileExists(path))
|
||||
return -2;
|
||||
|
||||
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0)
|
||||
if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
|
||||
return -1;
|
||||
|
||||
virStringTrimOptionalNewline(str);
|
||||
@ -4188,7 +4187,7 @@ virFileReadValueScaledInt(unsigned long long *value, const char *format, ...)
|
||||
if (!virFileExists(path))
|
||||
return -2;
|
||||
|
||||
if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0)
|
||||
if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0)
|
||||
return -1;
|
||||
|
||||
virStringTrimOptionalNewline(str);
|
||||
|
@ -43,7 +43,6 @@
|
||||
#include "virhostcpupriv.h"
|
||||
#include "physmem.h"
|
||||
#include "virerror.h"
|
||||
#include "intprops.h"
|
||||
#include "virarch.h"
|
||||
#include "virfile.h"
|
||||
#include "virtypedparam.h"
|
||||
@ -791,7 +790,7 @@ virHostCPUGetStatsLinux(FILE *procstat,
|
||||
char line[1024];
|
||||
unsigned long long usr, ni, sys, idle, iowait;
|
||||
unsigned long long irq, softirq, steal, guest, guest_nice;
|
||||
char cpu_header[4 + INT_BUFSIZE_BOUND(cpuNum)];
|
||||
char cpu_header[4 + VIR_INT64_STR_BUFLEN];
|
||||
|
||||
if ((*nparams) == 0) {
|
||||
/* Current number of cpu stats supported by linux */
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "virthread.h"
|
||||
#include "virfile.h"
|
||||
#include "virtime.h"
|
||||
#include "intprops.h"
|
||||
#include "virstring.h"
|
||||
#include "configmake.h"
|
||||
|
||||
@ -832,7 +831,7 @@ virLogNewOutputToSyslog(virLogPriority priority,
|
||||
# define IOVEC_SET_STRING(iov, str) IOVEC_SET(iov, str, strlen(str))
|
||||
|
||||
/* Used for conversion of numbers to strings, and for length of binary data */
|
||||
# define JOURNAL_BUF_SIZE (MAX(INT_BUFSIZE_BOUND(int), sizeof(uint64_t)))
|
||||
# define JOURNAL_BUF_SIZE (MAX(VIR_INT64_STR_BUFLEN, sizeof(uint64_t)))
|
||||
|
||||
struct journalState
|
||||
{
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "virfile.h"
|
||||
#include "viralloc.h"
|
||||
#include "virlog.h"
|
||||
#include "intprops.h"
|
||||
#include "virstring.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
@ -125,8 +124,7 @@ static int virNetDevBridgeSet(const char *brname,
|
||||
path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname);
|
||||
|
||||
if (virFileExists(path)) {
|
||||
char valuestr[INT_BUFSIZE_BOUND(value)];
|
||||
g_snprintf(valuestr, sizeof(valuestr), "%lu", value);
|
||||
g_autofree char *valuestr = g_strdup_printf("%lu", value);
|
||||
if (virFileWriteStr(path, valuestr, 0) >= 0)
|
||||
return 0;
|
||||
VIR_DEBUG("Unable to set bridge %s %s via sysfs", brname, paramname);
|
||||
@ -169,7 +167,7 @@ static int virNetDevBridgeGet(const char *brname,
|
||||
if (virFileExists(path)) {
|
||||
g_autofree char *valuestr = NULL;
|
||||
|
||||
if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long),
|
||||
if (virFileReadAll(path, VIR_INT64_STR_BUFLEN,
|
||||
&valuestr) < 0)
|
||||
return -1;
|
||||
|
||||
@ -215,7 +213,7 @@ virNetDevBridgePortSet(const char *brname,
|
||||
const char *paramname,
|
||||
unsigned long value)
|
||||
{
|
||||
char valuestr[INT_BUFSIZE_BOUND(value)];
|
||||
char valuestr[VIR_INT64_STR_BUFLEN];
|
||||
int ret = -1;
|
||||
g_autofree char *path = NULL;
|
||||
|
||||
@ -251,7 +249,7 @@ virNetDevBridgePortGet(const char *brname,
|
||||
path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname,
|
||||
paramname);
|
||||
|
||||
if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0)
|
||||
if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &valuestr) < 0)
|
||||
return -1;
|
||||
|
||||
if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) {
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "virfile.h"
|
||||
#include "viralloc.h"
|
||||
#include "virutil.h"
|
||||
#include "intprops.h"
|
||||
#include "virlog.h"
|
||||
#include "virerror.h"
|
||||
#include "virstring.h"
|
||||
@ -57,7 +56,7 @@ int virPidFileWritePath(const char *pidfile,
|
||||
{
|
||||
int rc;
|
||||
int fd;
|
||||
char pidstr[INT_BUFSIZE_BOUND(pid)];
|
||||
char pidstr[VIR_INT64_STR_BUFLEN];
|
||||
|
||||
if ((fd = open(pidfile,
|
||||
O_WRONLY | O_CREAT | O_TRUNC,
|
||||
@ -110,7 +109,7 @@ int virPidFileReadPath(const char *path,
|
||||
int rc;
|
||||
ssize_t bytes;
|
||||
long long pid_value = 0;
|
||||
char pidstr[INT_BUFSIZE_BOUND(pid_value)];
|
||||
char pidstr[VIR_INT64_STR_BUFLEN];
|
||||
char *endptr = NULL;
|
||||
|
||||
*pid = 0;
|
||||
@ -333,7 +332,7 @@ int virPidFileAcquirePath(const char *path,
|
||||
pid_t pid)
|
||||
{
|
||||
int fd = -1;
|
||||
char pidstr[INT_BUFSIZE_BOUND(pid)];
|
||||
char pidstr[VIR_INT64_STR_BUFLEN];
|
||||
|
||||
if (path[0] == '\0')
|
||||
return 0;
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#define VIR_INT64_STR_BUFLEN 21
|
||||
|
||||
char **virStringSplitCount(const char *string,
|
||||
const char *delim,
|
||||
size_t max_tokens,
|
||||
|
@ -33,7 +33,6 @@
|
||||
# include "virlog.h"
|
||||
# include "virmock.h"
|
||||
# include "rpc/virnetsocket.h"
|
||||
# include "intprops.h"
|
||||
# define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
VIR_LOG_INIT("tests.systemdtest");
|
||||
@ -548,8 +547,8 @@ testActivation(bool useNames)
|
||||
size_t nsockIP;
|
||||
int ret = -1;
|
||||
size_t i;
|
||||
char nfdstr[INT_BUFSIZE_BOUND(size_t)];
|
||||
char pidstr[INT_BUFSIZE_BOUND(pid_t)];
|
||||
char nfdstr[VIR_INT64_STR_BUFLEN];
|
||||
char pidstr[VIR_INT64_STR_BUFLEN];
|
||||
virSystemdActivationMap map[2];
|
||||
int *fds = NULL;
|
||||
size_t nfds = 0;
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include "conf/virdomainobjlist.h"
|
||||
#include "intprops.h"
|
||||
#include "viralloc.h"
|
||||
#include "virmacaddr.h"
|
||||
#include "virxml.h"
|
||||
@ -1964,7 +1963,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
bool ret = false;
|
||||
virshDomainListPtr list = NULL;
|
||||
virDomainPtr dom;
|
||||
char id_buf[INT_BUFSIZE_BOUND(unsigned int)];
|
||||
char id_buf[VIR_INT64_STR_BUFLEN];
|
||||
unsigned int id;
|
||||
unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE;
|
||||
vshTablePtr table = NULL;
|
||||
|
@ -33,11 +33,12 @@
|
||||
* so don't introduce a link time dep, which we must avoid
|
||||
*/
|
||||
#include "gnulib/lib/configmake.h"
|
||||
#include "gnulib/lib/intprops.h"
|
||||
|
||||
#define VIR_INT64_STR_BUFLEN 21
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char uidstr[INT_BUFSIZE_BOUND(uid_t)];
|
||||
char gidstr[INT_BUFSIZE_BOUND(gid_t)];
|
||||
char uidstr[VIR_INT64_STR_BUFLEN];
|
||||
char gidstr[VIR_INT64_STR_BUFLEN];
|
||||
const char * newargv[6];
|
||||
size_t nargs = 0;
|
||||
char *newenv[] = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user