group_member missing.

6 views
Skip to first unread message

Pascal via Darwin-dev

unread,
Feb 17, 2020, 11:17:47 AM2/17/20
to darwi...@lists.apple.com
Hello,

I've come up on a compilation issue which asks for group_member.
It is part of unistd.h:
http://man7.org/linux/man-pages/man3/group_member.3.html

It seems missing in macOS / Darwin includes.
Is there a way to emulate it?

Thanks, Pascal.
https://blady.pagesperso-orange.fr


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (Darwi...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/darwin-dev/darwin-dev-garchive-73044%40googlegroups.com

This email sent to darwin-dev-g...@googlegroups.com

Sandor Szatmari via Darwin-dev

unread,
Feb 17, 2020, 12:51:57 PM2/17/20
to Pascal, darwi...@lists.apple.com
I’m assuming you mean the precompile/compile fails with a ‘can’t find the header’ and not a linker error that the symbol doesn’t exist.

Maybe copy the relevant declaration/definitions into your own header file, but wrap them in a #ifndef <SOME_SYMBOL> block to prevent double include? Not sure how to ensure your private header would always be included second if this symbol reappeared in future releases.

Also, submit a notification of the maintainer of the header to get it re-included?

Sandor

> On Feb 17, 2020, at 11:17, Pascal via Darwin-dev <darwi...@lists.apple.com> wrote:
>
> Hello,


>
> I've come up on a compilation issue which asks for group_member.
> It is part of unistd.h:
> http://man7.org/linux/man-pages/man3/group_member.3.html
>
> It seems missing in macOS / Darwin includes.
> Is there a way to emulate it?
>
> Thanks, Pascal.
> https://blady.pagesperso-orange.fr
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Darwin-dev mailing list (Darwi...@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:

> https://lists.apple.com/mailman/options/darwin-dev/admin.szatmari.net%40gmail.com
>
> This email sent to admin.sza...@gmail.com

Jens Alfke via Darwin-dev

unread,
Feb 17, 2020, 1:00:42 PM2/17/20
to Sandor Szatmari, Pascal, darwi...@lists.apple.com


On Feb 17, 2020, at 9:51 AM, Sandor Szatmari via Darwin-dev <darwi...@lists.apple.com> wrote:

I’m assuming you mean the precompile/compile fails with a ‘can’t find the header’ and not a linker error that the symbol doesn’t exist.

No, the <unistd.h> header exists on Darwin. The OP is referring to the _function_ group_member(), which seems to be Linux-specific, not part of any portable API.

It would have to be emulated … I don't know much about the users & groups related system calls, so I don't have any suggestions about how.

—Jens


Jonas Maebe via Darwin-dev

unread,
Feb 17, 2020, 1:05:19 PM2/17/20
to darwi...@lists.apple.com
On 17/02/2020 17:17, Pascal via Darwin-dev wrote:
> Hello,
>
> I've come up on a compilation issue which asks for group_member.
> It is part of unistd.h:
> http://man7.org/linux/man-pages/man3/group_member.3.html
>
> It seems missing in macOS / Darwin includes.
> Is there a way to emulate it?

The linked man page says that it does the same as checking whether the
passed gid is in the result of getgroups. getgroups does exist on Darwin.


Jonas

Sandor Szatmari via Darwin-dev

unread,
Feb 17, 2020, 1:24:02 PM2/17/20
to Jens Alfke, Pascal, darwi...@lists.apple.com
Ahh, Got it.

This is what I’ve used for that in the past


Pascal,

Could you emulate your needs with it?

Sandor

On Feb 17, 2020, at 13:00, Jens Alfke <je...@mooseyard.com> wrote:



Pascal via Darwin-dev

unread,
Feb 19, 2020, 2:30:03 PM2/19/20
to Sandor Szatmari, darwi...@lists.apple.com

> Le 17 févr. 2020 à 19:23, Sandor Szatmari <admin.sza...@gmail.com> a écrit :
>
> Ahh, Got it.
>
> This is what I’ve used for that in the past
>
> https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getpwuid.3.html
>
> Pascal,
>
> Could you emulate your needs with it?

Hello,

I haven't found how to use the previous link for groups.

But after I've found the following link:
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getgrouplist.3.html

And an example:
http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fg%2Fgetgrouplist.html

My emulation code is then:
#ifdef __APPLE__
int group_member(gid_t gid) {
int ngroups, i, ret;
int groups[NGROUPS_MAX];

ngroups = NGROUPS_MAX;
if (getgrouplist(getlogin(), -1, groups, &ngroups) == -1) {
printf ("Groups array is too small: %d\n", ngroups);
}
ret = 0;
for (i = 0; i < ngroups; i++) {
if (gid == groups[i])
ret = i;
}
return ret;
}
#endif

Regards, Pascal.
https://blady.pagesperso-orange.fr

Sandor Szatmari via Darwin-dev

unread,
Feb 19, 2020, 4:17:27 PM2/19/20
to Pascal, darwi...@lists.apple.com
Pascal,

Thanks for sharing your solution!  Might I suggest… based on my read of the group_member() man page, it does not specify the value returned, merely that upon success it is non-zero. My thought is why continue the loop once success is determined.  See below.

Sandor

NOTE: I read the first man page google showed me so this may not be current.

On Feb 19, 2020, at 14:37, Pascal <sur.p...@wanadoo.fr> wrote:


Le 17 févr. 2020 à 19:23, Sandor Szatmari <admin.sza...@gmail.com> a écrit :

Ahh, Got it.

This is what I’ve used for that in the past

https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getpwuid.3.html

Pascal,

Could you emulate your needs with it?

Hello,

I haven't found how to use the previous link for groups.

But after I've found the following link:
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getgrouplist.3.html

And an example:
http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fg%2Fgetgrouplist.html

My emulation code is then:
#ifdef __APPLE__
int group_member(gid_t gid) {
int ngroups, i, ret;
int groups[NGROUPS_MAX];

ngroups = NGROUPS_MAX;
if (getgrouplist(getlogin(), -1, groups, &ngroups) == -1) {
  printf ("Groups array is too small: %d\n", ngroups);
}
ret = 0;
for (i = 0; i < ngroups; i++) {
  if (gid == groups[i])
    {
      ret = 1; // or i++, 42, handle match on first iteration
      break;

Pascal via Darwin-dev

unread,
Feb 20, 2020, 10:51:35 AM2/20/20
to Sandor Szatmari, darwi...@lists.apple.com

> Le 19 févr. 2020 à 22:17, Sandor Szatmari <admin.sza...@gmail.com> a écrit :
>
> Pascal,
>
> Thanks for sharing your solution! Might I suggest… based on my read of the group_member() man page, it does not specify the value returned, merely that upon success it is non-zero. My thought is why continue the loop once success is determined. See below.

Thanks Sandor for the fix.
I've corrected my code with your's.

Reply all
Reply to author
Forward
0 new messages