Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Programming Guide

Using C functions

Matching simple parameter types
Matching string parameter types
Functions returning ENTRYs

Let's say we wanted to write a program to read a file and dump it as formatted hex - using the C functions fopen and fread.

The code for this program is straightforward:

Figure 60. Sample code to use fopen and fread to dump a file
   filedump:
     proc(fn) options(noexecops main);

     dcl fn             char(*) var;

     %include filedump;

     file = fopen( fn, 'rb' );

     if file = sysnull() then
       do;
         display( 'file could not be opened' );
         return;
       end;

     do forever;
       unspec(buffer) = ''b;

       read_In = fread( addr(buffer), 1, stg(buffer), file );

       if read_In = 0 then
         leave;

       display(    heximage(addr(buffer),16,' ')  ||  '  '
                || translate(buffer,(32)'.',unprintable)  );

       if read_In < stg(buffer) then
         leave;
     end;

     call fclose( file );
   end filedump;

Most of the declarations in the INCLUDE file filedump are obvious:

Figure 61. Declarations for filedump program
     define struct      1 file;
     define alias       file_Handle  handle file;

     define alias       size_t unsigned fixed bin(32);
     define alias       int signed fixed bin(31);

     dcl file           type(file_Handle);
     dcl read_In        fixed bin(31);
     dcl buffer         char(16);

     dcl unprintable    char(32) value( substr(collate(),1,32) );

Terms of use | Feedback

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