mirror of
https://repo.or.cz/socat.git
synced 2025-07-06 13:06:33 +00:00
Red Hat issue 1021948: snprintf API change
This commit is contained in:
parent
52e8a5ec2b
commit
cf39583b25
8 changed files with 74 additions and 53 deletions
21
utils.c
21
utils.c
|
@ -1,5 +1,5 @@
|
|||
/* source: utils.c */
|
||||
/* Copyright Gerhard Rieger 2001-2009 */
|
||||
/* Copyright Gerhard Rieger */
|
||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||
|
||||
/* useful additions to C library */
|
||||
|
@ -161,3 +161,22 @@ char *xiosubstr(char *scratch, const char *str, size_t from, size_t len) {
|
|||
return scratch0;
|
||||
}
|
||||
|
||||
|
||||
/* since version 1.7.2.4 socat supports C-99 behaviour of snprintf but still
|
||||
can handle the old glibc case with -1 return on truncation.
|
||||
Do not rely on exact return value in case of truncation
|
||||
*/
|
||||
int xio_snprintf(char *str, size_t size, const char *format, ...) {
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start(ap, format);
|
||||
result = vsnprintf(str, size, format, ap);
|
||||
#if ! HAVE_C99_SNPRINTF
|
||||
if (result < 0) {
|
||||
result = size+63; /* indicate truncation with just some guess */
|
||||
}
|
||||
#endif /* !HAVE_C99_SNPRINTF */
|
||||
va_end(ap);
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue