Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
120 user(s) are online (60 user(s) are browsing Forums)

Members: 1
Guests: 119

kas1e, more...

Support us!

Headlines

 
  Register To Post  

[FIXED] IDOS->Open / Close / FRead / GetFileSize
Quite a regular
Quite a regular


See User information
Hi All,

I Try to use dos lib to open to read/write files.

I have made some functions for this but I encounter some problems.
Here are the functions :
FILE *FileChannel[ 256 ];

void DEFileOpenToRead( int ChannelID, const char *FileName ){
  
int FOpened = DEFileOpened( ChannelID );
  if ( 
FOpened == 0 ){
    if ( 
ChannelID > 0 ){
      if ( 
ChannelID < 257 ){
        
FileChannel[ ChannelID ] = Open( FileName, MODE_OLDFILE );
       }
     }
   }
 }

void DEFileOpenToWrite( int ChannelID, const char *FileName ){
  
int FOpened = DEFileOpened( ChannelID );
  if ( 
FOpened == 0 ){
    if ( 
ChannelID > 0 ){
      if ( 
ChannelID < 257 ){
        
FileChannel[ ChannelID ] = Open( FileName, MODE_NEWFILE );
       }
     }
   }
 }

void DECloseFile( int ChannelID ){
  
int FOpened = DEFileOpened( ChannelID );
  if ( 
FOpened == 1 ){
    
Close( FileChannel[ ChannelID ] );
    
FileChannel[ ChannelID ] = NULL;
   }
 }

void DEMakeMemblockFromFileEx( int MemblockID, const char *FileName ){
  
int ChannelID = DENextFreeFile();
  
DEFileOpenToRead( ChannelID, FileName );
  
int FileSize = IDOS->GetFileSize( FileChannel[ ChannelID ] );
  
DEMakeMemblock( MemblockID, FileSize );
  
IDOS->FRead( FileChannel[ ChannelID ], DEGetMemblockPTR( MemblockID ), FileSize, 1 );
  
DECloseFile( ChannelID );
 }


Concerning Open / Close, I get errors on compilations :

undefined reference to 'close'
undefined reference to 'open'

if I try to change this by :

if I change with IDOS->Open, I get warning :
PAssing argument 2 of 'IDOS->Close' makes integer from pointer without a cast ) ...
Arg 2 is not a pointer ... strange ?

Of course, I have <proto/dos.h> included ;)
and GetFileSize and FRead are correctly identified and does not report any error on compilation.

Don't mind .. I have checked the sample in AmigaOS 4 SDK and founded what was wrong :p

Kindest Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: [FIXED] IDOS->Open / Close / FRead / GetFileSize
Home away from home
Home away from home


See User information
@freddix

You're welcome. Was just about to replay when i saw you're edit.

X5000
Go to top
Re: [FIXED] IDOS->Open / Close / FRead / GetFileSize
Quite a regular
Quite a regular


See User information
@Antique
Loool :p

All we have to decide is what to do with the time that is given to us.
Go to top
Re: [FIXED] IDOS->Open / Close / FRead / GetFileSize
Just popping in
Just popping in


See User information
@freddix

Quote:
FILE *FileChannel[ 256 ];

void DEFileOpenToRead( int ChannelID, const char *FileName ){
  
int FOpened = DEFileOpened( ChannelID );
  if ( 
FOpened == 0 ){
    if ( 
ChannelID > 0 ){
      if ( 
ChannelID < 257 ){
        
FileChannel[ ChannelID ] = Open( FileName, MODE_OLDFILE );
       }
     }
   }
 }


If you are using the DOS functions instead of the C library function the correct type for a file handle is BPTR instead of FILE*.

Furthermore you implemented the "zero index problem" at best. An array declared as "array[256]" has indices 0 to 255, but you check for 1 to 256. This will always leave the first entry unused (harmless) and write beyond the array bounds for the last entry (very harmful!!!).

Quote:
if I change with IDOS->Open, I get warning :
PAssing argument 2 of 'IDOS->Close' makes integer from pointer without a cast ) ...
Arg 2 is not a pointer ... strange ?


Not strange at all, given the fact that dos/Open() and dos/Close() use a BPTR variable, which in fact is a LONG and no real pointer.

Go to top
Re: [FIXED] IDOS->Open / Close / FRead / GetFileSize
Quite a regular
Quite a regular


See User information
@tboeckel :
Yes, it's what I've seen and why I put it as "fixed" :p

All we have to decide is what to do with the time that is given to us.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project