Author Topic: Note to all users of direntry.h  (Read 2641 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Note to all users of direntry.h
« on: June 26, 2020, 07:16:24 pm »
A friendly reminder for everyone:

C strings are NOT the same as QB64 strings.

It seems that everyone -- and, by everyone, I include myself in that count -- has been overlooking that glaringly obvious fact with the direntry.h functions. 

Blame me.  I didn't catch the glitch when I first released and demoed the routines, and the problem has perpetrated into tons of folks codes and routines. 

load_dir _CWD$ may not work as you'd expect with direntry.h.   _CWD$ is a QB64 string -- not a C string -- and it's missing one very important thing:  the null, end-of-string, terminator!

If you're using the direntry.h routines, go back and double check your programs to make certain that you null terminate them.

If you're using the demos I provided as a template for your own work, you should see something like the following in your code:

    CONST IS_DIR = 1
    DIM flags AS LONG, file_size AS LONG, length, nam$
    IF load_dir(SearchDirectory) THEN

You will probably want to null terminate that search string with something like the following:

    CONST IS_DIR = 1
    DIM flags AS LONG, file_size AS LONG, length, nam$
    IF load_dir(SearchDirectory + CHR$(0)) THEN



You've been warned here first.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Note to all users of direntry.h
« Reply #1 on: June 26, 2020, 07:56:14 pm »
Yes, that seems to fix the place where I was running into snags with the Tiny Navigator code I was using.

Now if only we can get confirmation that it works in Linux but I suspect we might have to reverse the slant when string together directories for a path.