-
The low-level open()
function, when succeeded, returns:
- an
int
as an error code
- an
int
as a file descriptor
- a pointer to an error code
- a pointer to a file descriptor
-
The readlink()
function:
- gets the name of a file pointed to by the link
- gets all names of the link
- reads a file pointer to by the link
- gets all names of the file pointed to by the link
-
A descriptor with a value equal to 0
:
- is connected to
stderr
- is connected to
stdin
- is not connected and may be freely used
- is connected to
stdout
-
What should be placed instead of <?>
to make the following snippet work properly?
int fd = open("input", o_WRONLY);
if(<?> ) {
puts("File could not be open");
exit(1);
}
fd > 0
fd < 0
fd == NULL
fd == 0
-
An “endline translation” occurs:
- when the file is being created
- when the file is opened with an
O_TEXT
flag
- when the file is opened with
O_TEXT
and O_BINARY
flags ORed (|
)together
- when the file is opened with an
O_BINARY
flag
-
An EBADF (Bad file descriptor) error may occur during the invocation:
open(fname, O_RDWR)
unlink("file.txt");
readlink("file.txt", namebuff, sizeof(namebuff));
read(fd, buff, 100);
-
To create a link in an MS Windows environment, you may use the function named:
CreateSymbolicLink()
symlink()
createsymlink()
makesymlink()
-
Which snippet will you use to delete the file name file ?
int fd = open("file",O_RDWR); unlink(fd); close(fd);
open("file", O_DELETE);
FILE *f = fopen("file","rw"); unlink(f); fclose(f);
unlink("file");
-
The O_CREATE
flag, used by the open()
function, has the following effect:
- if the file does not exit, it will be created
- if the file exists, it will be truncated to zero
- if the file exists, it will be erased and created again
- if the file does not exists, the
open()
function will fail
-
The fcntl()
function
- is able to change all of the access modes specified during the
open()
function invocation
- must not be used when it comes to a regular file’s access modes
- is not able to change the access mode specified during the
open()
function invocation
- is able to change some of the access modes specified during the
open()
function invocation
-
The st_ino
filed of the struct stat
:
- is always
-1
in MS Windows
- is emulated in MS Windows
- has no meaning in MS Windows
- if fully supported in MS Windows
-
The lseek(fd, 0, seek_CUB)
invocation sets the file pointer to:
- the file’s beginning
- the same place as before invocation
- a random position
- the file’s end
-
The so-called EPOCH time is the number of seconds elapsed from 00:00:00UTC, 1 January:
-
The dprintf()
funciton is designed to:
- print the formatted strings to two streams at the same time
- print
doubles
instead of floats
- use a file descriptor instead of the
FILE *
pointer
- deleted stream content
-
The st_mode
field of struct stat
in an MS Windows environment determines the state of an “executable” attribute:
- using the owner’s name
- using the owner’s permission
- using the file’s permission
- using the file’s name
-
To write all the elements of the array declared below, you may use the invocation:
double vec[3] = {-1., 1., 0};
write(fh, vec, sizeof(vec));
write(fh, vec, 3);
write(fh, sizeof(vec), vec);
write(fh, 3, vec);
-
The close()
function:
- is of the
void
type
- may not succeed
- does not return any useful value
- always succeeds
-
How many bytes will the following program write to a file, assuming that the code is compiled by a CL compiler and successfully run on MS Windows?
#include <io.h>
#include <fcntl.h>
int main(void) {
char buff[] = "ABC\n";
int fd = open("file", O_WRONLY | O_CREATE | O_TEXT);
write(fd, buff, strlen(buff));
close(fd);
return 0;
}
-
The fileno()
function:
- create a new file descriptor
- extracts a file descriptor from the given
FILE
structure
- counts all currently open file descriptor
- puts a file descriptor into the given
FILE
structure
-
The stat()
function:
- is partially supported in non-Unix operating systems
- is not accessible in non-Unix operating systems
- is full supported in all operating systems
- is named
Stat(0
in non-Unix operating systems