2026-02-08 14:19:53 +00:00
|
|
|
#include <stdio.h>
|
2026-02-08 14:59:34 +00:00
|
|
|
#include <errno.h>
|
2026-02-08 14:19:53 +00:00
|
|
|
|
|
|
|
|
#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()
|
|
|
|
|
{
|
2026-02-08 15:16:29 +00:00
|
|
|
FILE *fp_read;
|
|
|
|
|
FILE *fp_append;
|
2026-02-08 14:19:53 +00:00
|
|
|
char buffer[BUFFER_SIZE];
|
|
|
|
|
|
2026-02-08 15:16:29 +00:00
|
|
|
/* First: open for reading only to dump current content */
|
|
|
|
|
fp_read = fopen("dd:TESTDD", "r");
|
|
|
|
|
if (fp_read == NULL)
|
2026-02-08 14:19:53 +00:00
|
|
|
{
|
2026-02-08 15:16:29 +00:00
|
|
|
perror("fopen read failed");
|
2026-02-08 14:59:34 +00:00
|
|
|
printf("errno = %d\n", __errno());
|
2026-02-08 14:19:53 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Existing content:\n");
|
2026-02-08 15:16:29 +00:00
|
|
|
while (fgets(buffer, BUFFER_SIZE, fp_read) != NULL)
|
2026-02-08 14:19:53 +00:00
|
|
|
{
|
|
|
|
|
printf("%s", buffer);
|
|
|
|
|
}
|
2026-02-08 15:16:29 +00:00
|
|
|
fclose(fp_read);
|
2026-02-08 14:19:53 +00:00
|
|
|
|
2026-02-08 15:16:29 +00:00
|
|
|
/* Second: open for append only to add the new line */
|
|
|
|
|
fp_append = fopen("dd:TESTDD", "a");
|
|
|
|
|
if (fp_append == NULL)
|
|
|
|
|
{
|
|
|
|
|
perror("fopen append failed");
|
|
|
|
|
printf("errno = %d\n", __errno());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2026-02-08 14:19:53 +00:00
|
|
|
|
2026-02-08 15:16:29 +00:00
|
|
|
fprintf(fp_append, "Appended from C program!\n");
|
|
|
|
|
fclose(fp_append);
|
2026-02-08 14:19:53 +00:00
|
|
|
|
|
|
|
|
printf("Append complete.\n");
|
|
|
|
|
|
|
|
|
|
return 0;
|
2026-02-08 14:26:36 +00:00
|
|
|
}
|