cmpsc 311 test 2 IO Flashcards

(78 cards)

1
Q

fopen() syntax

A

FILE *fopen(const char *path, const char *mode);

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

IO, pointer

A

the fopen function opens a file for — and returns a —- to a FILE* structure

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

stream

A

A FILE* structure is also referred to as a —-

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

r

A

–: open text file for reading. The stream is positioned at the beginning of the file

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

r+

A

— Open for reading and writing. The stream is positioned at the beginning of the file

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

w

A

–: truncate file to zero length or create text file for writing. the stream is positioned at the beginning of the file

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

w+

A

—: Open for reading and writing. The file is created if it does not exist, otherwise it is truncated

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

a

A

Open for appending (writing at the end of file). The file is created if it does not exist

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

a+

A

Open for reading and appending (writing at end of file). the file is created if it does not exist

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

fscanf, fgets

A

there are two dominant ways to read the file: ——- and ——

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

fscanf, scanf

A

— reads the data from the file just like —–, just reading and writing

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

fgets

A

— reads a line of text from the file

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

fprintf, fputs

A

there are two dominant ways to write the file, —- and —-

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

fprintf, printf

A

— writes data to the file just like —-, just reading and writing

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

fputs

A

—- writes a line of text to the file

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

FILE*

A

—- based IO is buffered

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

fflush

A

—- attempts to reset/the flush state

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

int fflush(FILE *stream)

A

fflush syntax

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

buffered, written, pushed, OS/disk

A

FILE* based writes are —–, so there may be data ——-, but not yet —– to the —/—–

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

fflush()

A

—– forces a write of all buffered data

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

buffered, current, current

A

FILE* based reads are —-, so the — data (in the process space) may not be —-

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

fflush()

A

—– discards buffered data from the underlying file

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

NULL, fflush, all

A

If the stream argument is —–, ——() flushes —- open output streams

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

fclose()

A

—– closes the file and releases the memory associated with the FILE* structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
storage
fclose() implicitly flushes the data to ------
26
file, integer file handle
the open function opens a ---- for IO and returns an ------ ------ -----
27
int open(const char *path, int flags, mode_tmode);
open() syntax
28
path
open(): --- is a string containing the absolute or relative path to the file to be opened
29
flags
open(): --- indicates the kind of open you are requesting
30
mode
open(): ---- sets a security policy for the file
31
file handle
open() returns a ---- ----
32
O_RDONLY
open() flags: ---- read only
33
O_WRONLY
open() flags: ---- write only
34
O_RDWR
open() flags: ---- read and write
35
O_CREAT
open() options: ---- if the file does not exist it will be created
36
O_EXCL
open() options: --- ensure that this call creates the file, fail otherwise (fail if already exists)
37
O_TRUNC
open() options: --- if the file already exists it will be truncated to length 0
38
bitwise or (|)
You ------ ---- the mode/options you want in open()
39
discretionary access control, user
The UNIX filesystem implements ----- ----- ---- through file permissions set by user. The permissions are set at the discretion of the ---
40
bits, access
Every file in the file system ha has a set of ----- which determine who has ----- to the files.
41
user
------ the owner is typically the creator of the file, and the entity in control of the access control policy
42
group
---- a set of users on the system setup by the admin
43
world
----- the set of everyone on the system
44
root
Not discretionary access control can be overridden by the ---- user
45
READ
3 rights in UNIX filesystem: ----: allows the subject(process) to read the contents of the file
46
WRITE
3 rights in UNIX filesystem: ----: allows the subject (process) to alter the contents of the file
47
EXECUTE
3 rights in UNIX filesystem: ---: allows the subject (process) to execute the contents of the file (eg, shell program, executable, ...)
48
r, w, x, -
UNIX Access policy: Really, this is a bit string encoding an access policy. And a policy is encoded as ---, ----, --- if enabled and --- if not
49
rwxrw---x
encoding syntax example. says user can read, write and execute, group can read and write, and world can execute only
50
S_IRWXU 00700
Specify a file access policy by bit-wise ORing(|): | --------: user (file owner) has read, write and execute
51
S_IRUSR 00400
Specify a file access policy by bit-wise ORing(|): | --------: user has read permission
52
S_IWUSR 00200
Specify a file access policy by bit-wise ORing(|): | --------: user has write permission
53
S_IXUSR 0100
Specify a file access policy by bit-wise ORing(|): | --------: user has execute permission
54
S_IRGRP 00040
Specify a file access policy by bit-wise ORing(|): | --------: group has read permission
55
S_IWGRP 00020
Specify a file access policy by bit-wise ORing(|): | --------: group has write permission
56
S_IXGRP 00010
Specify a file access policy by bit-wise ORing(|): | --------: group has execute permission
57
S_IRWXO 00007
Specify a file access policy by bit-wise ORing(|): | --------: world has read, write, and execute permission
58
S_IROTH 00004
Specify a file access policy by bit-wise ORing(|): | --------: world has read permission
59
S_IWOTH 00002
Specify a file access policy by bit-wise ORing(|): | --------: world has write permission
60
S_IXOTH 00001
Specify a file access policy by bit-wise ORing(|): | --------: world has execute permission
61
S_IRWXG 00070
Specify a file access policy by bit-wise ORing(|): | --------: group has read, write, and execute permission
62
int
Why is an ---- returned by open() file
63
file descriptor
a ----- ----- is an index assigned by the kernel into a table of file information maintained in the OS.
64
unique, process, open
The file descriptor table is ----- to each ----- and contains the details of ---- files
65
calling IO system
File descriptors are used to reference when ----- the ----- ------ calls
66
kernel, process, system call
The ---- accesses the file for the ----- and returns the results in ----- --- response
67
primitive
------ reading and writing mechanisms that only process only blocks of opaque data
68
ssize_twrite(int fd, const void *buf, size_tcount);
primitive write syntax
69
ssize_tread(int fd, void *buf, size_tcount);
primitive read syntax
70
fd, buf, count
primitive read/write syntax: Where --- is the file descriptor, ---- is an array of bytes to write from or read into, and ---- is the number of bytes to read or write
71
number, bytes, result
both read() and write(0 returned the ---- of ------ read and written. Be sure to always check the ----
72
buffer, output
On reads, you are responsible for supplying a ----- that is large enough to put the ----- into
73
close(), -1
----- closes the file and deletes the file's entry in the file descriptor table. Always reset your file handles to ---- to avoid use after close
74
fopen
---- provides you with buffering IO that may or may not turn out to be a faster than what you're doing with open
75
fopen, binary mode
----- does line ending translation if the file is not opened in ----- ---, which can be very helpful if your program is ever ported to a non-UNIX environment`
76
FILE*, fscanf, stdio
A ---- gives you the ability to use ---- and other --- functions that parse out data and support formatted output
77
FILE*, file handle
IMO: use ----- style I/O for ASCII processing, and ---- ------ I/O for binary data processing
78
include, stdio.h, sys/types.h, sys/stat.h, fcnt1.h, unistd.h
each of the styles of I/O requires a different set of ----- files. FILE* requires: -------- file handle I/O requires: - ------ - ------ - ------ - ------