Skip to content

Commit

Permalink
Support older mac0S versions that lack vdprintf()
Browse files Browse the repository at this point in the history
Define and call an alternative vdprintf(), only
if the genuine vdprintf() does not exist.
  • Loading branch information
DimitriPapadopoulos committed Jun 6, 2024
1 parent 371edb5 commit c54ef1a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ write \
], [], AC_MSG_ERROR([Required function not found]))

# Checks for optional functions.
AC_CHECK_FUNCS([pthread_mutexattr_setrobust])
AC_CHECK_FUNCS([ \
pthread_mutexattr_setrobust \
vdprintf \
])

# Use PKG_CHECK_MODULES compiler/linker flags
save_openssl_CPPFLAGS="${CPPFLAGS}"
save_openssl_LIBS="${LIBS}"
Expand Down
16 changes: 16 additions & 0 deletions src/userinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ static int pinentry_read(int from, char **retstr)
return -1;
}

#ifndef HAVE_VDPRINTF
static int vdprintf(int fd, const char *format, va_list ap)
{
char buffer[2049];
int size = vsnprintf(buffer, sizeof(buffer), format, ap);

if (size < 0)
return size;

if (size >= sizeof(buffer)) // silently discard beyond the buffer size
size = sizeof(buffer) - 1;

return (int) write(fd, buffer, size);
}
#endif

static int pinentry_exchange(int to, int from, char **retstr,
const char *format, ...)
{
Expand Down

0 comments on commit c54ef1a

Please sign in to comment.