Last Updated on May 5, 2022 by Admin 2

Low-Level I/O M3 Test

  1. 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
  2. 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
  3. 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
  4. 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");
    • fd > 0
    • fd < 0
    • fd == NULL
    • fd == 0
  5. 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
  6. 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);
  7. To create a link in an MS Windows environment, you may use the function named:

    • CreateSymbolicLink()
    • symlink()
    • createsymlink()
    • makesymlink()
  8. 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");
  9. 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
  10. 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
  11. 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
  12. 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
  13. The so-called EPOCH time is the number of seconds elapsed from 00:00:00UTC, 1 January:

    • 1990
    • 1970
    • 1960
    • 1980
  14. 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
  15. 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
  16. 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);
  17. The close() function:

    • is of the void type
    • may not succeed
    • does not return any useful value 
    • always succeeds
  18. 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));
         return 0;
    • three
    • zero
    • five
    • four
  19. 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
  20. 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