sorry for the strange formatting of the example code:

should be

'open' path, O_rdwr+O_creat+O_trunc, 660
if retval=-1 then do
    say 'file not opened, error codes' errno errnojr return
end
fd=retval

Kind regards

Bernd


Am 11.09.2022 um 09:57 schrieb Bernd Oppolzer:
Why is there suddenly the variable RC used to test the outcome of OPEN?
In the examples in the IBM doc I see:

|'open' path, O_rdwr+O_creat+O_trunc, 660 if retval=-1 then do say 'file not opened, error codes' errno errnojr return end fd=retval |that is:

the returned fd and the code to test the success of OPEN
is both in the variable retval, not RC.

And: it would be better to assign the value of retval to
fd after the test for success.

Kind regards

Bernd


Am 11.09.2022 um 01:45 schrieb Charles Mills:
I am working on a Rexx program that reads one or more UNIX files. (And please, don't beat me up for Rexx; we can have the "superiority of Python" discussion another day.)

The logic works for the first file, but if there is a second file the read fails with a -21, which I interpret as "bad fd." (Am I wrong about that?)

Here are the read and open routines. The read routine gets called with the file name. It's getting that right because the first file works (and the second file works if it is first). There is no error printed by FileOpen. I can see from the Print at the start of ReadOneFile that the filename is correct. How could the fd be bad if the open succeeds?

ReadOneLogFile:
   If IsVerbose Then Call Print "ReadOneLogFile:" Arg(1)
       ADDRESS SYSCALL
   Call FileOpen Arg(1)
      Do Forever
     "read" Filefd "record" LogFileRecLen
     If Length(record) <> LogFileRecLen Then Leave
          /* snip */
          End   /* Read records forever */
      "close" Filefd
     Return

FileOpen:
   /* Open the file */
   "open" Arg(1) O_RDONLY
   Filefd = retval
   if RC = -1 Then Do
     Call Print "Error from Log File open. RC =" RC errno errnojr
     Signal EndProgram
     End  /* RC <> 0 */
   Return

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email tolists...@listserv.ua.edu  with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to