~rabbits/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
6 4

[PATCH] Declare snprintf to fix builds on macOS

Details
Message ID
<20230501054244.85763-1-matus@laslofi.sk>
DKIM signature
missing
Download raw message
Patch: +4 -0
For some reason on macOS, the functions `snprintf` and `vsnprintf` are
not in the X/Open 5 (ANSI C89) standard but rather in the X/Open
6 (ISO C99). A simplest solution seems to be to declaring the missing
functions before using them, which is what I did here. Another option
is to use the C99 standard with `#define _XOPEN_SOURCE 600`, which
seems to be an overkill for such a niche issue.

Quoting from the STANDARDS section in `man 3 snprintf` on macOS:

> ...the snprintf() and vsnprintf() functions conform to ISO/IEC
> 9899:1999 (“ISO C99”)...
---
 src/devices/file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/devices/file.c b/src/devices/file.c
index a208b8f..bc7c4fd 100644
--- a/src/devices/file.c
+++ b/src/devices/file.c
@@ -26,6 +26,10 @@
#define PATH_MAX 4096
#endif

#ifdef __APPLE__
int snprintf(char *, unsigned long, const char *, ...);
#endif

#include "../uxn.h"
#include "file.h"

-- 
2.39.0
Details
Message ID
<CAKis=aFh5LPgzRx0w=hVz19SmZbwSbOb94_QFPmE5DoTsJhCwQ@mail.gmail.com>
In-Reply-To
<20230501054244.85763-1-matus@laslofi.sk> (view parent)
DKIM signature
missing
Download raw message
Thanks Matus,

Someone was hitting that same issue just yesterday, hopefully this
will help them with their issue, merged :)

On 4/30/23, Matus Laslofi <matus@laslofi.sk> wrote:
> For some reason on macOS, the functions `snprintf` and `vsnprintf` are
> not in the X/Open 5 (ANSI C89) standard but rather in the X/Open
> 6 (ISO C99). A simplest solution seems to be to declaring the missing
> functions before using them, which is what I did here. Another option
> is to use the C99 standard with `#define _XOPEN_SOURCE 600`, which
> seems to be an overkill for such a niche issue.
>
> Quoting from the STANDARDS section in `man 3 snprintf` on macOS:
>
>> ...the snprintf() and vsnprintf() functions conform to ISO/IEC
>> 9899:1999 (“ISO C99”)...
> ---
>  src/devices/file.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/src/devices/file.c b/src/devices/file.c
> index a208b8f..bc7c4fd 100644
> --- a/src/devices/file.c
> +++ b/src/devices/file.c
> @@ -26,6 +26,10 @@
>  #define PATH_MAX 4096
>  #endif
>
> +#ifdef __APPLE__
> +int snprintf(char *, unsigned long, const char *, ...);
> +#endif
> +
>  #include "../uxn.h"
>  #include "file.h"
>
> --
> 2.39.0
>
>
Details
Message ID
<791p55r0-ns11-prr9-3p43-os81oqq0r184@fncre.vasb>
In-Reply-To
<CAKis=aFh5LPgzRx0w=hVz19SmZbwSbOb94_QFPmE5DoTsJhCwQ@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
On Mon, 1 May 2023, Hundred Rabbits wrote:

> Thanks Matus,
>
> Someone was hitting that same issue just yesterday, hopefully this
> will help them with their issue, merged :)

Would

#ifndef snprintf

also work?
Details
Message ID
<CAKis=aEeWpr64ZA4x1T+=gzgQG2r7FOcEyQJRnD2LDsAhc4Zrw@mail.gmail.com>
In-Reply-To
<791p55r0-ns11-prr9-3p43-os81oqq0r184@fncre.vasb> (view parent)
DKIM signature
missing
Download raw message
I don't have an Apple system to test this with, but @tendigits
reported that this fixed the problem for them.

On 5/1/23, Marcin Cieslak <saper@saper.info> wrote:
> On Mon, 1 May 2023, Hundred Rabbits wrote:
>
>> Thanks Matus,
>>
>> Someone was hitting that same issue just yesterday, hopefully this
>> will help them with their issue, merged :)
>
> Would
>
> #ifndef snprintf
>
> also work?
>
Details
Message ID
<BF296C13-F557-4EC6-92EB-18F6A177B0B1@laslofi.sk>
In-Reply-To
<CAKis=aEeWpr64ZA4x1T+=gzgQG2r7FOcEyQJRnD2LDsAhc4Zrw@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
> Would
> 
> #ifndef snprintf
> 
> also work?

Just tested this and yes, it works. However I have no idea if one is “better" over the other.
Details
Message ID
<EC6C50813D80D804125E0476CAEF9195@ftrv.se>
In-Reply-To
<BF296C13-F557-4EC6-92EB-18F6A177B0B1@laslofi.sk> (view parent)
DKIM signature
missing
Download raw message
It'd also work, but only because snprintf is not a define. Imo, this is just wrong way to fix this.
Details
Message ID
<r42rn7qn-4s9q-sr77-5srs-0q59qroo5s31@fncre.vasb>
In-Reply-To
<EC6C50813D80D804125E0476CAEF9195@ftrv.se> (view parent)
DKIM signature
missing
Download raw message
On Tue, 2 May 2023, Sigrid Solveig Haflínudóttir wrote:

> It'd also work, but only because snprintf is not a define. Imo, this is just wrong way to fix this.

Sorry, forget my babble. I've played too much with the macros that day. You are of course correct.

I just dislike the code sprinkled with some crazy system-specific #ifdefs
Reply to thread Export thread (mbox)