Fix fstat return value check
Increase image file name buffer size to 256 bytes.

Use 4 digits for seconds counter in image file name.