Amiga-Development

Please login or register.

Login with username, password and session length
Advanced search  

News:

Created for developers of all Amiga camps

Author Topic: fgetc() in dos.library crashes the OS (no C runtime)  (Read 1017 times)

0 Members and 1 Guest are viewing this topic.

Rink

  • Newbie
  • *
  • Posts: 3
    • View Profile
fgetc() in dos.library crashes the OS (no C runtime)
« on: March 28, 2016, 10:06:45 AM »

Hi all,

I'm trying to get back into Amiga C coding, for the first time since the A1200 came out. I have a problem and was hoping someone here could point me in the right direction.

I'm using SAS/C 6.5.8, with C runtime startup code disabled, on an installation of Workbench 1.3 in WinUAE.

Basically, when I run this, this code crashes the entire OS when fgetc() is called. The DOS library does find the file ok, so I'm guessing it's related to my project build settings (which I'll try and include below).

Code: [Select]
#include <proto/dos.h>
#include <proto/exec.h>

void Test(void) {
BPTR fh;
UBYTE buf[5];
UBYTE *count;

    struct DOSLibrary *DOSBase = (struct DOSLibrary*)OpenLibrary("dos.library", 0L);
    Write(Output(), "==Test==\n", 9);

    fh = Open("Resources/Test.iff", MODE_OLDFILE);
    if (fh) {
    Write(Output(), "Opened\n", 7);

    buf[0] = FGetC(fh);
    Write(Output(), buf, 1L);

    Close(fh);
    Write(Output(), "Closed\n", 7);
} else {
Write(Output(), "Failed!\n", 8);
}

    CloseLibrary((struct Library*)DOSBase);
}

Here are the compiler options that I have set (all of the others are just at SAS/C defaults - let me know if there's any you want to see):

Compiler options: StringMerge
Code options: Parms=REGISTER, NoStackCheck
List/Xref options: NoList, NoXref
Optimizer Options...: NoOptimize
Prototype Options...: NoGenProto
Linker Options: Link, SmallCode, SmallData, AddSym, NoStripDebug, NoChkAbort, NoBatch, NoStartup
Map Options...: NoMap
NoVerbose

I have used these settings before for other tests (mostly Intuition library tests).

The program builds with no errors or warnings, and pops up this box when run (from a Shell):
Software error - task held. Finish ALL disk activity Select CANCEL to reset/debug

Followed by...
Guru Meditation #00000004.00C20458

Any ideas would be much appreciated.
Logged

thomas

  • Newbie
  • *
  • Gender: Male
  • Posts: 10
    • View Profile
Re: fgetc() in dos.library crashes the OS (no C runtime)
« Reply #1 on: March 29, 2016, 12:17:31 PM »


FGetC only exists in 2.0 and above.

Use OpenLibrary("dos.library", 36L) and check the result to run safely.

Logged

Rink

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: fgetc() in dos.library crashes the OS (no C runtime)
« Reply #2 on: March 29, 2016, 05:21:31 PM »

FGetC only exists in 2.0 and above.
Well that would certainly explain it. ;D

Although I'm now pretty embarrassed, given how many hours I've wasted trying to figure this one out. Good learning experience though.

Cheers mate.
Logged

Rink

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: fgetc() in dos.library crashes the OS (no C runtime)
« Reply #3 on: April 01, 2016, 05:55:02 PM »

Bit of a delay in replying, but I finally got around to replacing the call to FGetC() with one to Read() and everything is working fine.

Lesson learned: read up on which functions are in which versions of libraries before trying to use them. :)

Thanks again Thomas.
Logged