This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos 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]

[PATCH] add ftok() and getenv() functions to the synthetic target


Hi,

the attached patch implements ftok() and getenv() for the synthetic target. 
This is quite useful, since often ipc keys are generated using ftok() and 
environment variables (getenv()).
Both ftok() and getenv() are taken from FreeBSD. The FreeBSD getenv() is 
smaller and has no dependencies as compared to the eCos getenv() (which uses 
strlen() and strncmp()).

Please apply.

Bye
Alex
-- 
Work: alexander.neundorf@jenoptik.com - http://www.jenoptik-los.de
Home: neundorf@kde.org                - http://www.kde.org
      alex@neundorf.net               - http://www.neundorf.net
Index: current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/ChangeLog,v
retrieving revision 1.30
diff -b -u -p -r1.30 ChangeLog
--- current/ChangeLog	30 Jul 2005 11:10:34 -0000	1.30
+++ current/ChangeLog	19 Oct 2005 17:13:38 -0000
@@ -1,3 +1,8 @@
+2005-10-19  Alexander Neundorf <neundorf@kde.org>
+
+	* src/synth_syscall.c: add cyg_hal_sys_ftok() and
+	cyg_hal_sys_getenv() functions
+
 2005-07-30  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* src/synth_diag.c (hal_diag_write_char): Compiler warning fix.
Index: current/include/hal_io.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/include/hal_io.h,v
retrieving revision 1.13
diff -b -u -p -r1.13 hal_io.h
--- current/include/hal_io.h	11 Mar 2005 19:04:07 -0000	1.13
+++ current/include/hal_io.h	19 Oct 2005 17:13:38 -0000
@@ -514,6 +514,10 @@ externC void *          cyg_hal_sys_shma
 //detach from it again
 externC int             cyg_hal_sys_shmdt (const void* shmaddr);
 
+// Convert a pathname and an identifier into a System V IPC key
+externC int             cyg_hal_sys_ftok(const char* path, int id);
+
+
 // The actual implementation appears to return the new brk() value.
 externC void*           cyg_hal_sys_brk(void*);
 
@@ -546,6 +550,8 @@ extern int              cyg_hal_sys_argc
 extern const char**     cyg_hal_sys_argv;
 extern const char**     cyg_hal_sys_environ;
 
+externC const char* cyg_hal_sys_getenv(const char* name);
+
 // ----------------------------------------------------------------------------
 // Interaction between the application and the auxiliary.
 
Index: current/src/synth_syscalls.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/src/synth_syscalls.c,v
retrieving revision 1.1
diff -b -u -p -r1.1 synth_syscalls.c
--- current/src/synth_syscalls.c	15 Dec 2004 14:01:39 -0000	1.1
+++ current/src/synth_syscalls.c	19 Oct 2005 17:13:39 -0000
@@ -35,6 +35,33 @@
 // this file might be covered by the GNU General Public License.
 // -------------------------------------------
 //####ECOSGPLCOPYRIGHTEND####
+/* ftok() and getenv() are taken from FreeBSD:
+ *
+ * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
 //=============================================================================
 //#####DESCRIPTIONBEGIN####
 //
@@ -51,6 +78,8 @@
 #include <cyg/infra/cyg_type.h>
 #include <cyg/hal/hal_diag.h>
 #include <cyg/hal/hal_io.h>
+#include <cyg/infra/cyg_ass.h>
+#include <cyg/infra/cyg_trac.h>
 
 void * cyg_hal_sys_shmat(int shmid, const void* shmaddr, int shmflg)
 {
@@ -92,3 +121,37 @@ cyg_hal_sys_mmap(void *addr, unsigned lo
   
   return (cyg_hal_sys_mmapx(&args));
 } 
+
+int cyg_hal_sys_ftok(const char* path, int id)
+{
+   struct cyg_hal_sys_stat st;
+
+   if (cyg_hal_sys_lstat(path, &st) < 0)
+      return (cyg_uint32)-1;
+
+   return (cyg_uint32) (id << 24 | (st.dev & 0xff) << 16 | (st.ino & 0xffff));
+}
+
+const char * cyg_hal_sys_getenv(const char* name)
+{
+   int len, i;
+   const char *np;
+   const char **p;
+   const char *cp;
+
+   if (name == NULL || cyg_hal_sys_environ == NULL)
+      return (NULL);
+   for (np = name; *np && *np != '='; ++np)
+      continue;
+   len = np - name;
+   for (p = cyg_hal_sys_environ; (cp = *p) != NULL; ++p) {
+      for (np = name, i = len; i && *cp; i--)
+         if (*cp++ != *np++)
+            break;
+      if (i == 0 && *cp++ == '=') {
+         return (cp);
+      }
+   }
+   return (NULL);
+}
+

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