Rational Developer for System z

C program for error feedback

The following sample C program, ZFLDATA, dynamically queries the DSName for a passed-in DDName. The PL/I sample program in Related References illustrates the call to this C program to query the DSName for the SYSXMLSD DDName for error feedback.
As part of the processing, TMPLT00 calls a C routine called ZFLDATA. This routine has a single purpose. It takes a data set DD name, and if possible, it will return the data set name that the DD name refers to. The source for ZFLDATA is listed below.
#include <stdio.h>
#include <string.h>
#define FILENAMEMAX 255
#define ATTRMAX 100

int main(void)
{
   FILE *stream;
   char dsn[FILENAMEMAX];
   char filename[FILENAMEMAX];
   char fileattrs[ATTRMAX];
   int rc;
   int getFileData(char * dsn, char * filename, char * fileattrs);


   memset(filename ,'\0',sizeof(filename));
   memset(filename ,'\0',sizeof(fileattrs));
   memcpy(filename ,"DD:SYSXMLSD",sizeof("DD:SYSXMLSD"));
   memcpy(fileattrs ,"a+",
		   sizeof("a+"));


   rc = ZFLDATA(dsn,filename,fileattrs);



   if (rc != 0)
      printf("fldata failed\n");
   else
      printf("filename is %s\n",dsn);
}

int ZFLDATA(char * dsn, char *fn, char *fileattrs)
  {
	 fldata_t fileinfo;
	 fldata_t * fileinfoptr;
	 int rc;
	 FILE *stream;

	 /******************************************************/
	 /*Get a stream for the file and attributes passed in  */
	 /******************************************************/
	 stream = fopen(fn,fileattrs);
     if (stream == NULL)
     {
        perror("***FAILURE OPENING FILE*****");
     }

     /******************************************************/
     /*Get the actual data set name on DASD from fldata    */
     /******************************************************/
	 memset(dsn ,'\0',
  		   sizeof(dsn));
	 fileinfoptr = &fileinfo;
     rc = fldata(stream, dsn, &fileinfo;);
	 if (rc != 0)
	   {
	         printf("fldata failed\n");
	   }
	 else
	 {
	     memcpy (dsn,
	  		   fileinfoptr->__dsname,
	  		   strlen(fileinfoptr->__dsname));
	 }
     fclose(stream);
	 return rc;
	}

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)