Linux System Programming Part 3 - Filesystem and Files: IBA Bulgaria 2018
Linux System Programming Part 3 - Filesystem and Files: IBA Bulgaria 2018
If flags has O_CREAT set, the mode is a bit mask of: O_EXCL If O_CREAT and file exists, open( ) will fail.
S_IRWXG S_IWOTH O_SYNC The file will be opened for synchronous I/O.
● Each call reads up to len bytes into buf from the current file offset of
the file referenced by fd.
● On success, the number of bytes written into buf is returned.
● On error, the call returns -1 and errno is set.
readfile.c
● Writes up to count bytes starting at buf to the current file position of the file
referenced by the file descriptor fd.
● On success, the number of bytes written is returned, and the file position is
updated.
● On error, the call returns -1 and errno is set.
writefile.c
Do 100 times
Call getSentence() to get a new
text into the buffer and its length
Write the buffer into the file and get
the number of bytes written
If the number of written bytes is -1,
print error and stop writing.
Write a program (‘fmanipulator.c’), which takes 3 arguments: words_count, min_length, max_length. The
program should generate a file called ‘words.txt’, which contains words_count words (separated with
spaces). To generate the words use the following function from the code files in ‘/day03/rndword/’ (note
that the function will not generate real words, but rather random sequences of characters):
Then the program should print the generated file to the screen.
After the program creates ‘words.txt’ and before writing into it it should lock the first 100 bytes of the
file. When the program prints out the generated words it should wait for Enter key press and then unlock
the file. Respectively, if the file was already locked by another process, the program should notify about
this and wait for Enter key press, before trying again (to lock, generate and write).