Message-ID: <38303105.4DB4F377@softhome.net> Date: Mon, 15 Nov 1999 18:12:53 +0200 From: Laurynas Biveinis X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: lt,en MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com CC: Eli Zaretskii Subject: Re: First alpha symlink patch References: Content-Type: text/plain; charset=iso-8859-4 Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Eli Zaretskii wrote: > I don't know, they might. Did you try to call `getcwd' in a recursive > program, like the one which calls `ftw'? If not, it might be a good > idea. Well, I'm not certain, about what kind of recursive situation you're talking about. I tried the ftw() example given in docs, and it revealed another bug, not related with that above - it uses _chmod() to detect if path is a directory and I didn't make _chmod(), _open(), _any_dos_call_wrapper() functions see symlinks on purpose. Below is a patch for ftw.c, applies cleanly with or without first patch. BTW, how could DOS store `current directory' itself? IMHO in global variable. > > I wanted that first symlink file test would be fast and sort > > out 95% of non symlink cases, and only remaining 5% or so files would be > > opened, readed first few charactes > > Understood. I thought about this a bit, and it seems to me that the > only other way to do it would be to have symlinks be of constant known > size. Then you can call findfirst and look at the size to sort out > most of the files. It should be as fast as the attribute check, since > _chmod shares lots of code with findfirst (inside DOS, I mean). Sounds good. So let the symlinks be 376 bytes in size (just not the power of 2). Laurynas Biveinis -------- --- djgpp.old/src/libc/dos/dir/ftw.c Mon Aug 28 05:38:52 1995 +++ djgpp/src/libc/dos/dir/ftw.c Mon Nov 15 18:01:36 1999 @@ -1,4 +1,6 @@ +#define TEST /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */ /* ftw() for DJGPP. * * Recursively descent the directory hierarchy rooted in DIR, @@ -12,6 +14,7 @@ */ #include +#include #include #include #include @@ -107,6 +110,7 @@ { int flag; unsigned char pathbuf[FILENAME_MAX]; + unsigned char real_path[FILENAME_MAX]; int dirattr; int len; int e = errno; @@ -135,7 +139,12 @@ /* Fail for non-directories. */ errno = 0; - dirattr = _chmod(pathbuf, 0, 0); + /* _chmod() does not recognize symlinks, */ + /* so we give real name instead. */ + if (!_solve_symlinks(pathbuf, real_path)) + return -1; + + dirattr = _chmod(real_path, 0, 0); if (errno == ENOENT) return -1; else if ((dirattr & 0x10) != 0x10)