Skip to content

Commit

Permalink
MDEV-35578 innodb_gis.rtree_debug fails on mac
Browse files Browse the repository at this point in the history
strerror_s on Linux will, for unknown error codes, display
'Unknown error <codenum>' and our tests are written with this assumption.
However, on macOS, sterror_s returns 'Unknown error: <codenum>' in the
same case, which breaks tests.  Make my_strerror consistent across the
platforms by removing the ':' when present.
  • Loading branch information
DaveGosselin-MariaDB authored and grooverdan committed Dec 18, 2024
1 parent 7b0f59d commit a226f12
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions strings/my_vsnprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,27 @@ int my_fprintf(FILE *stream, const char* format, ...)
}


#ifdef __APPLE__
/* Delete the ':' character added by Apple's implementation of strerror_r */
static void delete_colon_char(char *buf)
{
static const char *unknown_err= "Unknown error";
static const size_t unknown_err_len= 13;
char *ptr= strstr(buf, unknown_err);
char *src= NULL;
if (ptr) {
ptr+= unknown_err_len;
if (*ptr == ':') {
// just overwrite the colon by shifting everything down by one,
// e.g. "Unknown error: 1000" becomes "Unknown error 1000"
src= ptr + 1;
memmove(ptr, src, strlen(src) + 1); // include null
}
}
}
#endif


/*
Return system error text for given error number
Expand Down Expand Up @@ -913,6 +934,10 @@ const char* my_strerror(char *buf, size_t len, int nr)
#else
strerror_r(nr, buf, len);
#endif

#ifdef __APPLE__
delete_colon_char(buf);
#endif
}

/*
Expand Down

0 comments on commit a226f12

Please sign in to comment.