rwx r-x r-x
In this case, the owner has read, write, and execute permissions, the group has only read and execute permissions, and the user also has only read and execute permissions.
111 101 101
So, the permissions for the file would be recorded internally as 755.
opensystem call, and you can set the permissions at that time, as well. We will discuss the idea of system calls soon, but for now, simply think of them as a function that can do systemsy stuff. The open function comes with the following signatures (and this works in C, even though C does not support function overloading! How, you ask? See here.)
There are many flags (see man 2 open for a list of them), and they can be bitwise or'd together. You must include exactly one of the following flags:
O_RDONLY: read only
O_WRONLY: write only
O_RDWR: read and write
/usr/class/cs110/lecture-examplesdirectory is a
gitrepository that will be updated with additional examples as the quarter progresses.
/usr/class/cs110/lecture-examples lecture-examplesat the command prompt to create your own local copy.
pull. Doing so will update your local copy to match whatever the primary has become.
teeprogram that ships with Linux copies everything from standard input to standard output, making zero or more extra copies in the named files supplied as user program arguments.
If the file
vowels.txt contains the five vowels and the newline character, and
tee is invoked as follows,
one.txt would be rewritten to contain only the English vowels.
argcincidentally equals the number of descriptors we need to write to. That's why we declare an int array (or rather, a descriptor array) of length
STDIN_FILENOis a built-in constant for the number 0, which is the descriptor normally linked to standard input.
STDOUT_FILENOis a constant for the number 1, which is the default descriptor bound to standard output.
lstatare system calls that populate a
statwith information about some named file. The prototypes of the two are:
lstatoperate exactly the same way, except when the named file is a link,
statreturns information about the file the link ultimately references, and
lstatreturns information about the link itself.
st_modefield—which is the only one we'll really pay much attention to—isn't so much a single value as it is a collection of bits encoding multiple pieces of information about file type and permissions. A collection of bit masks and macros can be used to extract information from this
I won't be formally covering stat in lecture, but I will refer to these in future lectures when stat is needed. Still, cool stuff!
listMatchesmakes use of three library functions to iterate over all files within a directory. Let's play with those before tackling listMatches.
opendirgets anything other than an accessible directory, it returns
dehas surfaced all entries,
direntis only guaranteed to contain a
d_namefield, which stores the entry's name as a C string.
..are included in the sequence of named entries.
.., else we're threatened with infinite recursion.
statso we know whether an entry is a link. We ignore all links because, again, we want to avoid infinite recursion.
statrecord identifies something as a regular file, we print the entire path if and only if the entry name matches the name of interest.
statrecord identifies something as a directory, we recursively dip into it to see if any descendents match