www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/11/15/12:22:01

Message-ID: <38303105.4DB4F377@softhome.net>
Date: Mon, 15 Nov 1999 18:12:53 +0200
From: Laurynas Biveinis <lauras AT softhome DOT net>
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 <eliz AT is DOT elta DOT co DOT il>
Subject: Re: First alpha symlink patch
References: <Pine DOT SUN DOT 3 DOT 91 DOT 991115112547 DOT 26969A-100000 AT is>
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 <libc/stubs.h>
+#include <libc/symlink.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -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)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019