Strange Error with Carbon FSWriteFork()

There were existing codes written with Carbon APIs. It has worked so far, but strangely it started malfunctioning. I simplified the troubled part by statically allocating memory it uses to show the problem more clearly here.

memset( testData, 'P', 400);
g_total_length = 400;
g_paged_aligned_buffer = testData;

int numIter;

numIter = 0;
while( numIter < 4 )
    err = FSWriteFork(refNumOut, thePositionMode, 0, g_total_length,
                             g_paged_aligned_buffer, &theActualBytes);

    if (err != 0 || g_total_length != theActualBytes)
        MsgBox(@"Error", @"Could not write the data to the destination file (In AddSamplesToExportFile)");

        free( g_paged_aligned_buffer );

        return 2;

When the FSWriteFork() is called repeatedly it returns -50 which means that there is something wrong with its parameters. It is pretty hard to figure out what is wrong. As I said earlier this code has been worked before. I just test it with 12 channel audio and it made it malfunctioning.

So, probably the thePositionMode is wrong. It is just 0. So, I tried turning of its caching feature by bit-ORing it with noCacheBit and noCacheMask.
After doing so, its simplified version started working without any problem.

However, when I enabled original codes block, it still didn’t work.
So, there must be something more is involved. The “thePositionMode” is 0, so it is same to fsAtMark. So, new write will be done after last position it wrote. What can be the cause of the -50 error? Hmmm..

Any ideas?
By the way, I have noticed many Carbon calls like this. In other words, it doesn’t tell much why it returns some error code.

UPDATED : It turned out that it was not a problem of Carbon functions. A CIF server, I use, validates incoming data packet and if it is not not formatted well, the CIF server rejects the incoming packets. I implemented it using Cocoa, but it also returned an error message which said, “some of the parameters are wrong.”. It would be much nicer if the message or description of Apple’s document is better though. Anyway, the Cocoa code is much shorter and nicer to debug.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: