On 10/5/20 9:04 AM, Richard W.M. Jones wrote:
IIUC, gid_t/uid_t don't have their signed-ness specified by POSIX, nor size, but you're required to cast negative values eg
gid_t foo = (gid_t)-1;
based on this, libvirt chose to expose them as "unsigned long long" to maximise future proofing.
We need an in-band error indication. I wonder if there are systems with valid UID or GID == (uint64_t)-1 ?
No. POSIX chown() ensures that that ([ug]id_t)(-1) can only be used as markers, never as valid ids. Thus they are always safe for in-band error indication. But Dan is correct that because it is unspecified if [ug]id_t is signed or unsigned, and also unspecified whether they are 16-, 32-, or 64-bit quantities, makes it mandatory to write the cast (that is, you HAVE to use ((uid_t)(-1)) instead of assuming that -1 will promote to the correct type). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org