summaryrefslogtreecommitdiffstats
path: root/test/atomic_writer.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
commitb2d661b508a7fc7a2592c13bc6bdc175551f075d (patch)
tree13baeb0d83a7c2a4c6299993c182b1227c2f6114 /test/atomic_writer.c
parent29ab58b58dce556639ea3154e262895773a8a8df (diff)
downloadhdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2
Clang-format of source files
Diffstat (limited to 'test/atomic_writer.c')
-rw-r--r--test/atomic_writer.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/test/atomic_writer.c b/test/atomic_writer.c
index b9ea03a..0f86f7b 100644
--- a/test/atomic_writer.c
+++ b/test/atomic_writer.c
@@ -53,7 +53,6 @@
static void usage(void);
-
/*-------------------------------------------------------------------------
* Function: usage
*
@@ -76,8 +75,6 @@ usage(void)
printf("\n");
} /* usage() */
-
-
/*-------------------------------------------------------------------------
* Function: main
*
@@ -114,33 +111,33 @@ usage(void)
int
main(int argc, char *argv[])
{
- int fd = -1; /* file descriptor */
- ssize_t bytes_wrote; /* the nubmer of bytes written */
- unsigned int *buf = NULL; /* buffer to hold written data */
- unsigned int n, u, i; /* local index variable */
- int temp; /* temporary variable */
- unsigned int iterations = 0; /* the input for "-i" */
- unsigned int num = 0; /* the input for "-n" */
- int opt = 0; /* option char */
+ int fd = -1; /* file descriptor */
+ ssize_t bytes_wrote; /* the nubmer of bytes written */
+ unsigned int *buf = NULL; /* buffer to hold written data */
+ unsigned int n, u, i; /* local index variable */
+ int temp; /* temporary variable */
+ unsigned int iterations = 0; /* the input for "-i" */
+ unsigned int num = 0; /* the input for "-n" */
+ int opt = 0; /* option char */
/* Ensure the # of arguments is as expected */
- if(argc != 5) {
+ if (argc != 5) {
usage();
exit(EXIT_FAILURE);
} /* end if */
/* Parse command line options */
- while((opt = getopt(argc, argv, "n:i:")) != -1) {
- switch(opt) {
+ while ((opt = getopt(argc, argv, "n:i:")) != -1) {
+ switch (opt) {
case 'n':
- if((temp = atoi(optarg)) < 0) {
+ if ((temp = atoi(optarg)) < 0) {
usage();
exit(EXIT_FAILURE);
} /* end if */
num = (unsigned int)temp;
break;
case 'i':
- if((temp = atoi(optarg)) < 0) {
+ if ((temp = atoi(optarg)) < 0) {
usage();
exit(EXIT_FAILURE);
} /* end if */
@@ -150,78 +147,79 @@ main(int argc, char *argv[])
printf("Invalid option encountered\n");
break;
} /* end switch */
- } /* end while */
+ } /* end while */
printf("WRITER: # of integers to write = %u; # of iterations = %d\n", num, iterations);
/* Remove existing data file if needed */
- if(remove(FILENAME) < 0) {
- if(errno == ENOENT)
+ if (remove(FILENAME) < 0) {
+ if (errno == ENOENT)
printf("WRITER: remove %s--%s\n", FILENAME, strerror(errno));
else {
printf("WRITER: error from remove: %d--%s\n", errno, strerror(errno));
goto error;
} /* end else */
- } else
+ }
+ else
printf("WRITER: %s is removed\n", FILENAME);
/* Create the data file */
- if((fd = open(FILENAME, O_RDWR|O_TRUNC|O_CREAT, 0664)) < 0) {
+ if ((fd = open(FILENAME, O_RDWR | O_TRUNC | O_CREAT, 0664)) < 0) {
printf("WRITER: error from open\n");
goto error;
} /* end if */
/* Allocate buffer for holding data to be written */
- if((buf = (unsigned int *)malloc(num * sizeof(unsigned int))) == NULL) {
+ if ((buf = (unsigned int *)malloc(num * sizeof(unsigned int))) == NULL) {
printf("WRITER: error from malloc\n");
- if(fd >= 0 && close(fd) < 0)
+ if (fd >= 0 && close(fd) < 0)
printf("WRITER: error from close\n");
goto error;
} /* end if */
printf("\n");
- for(i = 1; i <= iterations; i++) {
+ for (i = 1; i <= iterations; i++) {
printf("WRITER: *****start iteration %u*****\n", i);
/* Write the series of integers to the file */
- for(n = 0; n < num; n++) {
+ for (n = 0; n < num; n++) {
/* Set up data to be written */
- for(u=0; u < num; u++)
+ for (u = 0; u < num; u++)
buf[u] = n;
/* Position the file to the proper location */
- if(lseek(fd, (off_t)(n*sizeof(unsigned int)), SEEK_SET) < 0) {
+ if (lseek(fd, (off_t)(n * sizeof(unsigned int)), SEEK_SET) < 0) {
printf("WRITER: error from lseek\n");
goto error;
} /* end if */
/* Write the data */
- if((bytes_wrote = write(fd, buf, ((num-n) * sizeof(unsigned int)))) < 0) {
+ if ((bytes_wrote = write(fd, buf, ((num - n) * sizeof(unsigned int)))) < 0) {
printf("WRITER: error from write\n");
goto error;
} /* end if */
/* Verify the bytes written is correct */
- if(bytes_wrote != (ssize_t)((num-n) * sizeof(unsigned int))) {
+ if (bytes_wrote != (ssize_t)((num - n) * sizeof(unsigned int))) {
printf("WRITER: error from bytes written\n");
goto error;
} /* end if */
- } /* end for */
+ } /* end for */
printf("WRITER: *****end iteration %u*****\n\n", i);
} /* end for */
/* Close the file */
- if(close(fd) < 0) {
+ if (close(fd) < 0) {
printf("WRITER: error from close\n");
goto error;
} /* end if */
/* Free the buffer */
- if(buf)
+ if (buf)
free(buf);
return EXIT_SUCCESS;
@@ -240,4 +238,3 @@ main(void)
} /* end main() */
#endif /* WIN32 / MINGW32 */
-