Use epicsSnprintf() for old MSVC compilers

This commit is contained in:
Andrew Johnson
2023-12-14 11:27:30 -06:00
parent 5ecf7d18a8
commit 2e6fd505d2
6 changed files with 13 additions and 12 deletions

View File

@@ -25,6 +25,7 @@
#include <stdexcept>
#include <string> // vxWorks 6.0 requires this include
#include "epicsStdio.h"
#include "dbDefs.h"
#include "epicsGuard.h"
#include "epicsVersion.h"
@@ -1008,7 +1009,7 @@ bool cac::defaultExcep (
char buf[512];
char hostName[64];
iiu.getHostName ( guard, hostName, sizeof ( hostName ) );
snprintf( buf, sizeof(buf), "host=%s ctx=%.400s", hostName, pCtx );
epicsSnprintf( buf, sizeof(buf), "host=%s ctx=%.400s", hostName, pCtx );
this->notify.exception ( guard, status, buf, 0, 0u );
return true;
}
@@ -1312,7 +1313,7 @@ void cac::pvMultiplyDefinedNotify ( msgForMultiplyDefinedPV & mfmdpv,
const char * pChannelName, const char * pAcc, const char * pRej )
{
char buf[256];
snprintf( buf, sizeof(buf), "Channel: \"%.64s\", Connecting to: %.64s, Ignored: %.64s",
epicsSnprintf( buf, sizeof(buf), "Channel: \"%.64s\", Connecting to: %.64s, Ignored: %.64s",
pChannelName, pAcc, pRej );
{
callbackManager mgr ( this->notify, this->cbMutex );

View File

@@ -238,7 +238,7 @@ size_t epicsStdCall epicsTimeToStrftime (char *pBuff, size_t bufLength, const ch
// convert nanosecs to integer of correct range
frac /= div[fracWid];
char fracFormat[32];
snprintf ( fracFormat, sizeof ( fracFormat ), "%%0%lulu", fracWid );
epicsSnprintf ( fracFormat, sizeof ( fracFormat ), "%%0%lulu", fracWid );
int status = epicsSnprintf ( pBufCur, bufLenLeft, fracFormat, frac );
if ( status > 0 ) {
unsigned long nChar = static_cast < unsigned long > ( status );

View File

@@ -16,12 +16,12 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "epicsStdio.h"
#include "epicsThread.h"
#include "epicsEvent.h"
#include "epicsMutex.h"
@@ -244,7 +244,7 @@ MAIN(epicsEventTest)
name = (char **)calloc(nthreads, sizeof(char *));
for(int i = 0; i < nthreads; i++) {
name[i] = (char *)calloc(16, sizeof(char));
snprintf(name[i], 16, "producer %d",i);
epicsSnprintf(name[i], 16, "producer %d",i);
id[i] = epicsThreadCreate(name[i], 40, stackSize, producer, pinfo);
epicsThreadSleep(0.1);
}

View File

@@ -10,11 +10,11 @@
/*
* Author W. Eric Norum
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "epicsStdio.h"
#include "epicsMessageQueue.h"
#include "epicsThread.h"
#include "epicsExit.h"
@@ -232,7 +232,7 @@ sender(void *arg)
int i = 0;
while (!sendExit) {
len = snprintf(cbuf, sizeof(cbuf), "%s -- %d.", epicsThreadGetNameSelf(), ++i);
len = epicsSnprintf(cbuf, sizeof(cbuf), "%s -- %d.", epicsThreadGetNameSelf(), ++i);
while (q->trySend((void *)cbuf, len) < 0)
epicsThreadSleep(0.005 * (randBelow(5)));
epicsThreadSleep(0.005 * (randBelow(20)));
@@ -421,7 +421,7 @@ extern "C" void messageQueueTest(void *parm)
epicsThreadPriorityHigh,
epicsThreadPriorityHigh
};
snprintf(name, sizeof(name), "Sender %d", i+1);
epicsSnprintf(name, sizeof(name), "Sender %d", i+1);
opts.priority = pri[i];
senderId[i] = epicsThreadCreateOpt(name, sender, &q1, &opts);
if (!senderId[i])

View File

@@ -18,10 +18,10 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include "epicsStdio.h"
#include "epicsTime.h"
#include "epicsThread.h"
#include "epicsMutex.h"
@@ -266,7 +266,7 @@ MAIN(epicsMutexTest)
stackSize = epicsThreadGetStackSize(epicsThreadStackSmall);
for(i=0; i<nthreads; i++) {
name[i] = (char *)calloc(10,sizeof(char));
snprintf(name[i], 10, "task%d",i);
epicsSnprintf(name[i], 10, "task%d",i);
pinfo[i] = (info *)calloc(1,sizeof(info));
pinfo[i]->threadnum = i;
pinfo[i]->mutex = mutex;

View File

@@ -13,11 +13,11 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <math.h>
#include "epicsStdio.h"
#include "epicsThread.h"
#include "epicsEvent.h"
#include "epicsTime.h"
@@ -73,7 +73,7 @@ void testMyThread()
int startPriority = 0;
for (int i = 0; i < ntasks; i++) {
char name[10];
snprintf(name, sizeof(name), "t%d", i);
epicsSnprintf(name, sizeof(name), "t%d", i);
myThreads[i] = new myThread(i, name);
if (i == 0)
startPriority = myThreads[i]->thread.getPriority();