是将uid_t类型符号或无符号? [英] Is the uid_t type signed or unsigned?
问题描述
我知道,标准不说关于的符号性东西将uid_t
或 gid_t
。
不一致:
网页。 http://www.gnu.org/software /libc/manual/html_node/Reading-Persona.html 说:
在GNU C库,这是对的无符号整型的别名。
块引用>但
男人setreuid
说:
直供值 1 作为无论是真实或有效用户ID强制系统离开该ID不变。
块引用>问题:
那么,是
将uid_t
GNU库的符号或无符号?我如何能提供
1
如果将uid_t
和gid_t
是无符号的(1
将被转换为0xFFFFFFFF的
)?解决方案
将uid_t
是(经过一些类型定义/定义)定义为__ U32_TYPE
被定义为unsigned int类型
(这是我的Gentoo Linux系统)。但是,仅仅因为
1
有特殊的意义并不意味着UID将被限制为适合在签署INT <号码/ code>。它只是意味着最高值(即
(无符号整数)-1
)是不是一个有效的UID。在setreuid
的code可能使用该投的反向形式((符号的int)RUID
)比较虽然它接受对1
干净的将uid_t
。I know that the standard doesn't say anything about the signedness of
uid_t
orgid_t
.Inconsistency:
Page http://www.gnu.org/software/libc/manual/html_node/Reading-Persona.html says:
In the GNU C Library, this is an alias for unsigned int.
But
man setreuid
says:Supplying a value of -1 for either the real or effective user ID forces the system to leave that ID unchanged.
Questions:
So, is
uid_t
signed or unsigned in the GNU Library?How can I supply
-1
ifuid_t
andgid_t
are unsigned (-1
will be converted to0xFFFFFFFF
)?
解决方案
uid_t
is (after some typedefs/defines) defined as__U32_TYPE
which is defined asunsigned int
(that is on my Gentoo Linux system).However, just because
-1
has a special meaning it does not mean that UIDs are restricted to the numbers that fit in a signedint
. It just means that the highest value (i.e.(unsigned int)-1
) is not a valid UID. The code insetreuid
probably uses the reverse form of that cast ((signed int)ruid
) to compare against-1
cleanly although it accepts anuid_t
.这篇关于是将uid_t类型符号或无符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!