Task: Common Functions
Enter the chapters/software-stack/libc/drills/tasks/common-functions/ folder, then enter support/. Go through the practice items below.
-
Update
os_string.candos_string.hto make available theos_strcat()function that performs the same string concatenation asstrcat()fromlibc. Check your implementation by runningmake checkinsupport/tests/. If some of the tests fail, start debugging from the file that callsos_strcat():test.c. -
Update the
main_printf.cfile to use the implementation ofsprintf()to collect information to be printed inside a buffer. Call thewrite()function to print the information. Theprintf()function will no longer be called. This results in a singlewrite()system call.Using previously implemented functions allows us to more efficiently write new programs. These functions provide us with extensive features that we use in our programs.
-
Update the
putchar()function inmain_printf.cto implement a buffered functionality ofprintf(). Characters passed via theputchar()call will be stored in a predefined static global buffer. Thewrite()call will be invoked when a newline is encountered or when the buffer is full. This results in a reduced number ofwritesystem calls. Usestraceto confirm the reduction of the number ofwritesystem calls. -
Update the
main_printf.cfile to also feature aflush()function that forces the flushing of the static global buffer and awritesystem call. Make calls toprintf()andflush()to validate the implementation. Usestraceto inspect thewrite()system calls invoked byprintf()andflush().
If you’re having difficulties solving this exercise, go through this reading material.