Course Homepage

HW7

  1. How can we determine whether two paths refer to the same file?

  2. What flag to the open() system call will create a file if it doesn’t exist already? (See lecture notes and/or man 2 open.)

  3. What happens if we try to open a file that does not exist?

  4. What flag truncates a file upon opening?

  5. What happens if we open a file that already exists for writing, without truncating it, and then write bytes to it?

  6. Write a snippet of C code that uses a syscall to open a file called “hello” for writing, creating it if it doesn’t exist, but truncating if it does. Remember to include error checking that exits with EXIT_FAILURE if the call to open() fails.