Printing uid file on linux system

I study programming. I am trying to make my own program look like the ls command , but with fewer options. What I am doing is taking the input name of the directory / file as an argument, and then getting the whole entry in the directory using dirent struct (if it's a directory).

After that I use stat () to take all the information about the file, but here is my problem when I use write () to print these values ​​in order, but when I want to print them using printf (), I get a warning: format '% ld expects type' long int, but argument 2 is of type '__uid_t. I do not know what to use in place of % ld , as well as for other special data types.

+3
source share
2 answers

There is no format specifier for __uid_t , because this type is a system type and is not part of the C standard, and therefore printf not aware of this.

The usual workaround is to push it to a type that matches the entire range of UID values ​​in all the systems you are targeting:

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

You can overlay it on a long int:

 printf("foobar: %ld\n", (long int)your_uid_t_variable); 
+1
source

All Articles