On Sat, 10 Sep 2022 18:45:04 -0500, Charles Mills wrote:

>I am working on a Rexx program that reads one or more UNIX files. 
>    ...
>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?)
>
    SYSCALL  strerror error_code reason_code stem
might tell you more.

I always use SIGNAL ON NOVALUE.  It finds unsuspected errors.

Does open return the same Filefd each time?  As an experiment
you might try omitting the close to see how it works with a different
fd.  (WAG!)

for:
>  if RC = -1 Then Do
>    Call Print "Error from Log File open. RC =" RC errno errnojr

RC is(usually) nonzero if Rexx is unable to issue a system call,
in which case errno and errnojr are meaningless, perhaps unset.

>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

-- 
gil

----------------------------------------------------------------------
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