|
| 1 | +/* |
| 2 | + * Copyright (c) 2016,2018 IBM Corporation and other Contributors. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * http://www.eclipse.org/legal/epl-v10.html |
| 8 | + * |
| 9 | + * Contributors: |
| 10 | + * Douglas Burns |
| 11 | + */ |
| 12 | + |
| 13 | +/***************************************************************************/ |
| 14 | +/* This program is to be run on z/OS if the file transfer mechanism to get */ |
| 15 | +/* the SMF data to the workstation platform does not support VBS datasets. */ |
| 16 | +/* */ |
| 17 | +/* For example sftp works from USS files and the SMF dataset needs to be */ |
| 18 | +/* converted before sftp can process the z/OS file. */ |
| 19 | +/***************************************************************************/ |
| 20 | +#include <stdio.h> |
| 21 | +#include <unistd.h> |
| 22 | + |
| 23 | +#define BUFFERLENGTH 10485760 /* Max length of record accepted */ |
| 24 | + |
| 25 | +/**********************************************************************/ |
| 26 | +/* Function name: main */ |
| 27 | +/* */ |
| 28 | +/* Description: Reads the specified dataset and writes the */ |
| 29 | +/* contents */ |
| 30 | +/* */ |
| 31 | +/* Receives: Two parameters - SMF VBS dataset to read */ |
| 32 | +/* USS file to write */ |
| 33 | +/* */ |
| 34 | +/* */ |
| 35 | +/**********************************************************************/ |
| 36 | +int main(int argc, char *argv[] ) |
| 37 | +{ |
| 38 | + char inputDatasetName[4096]; |
| 39 | + char escapedInputDatasetName[4096]; |
| 40 | + char outputFileName[4096]; |
| 41 | + |
| 42 | + FILE *inputFile; |
| 43 | + FILE *outputFile; |
| 44 | + |
| 45 | + char databuffer[BUFFERLENGTH]; |
| 46 | + |
| 47 | + int dataLength = 0; |
| 48 | + int recordCount = 0; |
| 49 | + |
| 50 | + /* */ |
| 51 | + /* Handle the arguments passed */ |
| 52 | + /* */ |
| 53 | + if (argc < 3) { /* need prog name + two parm */ |
| 54 | + printf("\n%s called with incorrect arguments\n",argv[0] ); |
| 55 | + printf(" expected parms are DATASETNAME FILENAME\n "); |
| 56 | + printf(" where\n"); |
| 57 | + printf(" DATASETNAME = name of input dataset\n"); |
| 58 | + printf(" FILENAME = name of output file\n"); |
| 59 | + return(4); |
| 60 | + } |
| 61 | + strcpy(inputDatasetName, argv[1]); |
| 62 | + strcpy(outputFileName, argv[2]); |
| 63 | + |
| 64 | + strcpy(escapedInputDatasetName, "//'"); |
| 65 | + strcat(escapedInputDatasetName, inputDatasetName); |
| 66 | + strcat(escapedInputDatasetName, "'"); |
| 67 | + |
| 68 | + /* Open input file */ |
| 69 | + if ((inputFile = fopen(escapedInputDatasetName, "rb, type=record, recfm=*")) == NULL) { |
| 70 | + printf("Could not open dataset: %S\n", inputDatasetName); |
| 71 | + return(4); |
| 72 | + } |
| 73 | + |
| 74 | + /* Open output file */ |
| 75 | + if ((outputFile = fopen(outputFileName, "wb")) == NULL) { |
| 76 | + printf("Could not open file: %S\n", outputFileName); |
| 77 | + return(4); |
| 78 | + } |
| 79 | + |
| 80 | + /* Read in the data */ |
| 81 | + while (dataLength = fread(&databuffer, 1, BUFFERLENGTH, inputFile)) { |
| 82 | + recordCount++; |
| 83 | + |
| 84 | + /* Write the data */ |
| 85 | + fwrite(&databuffer, 1, dataLength, outputFile); |
| 86 | + } |
| 87 | + |
| 88 | + /* Close files */ |
| 89 | + fclose(inputFile); |
| 90 | + fclose(outputFile); |
| 91 | + |
| 92 | + printf("\n *** %d records written. ***\n", recordCount); |
| 93 | + |
| 94 | + printf("\n"); |
| 95 | +} |
0 commit comments