dirent on IRIX - d_type and d_fileno?
#1
dirent on IRIX - d_type and d_fileno?
Hey guys, 

Currently looking at porting NetBSD's patch and OpenBSD's diff to IRIX to replace its outdated GNU diff versions. 

One issue I'm running into is constant issues with IRIX's dirent implementation. In particular, its structs for it appear to lack certain members, namely:

d_type 
d_fileno 

For the first one, I found a stack overflow that suggested I try using stat instead:

https://stackoverflow.com/questions/3942...7#39430337

I have been studying that more. I wanted to get some clarification from others here on whether or not this is a good approach. The function using d_type and d_fileno is:

Code:
/*
* Do the actual diff by calling either diffreg() or diffdir().
*/
static void
diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2,
    int flags)
{
        flags |= D_HEADER;
        strlcpy(path1 + plen1, dp->d_name, PATH_MAX - plen1);
        if (stat(path1, &stb1) != 0) {
                if (!(Nflag || Pflag) || errno != ENOENT) {
                        warn("%s", path1);
                        return;
                }
                flags |= D_EMPTY1;
                memset(&stb1, 0, sizeof(stb1));
        }

        strlcpy(path2 + plen2, dp->d_name, PATH_MAX - plen2);
        if (stat(path2, &stb2) != 0) {
                if (!Nflag || errno != ENOENT) {
                        warn("%s", path2);
                        return;
                }
                flags |= D_EMPTY2;
                memset(&stb2, 0, sizeof(stb2));
                stb2.st_mode = stb1.st_mode;
        }
        if (stb1.st_mode == 0)
                stb1.st_mode = stb2.st_mode;

        if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
                if (rflag)
                        diffdir(path1, path2, flags);
                else
                        printf("Common subdirectories: %s and %s\n",
                            path1, path2);
                return;
        }
        if (!S_ISREG(stb1.st_mode) && !S_ISDIR(stb1.st_mode))
                dp->d_status = D_SKIPPED1;
        else if (!S_ISREG(stb2.st_mode) && !S_ISDIR(stb2.st_mode))
                dp->d_status = D_SKIPPED2;
        else
                dp->d_status = diffreg(path1, path2, flags);
        print_status(dp->d_status, path1, path2, "");
}

For those who want the complete file, it's here: https://raw.githubusercontent.com/openbs.../diffdir.c

I am trying to figure out a good way to translate this to IRIX. 

Other small things have been gathered that I'm working on, but this is the big one.

For those wondering why I chose OpenBSD's diff, it's small, simple and thus far has not required many major fixes to get it compiling.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-24-2021, 06:44 PM
#2
RE: dirent on IRIX - d_type and d_fileno?
Raion, I know you're not much of a GNU fan, but looking at their dirent.h it appears they don't force you to use either d_type or d_fileno.

Anyway, have you seen this for d_type

https://c-for-dummies.com/blog/?p=3252

Project: Temporarily lost at sea
Plan: World domination! Or something...
vishnu
Tezro, Octane2, 2 x Onyx4

Trade Count: (0)
Posts: 1,245
Threads: 41
Joined: Dec 2017
Location: Minneapolis, Minnesota USA
Find Reply
04-25-2021, 03:30 AM
#3
RE: dirent on IRIX - d_type and d_fileno?
The GNU diffutils package is far and above more costly in terms of lines of code, and I don't want GPL contamination in base.

We have Nedit, which historically came on IRIX, but nothing else really is going to be permissible. If I can't get it ported, I have the illumos-gate versions I can fall back on likely. There's a cost-benefit here, if I want to replace an IRIX tool which is known insufficient, has known problems etc, I'd rather first do a BSD/MIT licensed version.

Plus, this is good practice for me.

And cool, that does explain stat() rewrites a bit better. Once I rewrite this, it should be relatively easy to finish porting diff to IRIX. Patch requires removing some RCS code and moving around some structs, but that all looks easy.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-25-2021, 03:52 AM
#4
RE: dirent on IRIX - d_type and d_fileno?
Are you just going to use the BSD header files locally? #include "dirent.h" as oppsed to #include <dirent.h> I mean...

Project: Temporarily lost at sea
Plan: World domination! Or something...
(This post was last modified: 04-25-2021, 04:02 AM by vishnu.)
vishnu
Tezro, Octane2, 2 x Onyx4

Trade Count: (0)
Posts: 1,245
Threads: 41
Joined: Dec 2017
Location: Minneapolis, Minnesota USA
Find Reply
04-25-2021, 04:02 AM
#5
RE: dirent on IRIX - d_type and d_fileno?
I'd rather rewrite the code than potentially introduce problems with local headers. Thus far I've had to change bits and pieces of diff and patch to work on IRIX. Some are compiler specific fixes (i.e. mipspro). Others were to change other dirent issues, and to fix a few printf %zu moduli.

I get the argument of "Why waste time on X when Y works perfectly?" but sometimes the answer isn't to use a premade solution that's not the best tool for the job. Having GNU utils in a public IRIXCE source tree means more license notices need to be placed, and potentially greater separation and clarification to satisfy the GPL. At the end of the day, I'm the one currently in charge of stuff going into IRIXCE - and for me it's priority one if a GPL utility is in IRIX's base to be replaced with a better one.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-25-2021, 04:06 AM
#6
RE: dirent on IRIX - d_type and d_fileno?
Actually GNU dirent is released under the LGPL, which, at least as I understand it makes it more or less as usable as the BSD license. That said, I understand perfectly well your desire to keep GNU completely out of IRIXCE. License lawyers are a PITA. But remember, when GNU g++ first adopted the STL it was the SGI version copied verbatim. Same thing with the Linux multiprocessor code, the original version came 100 percent from SGI. Linus bitched, moaned whined and complained about it but he nonetheless accepted it into the kernel.

Project: Temporarily lost at sea
Plan: World domination! Or something...
(This post was last modified: 04-25-2021, 04:29 AM by vishnu.)
vishnu
Tezro, Octane2, 2 x Onyx4

Trade Count: (0)
Posts: 1,245
Threads: 41
Joined: Dec 2017
Location: Minneapolis, Minnesota USA
Find Reply
04-25-2021, 04:26 AM
#7
RE: dirent on IRIX - d_type and d_fileno?
Oh, I think we got off on the wrong foot.

GNULib you meant? i thought you meant GNU Diff/Patch

I generally avoid GNULib, but maybe I should consider a dirent addition to libxg.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-25-2021, 04:31 AM
#8
RE: dirent on IRIX - d_type and d_fileno?
Okay now we're on the same page! Cool

Yes the GNU C library is all LGPL so you could conceivably hold your nose and go ahead and use it. But if the BSD C library amounts to more or less the same amount of required hacking, obviously that would be preferable...

Project: Temporarily lost at sea
Plan: World domination! Or something...
vishnu
Tezro, Octane2, 2 x Onyx4

Trade Count: (0)
Posts: 1,245
Threads: 41
Joined: Dec 2017
Location: Minneapolis, Minnesota USA
Find Reply
04-25-2021, 04:42 AM
#9
RE: dirent on IRIX - d_type and d_fileno?
More so what my original plan was to figure out how to rewrite it using stat() for portability sake as Solaris also does not use d_type.

If I can't for whatever reason get it to work though this is a good plan.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-25-2021, 05:01 AM
#10
RE: dirent on IRIX - d_type and d_fileno?
Do you have your work in progress in a git repo anywhere? I'd be happy to contribute to the effort... Cool

Project: Temporarily lost at sea
Plan: World domination! Or something...
vishnu
Tezro, Octane2, 2 x Onyx4

Trade Count: (0)
Posts: 1,245
Threads: 41
Joined: Dec 2017
Location: Minneapolis, Minnesota USA
Find Reply
04-25-2021, 05:07 AM


Forum Jump:


Users browsing this thread: 1 Guest(s)