File Size


The complete source code and Makefile for these programs is available as a zip file.

Getting a File's Size

The following program uses the stat system call to retrieve a file's size.

get_file_size.c



      

Setting 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.

set_file_size.c