delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/08/22/07:56:39

Message-ID: <39A26B24.D48FE245@softhome.net>
Date: Tue, 22 Aug 2000 13:59:32 +0200
From: Laurynas Biveinis <lauras AT softhome DOT net>
X-Mailer: Mozilla 4.74 [en] (Win98; U)
X-Accept-Language: lt,en
MIME-Version: 1.0
To: DJGPP Workers <djgpp-workers AT delorie DOT com>
Subject: Patch: symlinks in access()
Reply-To: djgpp-workers AT delorie DOT com

Works OK for me.

Any comments before commiting?

Laurynas

Index: access.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/access.c,v
retrieving revision 1.5
diff -u -p -r1.5 access.c
--- access.c	1999/08/04 19:58:24	1.5
+++ access.c	2000/08/22 11:53:57
@@ -1,8 +1,10 @@
+/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
 #include <libc/stubs.h>
+#include <libc/symlink.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -10,18 +12,25 @@
 #include <dir.h>
 #include <errno.h>
 #include <dirent.h>
+#include <limits.h>
 
 int access(const char *fn, int flags)
 {
-  int attr = _chmod(fn, 0);
+  int attr;
+  char file_name[FILENAME_MAX];
 
+  if (!__solve_symlinks(fn, file_name))
+     return -1;
+
+  attr = _chmod(file_name, 0);
+
   if (attr == -1) {
     struct ffblk ff;
     char fixed_path[FILENAME_MAX];
 
     /* Root directories on some non-local drives (e.g. CD-ROM)
        might fail `_chmod'.  `findfirst' to the rescue.  */
-    _fixpath(fn, fixed_path);
+    _fixpath(file_name, fixed_path);
     if (fixed_path[1] == ':' && fixed_path[2] == '/' && fixed_path[3] == 0)
       {
         char *fp = fixed_path + 3;
@@ -41,7 +50,7 @@ int access(const char *fn, int flags)
 
     /* Devices also fail `_chmod'; some programs won't write to
        a device unless `access' tells them they are writeable.  */
-    if (findfirst(fn, &ff, FA_RDONLY | FA_ARCH) == 0
+    if (findfirst(file_name, &ff, FA_RDONLY | FA_ARCH) == 0
 	&& (ff.ff_attrib & 0x40) == 0x40
 	&& (flags & (X_OK | D_OK)) == 0)
     {
@@ -70,7 +79,7 @@ int access(const char *fn, int flags)
 
   if (flags & X_OK)
   {
-    if (!_is_executable(fn, 0, 0))
+    if (!_is_executable(file_name, 0, 0))
     {
       errno = EACCES;
       return -1;

- Raw text -


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