Paul.Thieme@xxxxxxxxxxxxxxxxx wrote:
Everything works fine. My problem is I don't understand what
%str(%addr(d_name)) is doing and why it is needed.

Walking through the program in debug, I noticed that d_name has a value. I
changed the code to the "easier on the eyes" version which is simply taking
a 256 char field and truncating it in a 120 char field.

Paul, readdir() returns a null-terminated string in d_name. The x'00' character is the null-terminator. In the debugger (see below), this character looks like a blank, but you can see it in the hex output if you use
eval d_name:x

The %STR builtin function looks for the null-terminator and ignores everything after it.

It looks like both %STR and %SUBST are equally valid ways of handling the output of readdir. (Assuming that it's impossible for a directory name to be longer than 639.)

In this debugger session, you can see the '00' in the second line of the hex listing for d_name:x

> EVAL d_name
1 '/home/mydir/a.txt

> EVAL d_name:x
00000 61889694 856194A8 848999...
00010 A3004040 40404040 404040...

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].