Task: Standard C Library
Enter the labs/lab-02/tasks/libc/ folder, then enter support/. Now go through the practice items below.
-
Use
malloc()andfree()functions in thememory.cprogram. Make your own use of the allocated memory.It’s very easy to use memory management functions with the libc. The alternative (without the libc) would be more cumbersome.
Use different values for
malloc(), i.e. the allocation size. Usestraceto check the system calls invoked bymalloc()andfree(). You’ll see that, depending on the size, thebrk()ormmap()/munmap()system calls are invoked. And for certain calls tomalloc()/free()no syscall is happening. You’ll find more about them in the Data chapter. -
Create your own C program with calls to the standard C library in
vendetta.c. Be as creative as you can about the types of functions being made. -
Inside the
vendetta.cfile make a callopen("a.txt", O_RDWR | O_CREAT, 0644)to open / create thea.txtfile. Make sure you include all required headers. Check the system call being made.Make an
fopen()with the proper arguments that gets as close as possible to theopen()call, i.e. the system call arguments are as close as possible. -
Inside the
vendetta.cfile make a call tosin()function (for sine). Computesin(0)andsin(PI/2).
If you’re having difficulties solving this exercise, go through this reading material.