Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
104 user(s) are online (65 user(s) are browsing Forums)

Members: 1
Guests: 103

Raziel, more...

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 *FileChannel256 ];

void DEFileOpenToReadint ChannelID, const char *FileName ){
  
int FOpened DEFileOpenedChannelID );
  if ( 
FOpened == ){
    if ( 
ChannelID ){
      if ( 
ChannelID 257 ){
        
FileChannelChannelID ] = OpenFileNameMODE_OLDFILE );
       }
     }
   }
 }

void DEFileOpenToWriteint ChannelID, const char *FileName ){
  
int FOpened DEFileOpenedChannelID );
  if ( 
FOpened == ){
    if ( 
ChannelID ){
      if ( 
ChannelID 257 ){
        
FileChannelChannelID ] = OpenFileNameMODE_NEWFILE );
       }
     }
   }
 }

void DECloseFileint ChannelID ){
  
int FOpened DEFileOpenedChannelID );
  if ( 
FOpened == ){
    
CloseFileChannelChannelID ] );
    
FileChannelChannelID ] = NULL;
   }
 }

void DEMakeMemblockFromFileExint MemblockID, const char *FileName ){
  
int ChannelID DENextFreeFile();
  
DEFileOpenToReadChannelIDFileName );
  
int FileSize IDOS->GetFileSizeFileChannelChannelID ] );
  
DEMakeMemblockMemblockIDFileSize );
  
IDOS->FReadFileChannelChannelID ], DEGetMemblockPTRMemblockID ), FileSize);
  
DECloseFileChannelID );
 }


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 *FileChannel256 ];

void DEFileOpenToReadint ChannelID, const char *FileName ){
  
int FOpened DEFileOpenedChannelID );
  if ( 
FOpened == ){
    if ( 
ChannelID ){
      if ( 
ChannelID 257 ){
        
FileChannelChannelID ] = OpenFileNameMODE_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-2023 The XOOPS Project