2026-02-08 14:19:53 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 256
|
|
|
|
|
|
|
|
|
|
/* Simple program to read and append to a single PDS member via DD name. */
|
|
|
|
|
/* Author: Greg Gauthier */
|
|
|
|
|
/* Date: 2026-02-08 */
|
|
|
|
|
/* NOTE: No single-line comments due to MVS SYSIN/JCL interpretation. */
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char buffer[BUFFER_SIZE];
|
|
|
|
|
|
|
|
|
|
/* Open the file in update mode (read and write). */
|
|
|
|
|
/* The filename is "dd:DDNAME" where DDNAME is defined in JCL. */
|
|
|
|
|
fp = fopen("dd:TESTDD", "r+");
|
|
|
|
|
if (fp == NULL)
|
|
|
|
|
{
|
2026-02-08 14:33:01 +00:00
|
|
|
perror("fopen failed. Insure the member exists.");
|
2026-02-08 14:19:53 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read and print existing lines (to SYSOUT). */
|
|
|
|
|
printf("Existing content:\n");
|
|
|
|
|
while (fgets(buffer, BUFFER_SIZE, fp) != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("%s", buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* After reading to EOF, the file position is at the end, so we can append. */
|
|
|
|
|
fprintf(fp, "Appended from C program!\n");
|
|
|
|
|
|
|
|
|
|
/* Close the file. */
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
printf("Append complete.\n");
|
|
|
|
|
|
|
|
|
|
return 0;
|
2026-02-08 14:26:36 +00:00
|
|
|
}
|
2026-02-08 14:28:05 +00:00
|
|
|
|
|
|
|
|
|