Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 7cac81e

Browse files
committed
Fix Issue 23157 - undefined reference to `__cmsg_nxthdr' on Alpine Linux (musl libc)
Make __CMSG_* and __MHDR_END private
1 parent 9c0d4f9 commit 7cac81e

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/core/sys/posix/sys/socket.d

+33-3
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,40 @@ version (linux)
188188

189189
extern (D) inout(ubyte)* CMSG_DATA( return scope inout(cmsghdr)* cmsg ) pure nothrow @nogc { return cast(ubyte*)( cmsg + 1 ); }
190190

191-
private inout(cmsghdr)* __cmsg_nxthdr(inout(msghdr)*, inout(cmsghdr)*) pure nothrow @nogc;
192-
extern (D) inout(cmsghdr)* CMSG_NXTHDR(inout(msghdr)* msg, inout(cmsghdr)* cmsg) pure nothrow @nogc
191+
version (CRuntime_Musl)
193192
{
194-
return __cmsg_nxthdr(msg, cmsg);
193+
extern (D)
194+
{
195+
private size_t __CMSG_LEN(inout(cmsghdr)* cmsg) pure nothrow @nogc
196+
{
197+
return (cmsg.cmsg_len + size_t.sizeof -1) & cast(size_t)(~(size_t.sizeof - 1));
198+
}
199+
200+
private inout(cmsghdr)* __CMSG_NEXT(inout(cmsghdr)* cmsg) pure nothrow @nogc
201+
{
202+
return cmsg + __CMSG_LEN(cmsg);
203+
}
204+
205+
private inout(msghdr)* __MHDR_END(inout(msghdr)* mhdr) pure nothrow @nogc
206+
{
207+
return cast(inout(msghdr)*)(mhdr.msg_control + mhdr.msg_controllen);
208+
}
209+
210+
inout(cmsghdr)* CMSG_NXTHDR(inout(msghdr)* msg, inout(cmsghdr)* cmsg) pure nothrow @nogc
211+
{
212+
return cmsg.cmsg_len < cmsghdr.sizeof ||
213+
__CMSG_LEN(cmsg) + cmsghdr.sizeof >= __MHDR_END(msg) - cast(inout(msghdr)*)(cmsg)
214+
? cast(inout(cmsghdr)*) null : cast(inout(cmsghdr)*) __CMSG_NEXT(cmsg);
215+
}
216+
}
217+
}
218+
else
219+
{
220+
private inout(cmsghdr)* __cmsg_nxthdr(inout(msghdr)*, inout(cmsghdr)*) pure nothrow @nogc;
221+
extern (D) inout(cmsghdr)* CMSG_NXTHDR(inout(msghdr)* msg, inout(cmsghdr)* cmsg) pure nothrow @nogc
222+
{
223+
return __cmsg_nxthdr(msg, cmsg);
224+
}
195225
}
196226

197227
extern (D) inout(cmsghdr)* CMSG_FIRSTHDR( inout(msghdr)* mhdr ) pure nothrow @nogc

0 commit comments

Comments
 (0)