James,

QDOS strings in C68 are normally represented by 2 fields as follows:

    unsigned short d_szname; /* size of name */
    char d_name[36]; /* name area */

the first being a short with the length, and the next being a char field
with the contents.   In your case it is actually working by 'luck' in that
QDOS tends to zero fill the unused space.    This is however not guaranteed
behaviour, and as you noted  your code will fail if the name is the maximum
allowed.   If you wanted to write bullet-proof C code you would use the
preceeding length field (d_szname) to tell you how much is valid in the
d_name field.   Also the QDOS format allows for 0 characters to be part of
the name, and again with your code this would fail as it would assume the 0
byte was the name terminator rather than part of the name itself.

Dave

----- Original Message ----- 
From: "James Hunkins" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 04, 2006 5:34 PM
Subject: Re: [ql-users] bug in qlib_h C68 support file


> Hi Guys,
>
> Three things were fooling me:
>
> 1) I was calling this using a C function so I 'assumed' that it was
> converting to C strings
>
> 2) when I grab the string, if under 36 characters, it always seems to
> have a 0 termination at the end
> [ assembly might be right filling the string with this ]
>
> 3) I do not see the first values at the start of the string for length
>    - I can handle this as a C string and have no garbage at the
> beginning and it terminates properly if < 36 chars
>
> The way I am using this is:
>
> DIR_LIST_t *tFileList;
>
> GetFileType(tFileList->dl_dir.d_name); /* calling function */
>
> short GetFileType(char *FileName)
> {
> printf("FileName: [%s]\n", FileName); /* this prints out the
> filename just fine if < 36 chars */
>
> }
>
>
> Unless I am missing something, it seems that the C call (haven't had
> time to dig up the source file yet) does at last a partial conversion
> from the QDOS structure.  Whether it on purpose adds the termination
> for items < 36 chars or not, don't know.
>
> With that said, going to take a break outside now that the rain has
> 'stopped' for a bit (3 day weekend, last of summer = rain).
>
> Cheers,
> jim
>
>
> On Sep 4, 2006, at 10:51 AM, Dave Walker wrote:
>
> > James,
> >
> > The header is correct - it defines a memory structure in QDOS, not a
> > structure designed for use with C.   As such the definition is
> > fixed and
> > cannot be changed.   You will find that under QDOS all strings are
> > preceded
> > by a 2-byte field that defines the length of the following string, and
> > strings are not zero-terminated.   When programming in C one should
> > always
> > therefore take account of this, and make sure that you use the length
> > limiting variants of copies and moves as you cannot assume a zero
> > termination to such strings.
> >
> > It can be advantageous to look at the .hdr versions of the header
> > files
> > supplied on one of the source disks.    These include comments
> > which can
> > make the files much easier to peruse.   You can also rename them
> > and put
> > them in place of the supplied .h files which have been processed to
> > remove
> > all comments and formatting to reduce their size for those using
> > floppy
> > based systems.  Those using hard disk based systems are better off
> > using the
> > commented versions
> >
> > Dave
> > .
> > ----- Original Message -----
> > From: "James Hunkins" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Monday, September 04, 2006 3:18 PM
> > Subject: [ql-users] bug in qlib_h C68 support file
> >
> >
> >> Guys,
> >>
> >> I think that I found a bug in the qlib_h include file used by C68.
> >> Here are the details:
> >>
> >> In the 'qdirect' structure, the member 'd_name' is defined as:
> >> char d_name[36];
> >>
> >> This works as long as the directory/file name is 35 or fewer
> >> characters and holds a properly terminated C string (terminates with
> >> a '0').  However, if the total name length is actually 36 characters,
> >> then there is no termination.  As far as I can tell the structure
> >> does properly hold everything and isn't corrupt, just no termination
> >> in that one case.
> >>
> >> This might explain why in a few problems with long file names, I see
> >> handling problems but not in others (compiled in C68 versus assembly
> >> or compiled SBASIC for example?).
> >>
> >> If I am correct this structure should define it as:
> >>
> >> char d_name[37];
> >>
> >> to allow room for the termination character of a C string.
> >>
> >> Jim
> >>
> >> _______________________________________________
> >> QL-Users Mailing List
> >> http://www.q-v-d.demon.co.uk/smsqe.htm
> >
> > _______________________________________________
> > QL-Users Mailing List
> > http://www.q-v-d.demon.co.uk/smsqe.htm
>
> _______________________________________________
> QL-Users Mailing List
> http://www.q-v-d.demon.co.uk/smsqe.htm

_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to