Lecture 01 Flashcards
What is POSIX?
A standard that attempts to define a common API across operating systems.
Which of the following OSes is not POSIX compliant?
Linux
Windows
MacOS
Windows.
Of course it’s fucking Windows.
What unix command is used to access the manual page for a given tool or library?
man
What is the function prototype for the function ‘open’?
int open(const char* pathname, int flags);
What different values can be passed as flags to the open() function?
O_RDONLY O_WRONLY O_RDWR O_TRUNC O_CREAT
What is the function prototype for read()?
ssize_t(int fd, void *buf, size_t count);
Why does read() return a ssize_t and not a size_t?
What’s the difference?
A ssize_t is a signed size_t.
read uses this so it can return -1 in the event of an error.
What function can be used to create a new file?
creat
What is the function prototype for creat?
int creat(const char* pathname, mode_t mode);
What stream number is stdin?
0
What stream number is stdout?
1
What stream number is stderr?
2
What is the function prototype for lseek?
off_t lseek(int fildes, off_t offset, int whence);
What does lseek do when whence is equal to ‘SEEK_SET’?
Sets the position to offset bytes from the start of the file.
What does lseek do when whence is equal to ‘SEEK_CUR’?
Sets the position to the current position plus offset bytes.
What does lseek do when whence is equal to ‘SEEK_END’?
Sets the position to the size of the file plus offset bytes.
What happens to the file size when you lseek using ‘SEEK_END’ and an offset >= 1?
The file size gets bigger.
What is the function prototype for fread?
size_t fread(void ptr, size_t size, size_t nmemb, FILE stream);
What is the function prototype for fwrite?
size_t fwrite(const void ptr, size_t size, size_t nmemb, FILE stream);
What is the function prototype for fseek?
int fseek(FILE* stream, long offset, int whence);