Getting access rights and ownership
In this recipe, we'll write a program that reads the access rights and ownership of a file using the stat()
system call we have seen previously in this chapter. We will continue to build upon the my-stat-v1
program that we built in the first recipe in this chapter. Here we will add the features to show ownership and access rights as well. Knowing how to get the owner and access rights programmatically is key to working with files and directories. It will enable you to check whether the user has the appropriate permissions and print an error message if they haven't.
We will also learn how access rights are interpreted in Linux and how to convert between numerical representation and letter representation. Understanding access rights in Linux is key to being a Linux system programmer. Every file and directory on the entire system has access rights and an owner and a group assigned to them. It doesn't matter whether it's a log...