C + %TRIMR(test_file)
C + ' closed successfully'
C except
C endif
Cᑍ
Cᑍ Open the file for read only
Cᑍ
C eval FileDesc = open2(%ADDR(FileName)
C : x'1')
Cᑍ
Cᑍ Check for error and report status. If an error occurs,
Cᑍ attempt cleanup.
Cᑍ
C if FileDesc = -1
C eval PrintLine = 'Open of file failed'
C exsr error
C eval ReturnInt = unlink(%ADDR(FileName))
C eval ᑍINLR = '1'
C return
C else
C eval PrintLine = 'Open of file successful'
C except
C endif
Cᑍ
Cᑍ Read from file
Cᑍ
C eval BytesRead = read(FileDesc
C : %ADDR(Buffer) : %SIZE(Buffer))
Cᑍ
Cᑍ Check for error and report status. If an error occurs,
Cᑍ attempt cleanup.
Cᑍ
C if BytesRead = -1
C eval PrintLine = 'Read failed'
C exsr error
C eval ReturnInt = close(FileDesc)
C eval ReturnInt = unlink(%ADDR(FileName))
C eval ᑍINLR = '1'
C return
C else
C if BytesRead = BytesWrt
C eval PrintLine = 'Data successfully read: '
C + %TRIMR(Buffer)
C else
C eval PrintLine = 'Data truncation on read'
C endif
C except
C endif
Cᑍ
Cᑍ Close the LinkName file
Cᑍ
C eval ReturnInt = close(FileDesc)
Cᑍ
Cᑍ Check for error and report status. If an error occurs,
Cᑍ attempt cleanup.
Cᑍ
C if ReturnInt = -1
C eval PrintLine = 'Close of link failed'
B-186 System API Programming V4R1