1 /* 2 @! # TESTCASE DESCRIPTION: 3 @! # Purpose: to create an input file of any size 4 @! # Command: none 5 @! # Subcommand: none 6 @! # Design: Write an array the size of BUFSIZ to created file until 7 @! # the file size matches the file size required 8 @! # SPEC. EXEC. REQS: This program is used by ctatcdt3.c and ctatcet3.c 9 */ 10 11 #include <sys/types.h> 12 #include <sys/stat.h> 13 #include <fcntl.h> 14 #include <stdio.h> 15 #include <stdlib.h> 16 #include <unistd.h> 17 18 int main(int argc, char *argv[]) 19 { 20 21 int fd; 22 int fsize; 23 int count = 0; 24 int n, remain; 25 static char buf[BUFSIZ]; 26 27 for (fsize = 0; fsize < BUFSIZ; fsize++) { 28 if ((fsize % 2) == 0) 29 buf[fsize++] = 'U'; 30 else 31 buf[fsize++] = '\n'; 32 } 33 34 fsize = strtol(argv[1], NULL, 10); 35 36 if ((fd = creat(argv[2], 0644)) == -1) 37 perror("createfile"); 38 if (fsize >= BUFSIZ) { 39 count = fsize / BUFSIZ; 40 remain = fsize % BUFSIZ; 41 } else 42 remain = fsize; 43 while (count-- != 0) { 44 if ((n = write(fd, buf, BUFSIZ)) != BUFSIZ) 45 perror("createfile"); 46 } 47 if ((n = write(fd, buf, remain)) != remain) 48 perror("createfile"); 49 close(fd); 50 51 return 0; 52 } 53