The complete source code and Makefile for these programs is available as a zip file.
The following program uses the stat system call to retrieve a file's size.
The following program uses the truncate system call to set a file to a specific size. If the new size is larger than the old size, the extra tail bytes are read as zero; if the new size is smaller than the old, the tail bytes are truncated.