- /* Process 0 creates the test file(s) */
- if (rank == 0) {
- sprintf(filename, "%s/%s", testdir, name);
- remove_file_or_dir(filename);
- if ((fd = creat(filename, FILEMODE)) == -1) {
- sprintf(errmsg, "create of file %s", filename);
- FAIL(errmsg);
- }
- if (filesize > 0) {
- if (lseek(fd, filesize - 1, SEEK_SET) == -1) {
- close(fd);
- sprintf(errmsg, "lseek of file %s", filename);
- FAIL(errmsg);
- }
- if (write(fd, &zero, 1) == -1) {
- close(fd);
- sprintf(errmsg, "write of file %s", filename);
- FAIL(errmsg);
- }
- }
- if (filesize > 0 && fill) {
- if (lseek(fd, 0, SEEK_SET) == -1) {
- close(fd);
- sprintf(errmsg, "lseek of file %s", filename);
- FAIL(errmsg);
- }
- memset(buf, c, 1024);
- while (left > 0) {
- if ((rc = write(fd, buf,
- left > (1024 * 8) ? (1024 * 8) : left))
- == -1) {
- close(fd);
- sprintf(errmsg, "write of file %s", filename);
- FAIL(errmsg);
- }
- left -= rc;
- }
- }
- if (close(fd) == -1) {
- sprintf(errmsg, "close of file %s", filename);
- FAIL(errmsg);
- }
- }
+ /* Process 0 creates the test file(s) */
+ if (rank == 0) {
+ sprintf(filename, "%s/%s", testdir, name);
+ remove_file_or_dir(filename);
+ fd = creat(filename, FILEMODE);
+ if (fd < 0)
+ FAILF("create of file %s", filename);
+
+ if (filesize > 0) {
+ if (lseek(fd, filesize - 1, SEEK_SET) == -1) {
+ close(fd);
+ FAILF("lseek of file %s", filename);
+ }
+ if (write(fd, &zero, 1) == -1) {
+ close(fd);
+ FAILF("write of file %s", filename);
+ }
+ }
+ if (filesize > 0 && fill) {
+ if (lseek(fd, 0, SEEK_SET) == -1) {
+ close(fd);
+ FAILF("lseek of file %s", filename);
+ }
+ memset(buf, c, 1024);
+ while (left > 0) {
+ rc = write(fd, buf, MAX(left, 8192));
+ if (rc < 0) {
+ close(fd);
+ FAILF("write of file %s", filename);
+ }
+ left -= rc;
+ }
+ }
+ if (close(fd) == -1)
+ FAILF("close of file %s", filename);
+ }