![]() |
![]() |
![]() |
#1 |
Registered User
![]() Join Date: May 2022
Location: Adelaide
Posts: 94
|
DOS Questions
Thanks in advance. |
![]() |
![]() |
#2 |
Registered User
![]() Join Date: May 2021
Location: Melbourne, Australia
Posts: 30
|
A file handle is used to refer to a file (stream) that has been opened. Opening it implies a lock.
A lock can refer to things other than files (such as directories or volumes) and do not require opening. See this link to the appropriate documentation. It is for OS4 but the concept is basically the same for OS3. https://wiki.amigaos.net/wiki/AmigaD...s#File_Handles Finally, creating a FileInfoBlock in an AmigaDOS compatible way is best done with the following code: Code:
struct FileInfoBlock *fib = (struct FileInfoBlock *)AllocDosObjectTags(DOS_FIB, TAG_DONE); Code:
FreeDosObject(DOS_FIB, fib); If you are writing code for a version of the OS that is too old, you can also use Code:
AllocMem(sizeof(struct FileInfoBlock), 0); What you definitely DON'T want to do is reserve space on the stack because that probably isn't longword aligned and will cause a crash. |
![]() |
![]() |
#3 |
Registered User
![]() Join Date: May 2022
Location: Adelaide
Posts: 94
|
If I write to a file once, do I need to seek to the start of it to write again?
Last edited by Steam Ranger; 28 November 2022 at 09:26. |
![]() |
![]() |
#4 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 2,394
|
I am sorry, but I do not quite understand which problem you attempt to solve. If you open a file for writing (MODE_NEWFILE), then if there is a file of the same name exists, it will be erased first, and you will write from offset 0 on. For any other mode, the file contents remains untouched, and you start overwriting from offset 0 on, leaving all bytes behind your current write position untouched. Thus, the pointer into the file is always at 0 after opening a file.
If a file is already open, the write pointer advances by the number of bytes you write. Thus, if you then seek backwards to offset 0, you start overwriting what you have written, without actually truncating the file. |
![]() |
![]() |
#5 |
Moderator
![]() Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,318
|
AmigaDev is a great resource, but only for reference if you already have some experience with how the OS works. For how to, the System Programmer's Guide has examples (in Assembler) with texts that explain the concepts.
|
![]() |
![]() |
#6 |
Moderator
![]() Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,318
|
AmigaDev is a great resource, but only for reference if you already have some experience with how the OS works. For how to, the System Programmer's Guide has examples (in Assembler) with texts that explain the concepts.
Seeking is rarely done unless you are dealing with a multi-megabyte file. In older computers this sometimes had to be done also for smaller files (due to many reasons, slow media and little RAM being the most relevant). The typical flow is to get a file handle, then open, read or write the complete file, and close. |
![]() |
![]() |
#7 |
Registered User
![]() Join Date: May 2022
Location: Adelaide
Posts: 94
|
Ok. So to overwrite an open file multiple times, you need to seek. Thanks.
I'll also check out the links. |
![]() |
![]() |
#8 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 2,394
|
In that generality, no. If you want to overwrite a file, close the file handle of the file. Re-open the file with MODE_NEWFILE. No seeking necessary.
Note that if you keep the file open, and you seek back, you do not truncate it. The data that is in there remains in there, you are just overwriting what is there. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Apollo 1240 - Questions about questions | StompinSteve | Hardware mods | 19 | 19 July 2021 02:05 |
PCMCIA fault: DOS error code 225 - Not a valid DOS disk | 4am | support.Hardware | 2 | 07 April 2012 10:20 |
Amiga DOS | aragon127 | support.WinUAE | 1 | 22 April 2004 03:26 |
For those of you that must run old MS-DOS games, DOS Box has been ported | Pyromania | Amiga scene | 19 | 06 June 2003 11:44 |
cross dos help | fastflange | request.Apps | 2 | 19 June 2002 17:56 |
|
|