Skip to content

Commit

Permalink
Merge remote-tracking branch 'mpg123/master' into master-with-github-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mpg123 GitHub bot committed Jan 4, 2025
2 parents 95bf436 + 855f5ee commit d3b64ec
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
1.32.11
------
- compat: Map strtok use to strtok_r or strtok_s (MS platforms), if possible.
users only in control_generic and libout123 so far. Out123 itself uses mytok.
Shall fix bug 376 (build with MSVC again).
- mpg123: Fix printout of filenames at end (convert/limit text encoding).
- libout123:
-- modules/win32: Align waveOutGetDevCapsA to WAVEOUTCAPSA, in anticipation
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,8 @@ AC_CHECK_FUNCS( sched_setscheduler setuid getuid)
# Check for setpriority
AC_CHECK_FUNCS( setpriority )

AC_CHECK_FUNCS( strerror strerror_l uselocale )
# strtok_s for MSVCRT, not the C11 variant
AC_CHECK_FUNCS( strerror strerror_l uselocale strtok_r strtok_s)

AC_CHECK_FUNCS( setlocale nl_langinfo mbstowcs wcstombs wcswidth iswprint )

Expand Down
2 changes: 2 additions & 0 deletions ports/cmake/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ check_function_exists(shmdt HAVE_SHMDT)
check_function_exists(shmctl HAVE_SHMCTL)
check_function_exists(strerror HAVE_STRERROR)
check_function_exists(strerror_l HAVE_STRERROR_L)
check_function_exists(strtok_r HAVE_STRTOK_R)
check_function_exists(strtok_s HAVE_STRTOK_S)
check_function_exists(fork HAVE_FORK)
check_function_exists(execvp HAVE_EXECVP)
check_function_exists(ctermid HAVE_CTERMID)
Expand Down
2 changes: 2 additions & 0 deletions ports/cmake/src/config.cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#cmakedefine HAVE_SIGNAL_H 1
#cmakedefine HAVE_STRERROR 1
#cmakedefine HAVE_STRERROR_L 1
#cmakedefine HAVE_STRTOK_R 1
#cmakedefine HAVE_STRTOK_S 1
#cmakedefine HAVE_FORK 1
#cmakedefine HAVE_EXECVP 1
#cmakedefine HAVE_CTERMID 1
Expand Down
14 changes: 14 additions & 0 deletions src/compat/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,17 @@

typedef unsigned char byte;

// Annoying hackery to select a safe strtok variant. MS decided to call their strtok_r strtok_s, while
// C11 declares another strtok_s with different prototype. Thanks to you all.
#ifdef HAVE_STRTOK_R
#define INT123_compat_strtok(a, b, c) strtok_r((a), (b), (c))
#endif

#if (defined(_UCRT) || defined(_MSC_VER) || (defined(__MINGW32__) || defined(__MINGW64__)) || (defined(__WATCOMC__) && defined(__NT__))) && !defined(__CYGWIN__)
#define MPG123_COMPAT_MSVCRT_IO
#ifndef INT123_compat_strtok
#define INT123_compat_strtok(a, b, c) strtok_s((a), (b), (c))
#endif
#endif

#if defined(MPG123_COMPAT_MSVCRT_IO)
Expand Down Expand Up @@ -150,6 +159,11 @@ typedef unsigned char byte;
#include <io.h>
#endif

#ifndef INT123_compat_strtok
#warning "no safe strtok found"
#define INT123_compat_strtok(a, b, c) strtok((a), (b))
#endif

/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
void *INT123_safe_realloc(void *ptr, size_t size);
// Also freeing ptr if result is NULL. You can do
Expand Down
5 changes: 3 additions & 2 deletions src/control_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,9 @@ int control_generic (mpg123_handle *fr)
/* commands with arguments */
cmd = NULL;
arg = NULL;
cmd = strtok(comstr," \t"); /* get the main command */
arg = strtok(NULL,""); /* get the args */
char *toksave = NULL;
cmd = INT123_compat_strtok(comstr, " \t", &toksave); /* get the main command */
arg = INT123_compat_strtok(NULL, "", &toksave); /* get the args */

if (cmd && strlen(cmd) && arg && strlen(arg))
{
Expand Down
4 changes: 2 additions & 2 deletions src/libout123/libout123.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ out123_open(out123_handle *ao, const char* driver, const char* device)

/* Now loop over the list of possible modules to find one that works. */
char *toksave = NULL;
nextname = strtok_r(modnames, ",", &toksave);
nextname = INT123_compat_strtok(modnames, ",", &toksave);
while(!ao->open && nextname)
{
char *curname = nextname;
nextname = strtok_r(NULL, ",", &toksave);
nextname = INT123_compat_strtok(NULL, ",", &toksave);
check_output_module(ao, curname, device, !nextname);
if(ao->open)
{
Expand Down

0 comments on commit d3b64ec

Please sign in to comment.