是将uid_t类型符号或无符号? [英] Is the uid_t type signed or unsigned?

查看:180
本文介绍了是将uid_t类型符号或无符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,标准不说关于的符号性东西将uid_t gid_t

不一致:

网页。 http://www.gnu.org/software /libc/manual/html_node/Reading-Persona.html 说:


  

在GNU C库,这是对的无符号整型的别名。


男人setreuid 说:


  

直供值 1 作为无论是真实或有效用户ID强制系统离开该ID不变。


问题:


  1. 那么,是将uid_t GNU库的符号或无符号?


  2. 我如何能提供 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 or gid_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:

  1. So, is uid_t signed or unsigned in the GNU Library?

  2. How can I supply -1 if uid_t and gid_t are unsigned (-1 will be converted to 0xFFFFFFFF)?

解决方案

uid_t is (after some typedefs/defines) defined as __U32_TYPE which is defined as unsigned 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 signed int. It just means that the highest value (i.e. (unsigned int)-1) is not a valid UID. The code in setreuid probably uses the reverse form of that cast ((signed int)ruid) to compare against -1 cleanly although it accepts an uid_t.

这篇关于是将uid_t类型符号或无符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆