Linux系统上的文件打印UID [英] printing uid of a file on linux system

查看:300
本文介绍了Linux系统上的文件打印UID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习C语言编程。我努力使自己的程序类似的 LS 命令,但用量少options.what我做的是采取输入目录/文件名作为参数,然后用得到的的dirent 结构(如果是目录)。

i am learning c programming. I am trying to make my own program similar to ls command but with less options.what i am doing is taking input directory/file name as argument and then gets all directory entry with dirent struct(if it is directory) .

在这我使用stat()取文件的所有信息,但这里是我的问题,当我使用write()来打印这些看重其优良的,但是当我想用printf的打印这些()我得到warninng:格式'%ld个'需要键入长整型,但参数2的类型__uid_t。我不知道什么应该在的地方使用%LD ,也为其他特殊的数据类型。

After it i use stat() to take all information of the file but here is my problem when i use write() to print these value its fine but when i want to print these with printf() i get warninng : format ‘%ld’ expects type ‘long int’, but argument 2 has type ‘__uid_t’. I don't know what should use at place of %ld and also for other special data types.

推荐答案

有是 __将uid_t 无格式说明,因为这种类型是系统特定的,不是部分的C标准,因此的printf 是没有意识到这一点。

There is no format specifier for __uid_t, because this type is system-specific and is not the part of C standard, and hence printf is not aware of it.

通常的解决方法是将其提升到能够适合所有的你的目标系统UID值的整个范围内的类型:

The usual workaround is to promote it to a type that would fit the entire range of UID values on all the systems you are targeting:

printf("%lu\n", (unsigned long int)uid); /* some systems support 32-bit UIDs */

这篇关于Linux系统上的文件打印UID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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