C exsr error
C eval ReturnInt = close(FileDesc)
C eval ReturnInt = unlink(%ADDR(FileName))
C eval ᑍINLR = '1'
C return
C else
C eval PrintLine = 'Close of link successful'
C except
C endif
Cᑍ
Cᑍ Unlink test_file
Cᑍ
C eval ReturnInt = unlink(%ADDR(FileName))
Cᑍ
Cᑍ Check for error and report status. If an error occurs,
Cᑍ attempt cleanup.
Cᑍ
C if ReturnInt = -1
C eval PrintLine = 'Unlink of file failed'
C exsr error
C eval ReturnInt = unlink(%ADDR(FileName))
C eval ᑍINLR = '1'
C return
C else
C eval PrintLine = 'Unlink of file successful'
C except
C endif
Cᑍ
Cᑍ End of main program
Cᑍ
C eval PrintLine = 'Program run is successful'
C except
C eval ᑍINLR = '1'
C return
Cᑍ
Cᑍ Common error reporting subroutine
Cᑍ
Cᑍ If errors occur, the integrated file system exports the variable
Cᑍ 'errno' to assist in determining the problem. As 'errno' is
Cᑍ lowercase, ILE RPG cannot directly import this variable and must
Cᑍ use a C module to access it. If the developer has ILE C
Cᑍ available, the following sample C code will import 'errno' and
Cᑍ make it available to the RPG application.
Cᑍ
Cᑍ #include <errno.h>
Cᑍ int geterrno()
Cᑍ {
Cᑍ return errno;
Cᑍ }
Cᑍ
Cᑍ To activate this C module, remove the four comment identifiers
Cᑍ following the 'except' statement and remove the comment identifier
Cᑍ from the errno prototype. Definitions for the returned errno
Cᑍ are found in the file QSYSINC/SYS member ERRNO.
Cᑍ
C error begsr
C except
Cᑍ eval ReturnInt = errno
Appendix B. Original Examples in Additional Languages B-187