Added include sys/stat.h for BSD systems.