Guardian Programmer's Guide

Table Of Contents
Using the File System
Guardian Programmer’s Guide 421922-014
2 - 17
Opening Files
naming is a system-management function, therefore you need to know some system-
configuration information before attempting to open a device file.
The following example opens a printer called $LP1:
FILE^NAME ':=' "$LP1" -> @S^PTR;
LENGTH := @S^PTR '-' @FILE^NAME;
ERROR := FILE_OPEN_(FILE^NAME:LENGTH,
FILENUM);
The next example opens the home terminal of the process:
ERROR := PROCESS_GETINFO_(
!process^handle!,
!file^name:maxlen!,
!file^name^len!,
!priority!,
!moms^processhandle!,
TERMINAL^NAME:ZSYS^VAL^LEN^FILENAME,
LENGTH);
ERROR := FILE_OPEN_(TERMINAL^NAME:LENGTH,
FILENUM);
Here, the PROCESS_GETINFO_ call returns the name of the home terminal in the
variable TERMINAL^NAME, along with the file-name length in LENGTH. Both of these
values are supplied to the FILE_OPEN_ call. You now use the returned file number to
perform I/O operations on the terminal.
Opening Processes
To open a process, you simply pass the process file name and its length to the
FILE_OPEN_ procedure. If the process you are opening was created by the current
process (using, for example, a call to PROCESS_CREATE_ as described earlier in this
section), then you use the process descriptor returned by the process creation
procedure. If the process was created outside the current process, then you can pass
the process name in the FILE_OPEN_ call.
Consider a requester process $REQ that needs the services of a server process
$S
ER1 that was created and named using the RUN command. The requester may
open the server process as follows:
FILE^NAME ':=' "$SER1" -> @S^PTR;
LENGTH := @S^PTR '-' @FILE^NAME;
ERROR := FILE_OPEN_(FILE^NAME:LENGTH,
FILENUM);
To receive messages sent to it, the $SER1 process must open its $RECEIVE file:
FILE^NAME ':=' "$RECEIVE" -> @S^PTR;
LENGTH := @S^PTR '-' @FILE^NAME;
RECEIVE^DEPTH := 1;
ERROR := FILE_OPEN_(FILE^NAME:LENGTH,
FILENUM,
!access!,
!exclusion!,