opal: minor update to guess_strlen
This is a minor update to open-mpi/ompi@c52601f0c5. If we have vsnprintf(), we might as well not have the rest of the guess_strlen() routine. Also document the nifty trick/behavior of vsnprintf() that enables this shortcut (it was new to me!).
Этот коммит содержится в:
родитель
3430714989
Коммит
9e6b157cb6
@ -9,7 +9,7 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -40,6 +40,13 @@
|
||||
*/
|
||||
static int guess_strlen(const char *fmt, va_list ap)
|
||||
{
|
||||
#if HAVE_VSNPRINTF
|
||||
char dummy[1];
|
||||
|
||||
/* vsnprintf() returns the number of bytes that would have been
|
||||
copied if the provided buffer were infinite. */
|
||||
return 1 + vsnprintf(dummy, sizeof(dummy), fmt, ap);
|
||||
#else
|
||||
char *sarg, carg;
|
||||
double darg;
|
||||
float farg;
|
||||
@ -48,13 +55,6 @@ static int guess_strlen(const char *fmt, va_list ap)
|
||||
int len;
|
||||
long larg;
|
||||
|
||||
#if HAVE_VSNPRINTF
|
||||
{
|
||||
char dummy[1];
|
||||
return 1 + vsnprintf(dummy, sizeof(dummy), fmt, ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Start off with a fudge factor of 128 to handle the % escapes that
|
||||
we aren't calculating here */
|
||||
|
||||
@ -190,6 +190,7 @@ static int guess_strlen(const char *fmt, va_list ap)
|
||||
}
|
||||
|
||||
return len;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user