diff options
Diffstat (limited to 'testcases/network/nfs/nfslock01/nfs_flock_dgen.c')
-rw-r--r-- | testcases/network/nfs/nfslock01/nfs_flock_dgen.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/testcases/network/nfs/nfslock01/nfs_flock_dgen.c b/testcases/network/nfs/nfslock01/nfs_flock_dgen.c index 2b33ca974..6ecdcdc4f 100644 --- a/testcases/network/nfs/nfslock01/nfs_flock_dgen.c +++ b/testcases/network/nfs/nfslock01/nfs_flock_dgen.c @@ -1,5 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * This program generates data for testing file locking + * Copyright (c) Linux Test Project, 2001-2023 + * Copyright (c) International Business Machines Corp., 2001 + */ + +/*\ + * [Description] + * + * Tool to generate data for testing file locking. + * Used in nfslock01.sh. */ #include <stdio.h> @@ -13,32 +22,39 @@ int main(int argc, char **argv) FILE *fp; if (argc != 5) { - printf - ("usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\n"); + fprintf(stderr, "usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\n"); exit(2); } fp = fopen(argv[1], "w"); nchars = atoi(argv[2]); + nlines = atoi(argv[3]); + ctype = atoi(argv[4]); + if (nchars > BUFSIZ) { - printf("Exceeded the maximum limit of the buffer (%d)\n", - BUFSIZ); + fprintf(stderr, "Exceeded the maximum limit of the buffer (%d)\n", BUFSIZ); + exit(3); + } + + if (nchars < 1) { + fprintf(stderr, "<char/line> must be > 0\n"); + exit(3); + } + + if (nlines < 1) { + fprintf(stderr, "<lines> must be > 0\n"); exit(3); } - nlines = atoi(argv[3]); - ctype = atoi(argv[4]); k = 0; for (i = 1; i <= nlines; i++) { - if (ctype) c = ((i % 2) ? '1' : '0'); else c = 'A' + k; - for (j = 0; j < nchars; j++) - + for (j = 0; j < nchars - 1; j++) buf[j] = c; fprintf(fp, "%s\n", buf); @@ -53,5 +69,6 @@ int main(int argc, char **argv) } fclose(fp); - return (0); + + return 0; } |