This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH/RFA add "access" function for ARM


Richard Earnshaw wrote:
> 
> This patch adds the access() function for the ARM to newlib.
> Implementation isn't perfect, since there isn't really enough information
> available to do the job properly; but it's enough to make most of the f77
> tests in the gcc testsuite that rely on this function pass.
> 
> If this is ok, could someone please install it.
> 
> R.
> 
> PS, I'm not on this mailing list; please cc me directly on any follow up.
> 
> <date>  Richard Earnshaw  <rearnsha@arm.com>
> 
>         * sys/arm/access.c: New file.
>         * sys/arm/Makefile.am (lib_a_SOURCES): Add it
>         * sys/arm/Makefile.in: Regenerate.
>         * sys/arm/syscalls.c (_stat): New function.
> 

Richard,

  First of all, we don't add files with the copying.dj licence
in regular directories any more.  As it so happens, the access.c
file licence has been relaxed by DJ in the past and we can take a copy 
from the libgloss/mn10300 directory which has the less restrictive
licence.

  Can you comment on whether the change to _fstat is needed by f77
(i.e. is it just there to support _stat and thus: access() or does f77
rely on fstat returning S_IFREG | S_IREAD for st_mode).  I would prefer
to remove the call to _fstat and just set st manually since _stat
has confirmed that the file is regular and readable, not _fstat.
I have included a modified version of the patch in case you want
to verify whether the _fstat change is needed.

-- Jeff J.
Index: Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/arm/Makefile.am,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Makefile.am
--- Makefile.am	2000/02/17 19:39:49	1.1.1.1
+++ Makefile.am	2002/03/08 22:35:10
@@ -6,7 +6,7 @@
 
 noinst_LIBRARIES = lib.a
 
-lib_a_SOURCES = syscalls.c libcfunc.c trap.S setjmp.S
+lib_a_SOURCES = access.c syscalls.c libcfunc.c trap.S setjmp.S
 
 all: crt0.o
 
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/arm/Makefile.in,v
retrieving revision 1.2
diff -u -r1.2 Makefile.in
--- Makefile.in	2001/12/13 23:49:59	1.2
+++ Makefile.in	2002/03/08 22:35:10
@@ -84,7 +84,7 @@
 
 noinst_LIBRARIES = lib.a
 
-lib_a_SOURCES = syscalls.c libcfunc.c trap.S setjmp.S
+lib_a_SOURCES = access.c syscalls.c libcfunc.c trap.S setjmp.S
 
 ACLOCAL_AMFLAGS = -I ../../..
 CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
@@ -98,7 +98,7 @@
 CPPFLAGS = @CPPFLAGS@
 LIBS = @LIBS@
 lib_a_LIBADD = 
-lib_a_OBJECTS =  syscalls.o libcfunc.o trap.o setjmp.o
+lib_a_OBJECTS =  access.o syscalls.o libcfunc.o trap.o setjmp.o
 CFLAGS = @CFLAGS@
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
Index: access.c
===================================================================
RCS file: access.c
diff -N access.c
--- access.c	Tue May  5 13:32:27 1998
+++ access.c	Fri Mar  8 14:35:10 2002
@@ -0,0 +1,33 @@
+/* This is file ACCESS.C */
+/*
+ * Copyright (C) 1993 DJ Delorie
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms is permitted
+ * provided that the above copyright notice and following paragraph are
+ * duplicated in all such forms.
+ *
+ * This file is distributed WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int access(const char *fn, int flags)
+{
+  struct stat s;
+  if (stat(fn, &s))
+    return -1;
+  if (s.st_mode & S_IFDIR)
+    return 0;
+  if (flags & W_OK)
+  {
+    if (s.st_mode & S_IWRITE)
+      return 0;
+    return -1;
+  }
+  return 0;
+}
+	
Index: syscalls.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/arm/syscalls.c,v
retrieving revision 1.4
diff -u -r1.4 syscalls.c
--- syscalls.c	2002/01/17 16:39:53	1.4
+++ syscalls.c	2002/03/08 22:35:10
@@ -21,6 +21,7 @@
 void    _raise 		_PARAMS ((void));
 int     _unlink		_PARAMS ((void));
 int     _link 		_PARAMS ((void));
+int     _stat 		_PARAMS ((const char *, struct stat *));
 int     _fstat 		_PARAMS ((int, struct stat *));
 caddr_t _sbrk		_PARAMS ((int));
 int     _getpid		_PARAMS ((int));
@@ -513,6 +514,22 @@
   st->st_blksize = 1024;
   return 0;
   file = file;
+}
+
+int _stat (const char *fname, struct stat *st)
+{
+  int file;
+
+  /* The best we can do is try to open the file readonly.  If it exists,
+     then we can guess a few things about it.  */
+  if ((file = _open (fname, O_RDONLY)) < 0)
+    return -1;
+
+  memset (st, 0, sizeof (* st));
+  st->st_mode = S_IFREG | S_IREAD;
+  st->st_blksize = 1024;
+  _swiclose (file); /* Not interested in the error.  */
+  return 0;
 }
 
 int

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]