modified fcreat() to support automatic directory creation