Re: [cc65] Probleme mit File-IO ( die 2te )

Date view Thread view Subject view

From: Marc 'BlackJack' Rintsch (marc_at_rintsch.de)
Date: 2001-08-24 13:10:07


Hi udo,

> i still have problems with file-io, although i think i followed the
> rules. here is a a small piece of code.
>
> [code snipped]
>
> the open returns rc=5
> sometimes a rc=2

I wasn't able to reproduce rc=5 (= device not present) but I get rc=2 
(= file open).

The Problem is with cbm_open() which doesn't give an error when you try 
to open a non-existent file for reading. You open the adressbook file 
which is not present and then you try to read the number of adresses 
from it. This fails but you don't close the file in your error check. 
That's why you get "file open" errors if you try to open it again.

Adding a 'cbm_close' to your error check in 'loadAdr' should be a 
workaround:

if(rc<2){
    DispError("Lese-Fehler");
    anz_adr=0;
    cbm_close(A_FNR);
    return;
}

BTW why are you checking rc<2 ? Every value except 0 is an error.

The same problem you have in BASIC with the status variable ST.

10 OPEN2,8,2,"XYZ,S,R"
20 PRINT ST
30 GET#2,A$
40 PRINT ST

Assuming that a sequential file named "XYZ" doesn't exist: First output 
of ST is 0 and only after really trying to read something from the file 
sets it to an error value.

I haven't found an easy way to check this just on the computer side, 
you have to read the error channel to get this error. That's the next 
item on my TODO list but I was very lazy when it comes to working on 
that functions.


While looking at your code I noticed that you could spare the 64 bytes 
of the local variable 'cmd' and the sprintf function call in 
Open(Input|Output) if you use the secondary adress as a selector for 
read and write:

cbm_open(2,8,1,"name,s") opens a file for writing and 
cbm_open(2,8,0,"name,s") opens it for reading. In both cases you could 
use the same filename. I think I'm gonna add constants for the 
secondary address to cbm.h

Ciao,
	Marc 'BlackJack' Rintsch
-- 
Who is General Failure and why is he reading my hard disk?

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:41 CET