Lecture 01 Flashcards

1
Q

What is POSIX?

A

A standard that attempts to define a common API across operating systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following OSes is not POSIX compliant?
Linux
Windows
MacOS

A

Windows.

Of course it’s fucking Windows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What unix command is used to access the manual page for a given tool or library?

A

man

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the function prototype for the function ‘open’?

A

int open(const char* pathname, int flags);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What different values can be passed as flags to the open() function?

A
O_RDONLY
O_WRONLY
O_RDWR
O_TRUNC
O_CREAT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the function prototype for read()?

A

ssize_t(int fd, void *buf, size_t count);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why does read() return a ssize_t and not a size_t?

What’s the difference?

A

A ssize_t is a signed size_t.

read uses this so it can return -1 in the event of an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What function can be used to create a new file?

A

creat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the function prototype for creat?

A

int creat(const char* pathname, mode_t mode);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What stream number is stdin?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What stream number is stdout?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What stream number is stderr?

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the function prototype for lseek?

A

off_t lseek(int fildes, off_t offset, int whence);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does lseek do when whence is equal to ‘SEEK_SET’?

A

Sets the position to offset bytes from the start of the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does lseek do when whence is equal to ‘SEEK_CUR’?

A

Sets the position to the current position plus offset bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does lseek do when whence is equal to ‘SEEK_END’?

A

Sets the position to the size of the file plus offset bytes.

17
Q

What happens to the file size when you lseek using ‘SEEK_END’ and an offset >= 1?

A

The file size gets bigger.

18
Q

What is the function prototype for fread?

A

size_t fread(void ptr, size_t size, size_t nmemb, FILE stream);

19
Q

What is the function prototype for fwrite?

A

size_t fwrite(const void ptr, size_t size, size_t nmemb, FILE stream);

20
Q

What is the function prototype for fseek?

A

int fseek(FILE* stream, long offset, int whence);