<div dir="auto">Okay! So first let me check what files are updated till now.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 8 Jun, 2019, 1:00 AM Gedare Bloom, <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I wouldn't send the patch, I would suggest you write an email to<br>
discuss about how you are porting ndbm, and that the current version<br>
relies on the search/hash functions, and that the interface has<br>
changed a bit over time so inquire whether you should update<br>
hash/search functions to newer versions. This should reduce the<br>
number of changes you have to make to the ndbm files to get them to<br>
work.<br>
<br>
On Fri, Jun 7, 2019 at 11:24 AM Vaibhav Gupta <<a href="mailto:vaibhavgupta40@gmail.com" target="_blank" rel="noreferrer">vaibhavgupta40@gmail.com</a>> wrote:<br>
><br>
> Sure! I will send the patch to newlib and ask them if they need updated set of files inside libc/search.<br>
><br>
> On Fri, 7 Jun, 2019, 10:29 PM Gedare Bloom, <<a href="mailto:gedare@rtems.org" target="_blank" rel="noreferrer">gedare@rtems.org</a>> wrote:<br>
>><br>
>> On Thu, Jun 6, 2019 at 8:02 PM Vaibhav Gupta <<a href="mailto:vaibhavgupta40@gmail.com" target="_blank" rel="noreferrer">vaibhavgupta40@gmail.com</a>> wrote:<br>
>> ><br>
>> > Please review the code so that I can send it to newlib-devel.<br>
>> ><br>
>> > On Fri, Jun 7, 2019 at 7:22 AM Vaibhav Gupta <<a href="mailto:vaibhavgupta40@gmail.com" target="_blank" rel="noreferrer">vaibhavgupta40@gmail.com</a>> wrote:<br>
>> >><br>
>> >> ---<br>
>> >> newlib/libc/include/ndbm.h | 86 ++++++++++++++<br>
>> >> newlib/libc/posix/Makefile.am | 4 +-<br>
>> >> newlib/libc/posix/ndbm.c | 214 ++++++++++++++++++++++++++++++++++<br>
>> >> 3 files changed, 302 insertions(+), 2 deletions(-)<br>
>> >> create mode 100644 newlib/libc/include/ndbm.h<br>
>> >> create mode 100644 newlib/libc/posix/ndbm.c<br>
>> >><br>
>> >> diff --git a/newlib/libc/include/ndbm.h b/newlib/libc/include/ndbm.h<br>
>> >> new file mode 100644<br>
>> >> index 000000000..1fd5e5198<br>
>> >> --- /dev/null<br>
>> >> +++ b/newlib/libc/include/ndbm.h<br>
>> >> @@ -0,0 +1,86 @@<br>
>> >> +/*-<br>
>> >> + * SPDX-License-Identifier: BSD-3-Clause<br>
>> >> + *<br>
>> >> + * Copyright (c) 1990, 1993<br>
>> >> + * The Regents of the University of California. All rights reserved.<br>
>> >> + *<br>
>> >> + * This code is derived from software contributed to Berkeley by<br>
>> >> + * Margo Seltzer.<br>
>> >> + *<br>
>> >> + * Redistribution and use in source and binary forms, with or without<br>
>> >> + * modification, are permitted provided that the following conditions<br>
>> >> + * are met:<br>
>> >> + * 1. Redistributions of source code must retain the above copyright<br>
>> >> + * notice, this list of conditions and the following disclaimer.<br>
>> >> + * 2. Redistributions in binary form must reproduce the above copyright<br>
>> >> + * notice, this list of conditions and the following disclaimer in the<br>
>> >> + * documentation and/or other materials provided with the distribution.<br>
>> >> + * 3. Neither the name of the University nor the names of its contributors<br>
>> >> + * may be used to endorse or promote products derived from this software<br>
>> >> + * without specific prior written permission.<br>
>> >> + *<br>
>> >> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND<br>
>> >> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
>> >> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
>> >> + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE<br>
>> >> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>
>> >> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>
>> >> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>
>> >> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>
>> >> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>
>> >> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>
>> >> + * SUCH DAMAGE.<br>
>> >> + *<br>
>> >> + * @(#)ndbm.h 8.1 (Berkeley) 6/2/93<br>
>> >> + * $FreeBSD$<br>
>> >> + */<br>
>> >> +<br>
>> >> +#ifndef _NDBM_H_<br>
>> >> +#define _NDBM_H_<br>
>> >> +<br>
>> >> +#ifndef __DBINTERFACE_PRIVATE<br>
>> >> +#define __DBINTERFACE_PRIVATE<br>
>> >> +#endif<br>
>> ><br>
>> > Included the above lines in ndbm.h, since __hash_open was under conditional compilation in db_local.h . Line 211 (<a href="https://github.com/VARoDeK/newlib/blob/master/newlib/libc/search/db_local.h" rel="noreferrer noreferrer" target="_blank">https://github.com/VARoDeK/newlib/blob/master/newlib/libc/search/db_local.h</a> ).<br>
>> >><br>
>> >> +<br>
>> >> +#include <db_local.h><br>
>> >> +<br>
>> >> +/* Map dbm interface onto db(3). */<br>
>> >> +#define DBM_RDONLY O_RDONLY<br>
>> >> +<br>
>> >> +/* Flags to dbm_store(). */<br>
>> >> +#define DBM_INSERT 0<br>
>> >> +#define DBM_REPLACE 1<br>
>> >> +<br>
>> >> +/*<br>
>> >> + * The db(3) support for ndbm always appends this suffix to the<br>
>> >> + * file name to avoid overwriting the user's original database.<br>
>> >> + */<br>
>> >> +#define DBM_SUFFIX ".db"<br>
>> >> +<br>
>> >> +typedef struct {<br>
>> >> + void *dptr;<br>
>> >> + int dsize; /* XXX Should be size_t according to 1003.1-2008. */<br>
>> >> +} datum;<br>
>> >> +<br>
>> >> +typedef DB DBM;<br>
>> >> +#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE<br>
>> >> +<br>
>> >> +__BEGIN_DECLS<br>
>> >> +int dbm_clearerr(DBM *);<br>
>> >> +void dbm_close(DBM *);<br>
>> >> +int dbm_delete(DBM *, datum);<br>
>> >> +int dbm_error(DBM *);<br>
>> >> +datum dbm_fetch(DBM *, datum);<br>
>> >> +datum dbm_firstkey(DBM *);<br>
>> >> +#if __BSD_VISIBLE<br>
>> >> +long dbm_forder(DBM *, datum);<br>
>> >> +#endif<br>
>> >> +datum dbm_nextkey(DBM *);<br>
>> >> +DBM *dbm_open(const char *, int, mode_t);<br>
>> >> +int dbm_store(DBM *, datum, datum, int);<br>
>> >> +#if __BSD_VISIBLE<br>
>> >> +int dbm_dirfno(DBM *);<br>
>> >> +#endif<br>
>> >> +__END_DECLS<br>
>> >> +<br>
>> >> +#endif /* !_NDBM_H_ */<br>
>> >> diff --git a/newlib/libc/posix/Makefile.am b/newlib/libc/posix/Makefile.am<br>
>> >> index 6cdee1df0..01334c7fa 100644<br>
>> >> --- a/newlib/libc/posix/Makefile.am<br>
>> >> +++ b/newlib/libc/posix/Makefile.am<br>
>> >> @@ -2,12 +2,12 @@<br>
>> >><br>
>> >> AUTOMAKE_OPTIONS = cygnus<br>
>> >><br>
>> >> -INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)<br>
>> >> +INCLUDES = -I$(srcdir)/../search $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)<br>
>> >><br>
>> >> GENERAL_SOURCES = \<br>
>> >> closedir.c collate.c collcmp.c creat.c dirfd.c \<br>
>> >> fnmatch.c glob.c _isatty.c isatty.c \<br>
>> >> - opendir.c readdir.c readdir_r.c \<br>
>> >> + ndbm.c opendir.c readdir.c readdir_r.c \<br>
>> >> regcomp.c regerror.c regexec.c regfree.c \<br>
>> >> rewinddir.c sleep.c usleep.c \<br>
>> >> telldir.c<br>
>> >> diff --git a/newlib/libc/posix/ndbm.c b/newlib/libc/posix/ndbm.c<br>
>> >> new file mode 100644<br>
>> >> index 000000000..63e54df37<br>
>> >> --- /dev/null<br>
>> >> +++ b/newlib/libc/posix/ndbm.c<br>
>> >> @@ -0,0 +1,214 @@<br>
>> >> +/*-<br>
>> >> + * SPDX-License-Identifier: BSD-3-Clause<br>
>> >> + *<br>
>> >> + * Copyright (c) 1990, 1993<br>
>> >> + * The Regents of the University of California. All rights reserved.<br>
>> >> + *<br>
>> >> + * This code is derived from software contributed to Berkeley by<br>
>> >> + * Margo Seltzer.<br>
>> >> + *<br>
>> >> + * Redistribution and use in source and binary forms, with or without<br>
>> >> + * modification, are permitted provided that the following conditions<br>
>> >> + * are met:<br>
>> >> + * 1. Redistributions of source code must retain the above copyright<br>
>> >> + * notice, this list of conditions and the following disclaimer.<br>
>> >> + * 2. Redistributions in binary form must reproduce the above copyright<br>
>> >> + * notice, this list of conditions and the following disclaimer in the<br>
>> >> + * documentation and/or other materials provided with the distribution.<br>
>> >> + * 3. Neither the name of the University nor the names of its contributors<br>
>> >> + * may be used to endorse or promote products derived from this software<br>
>> >> + * without specific prior written permission.<br>
>> >> + *<br>
>> >> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND<br>
>> >> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
>> >> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
>> >> + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE<br>
>> >> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>
>> >> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>
>> >> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>
>> >> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>
>> >> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>
>> >> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>
>> >> + * SUCH DAMAGE.<br>
>> >> + */<br>
>> >> +<br>
>> >> +#if defined(LIBC_SCCS) && !defined(lint)<br>
>> >> +static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94";<br>
>> >> +#endif /* LIBC_SCCS and not lint */<br>
>> >> +#include <sys/cdefs.h><br>
>> >> +__FBSDID("$FreeBSD$");<br>
>> >> +<br>
>> >> +/*<br>
>> >> + * This package provides a dbm compatible interface to the new hashing<br>
>> >> + * package described in db(3).<br>
>> >> + */<br>
>> >> +<br>
>> >> +#include <sys/param.h><br>
>> >> +<br>
>> >> +#include <stdio.h><br>
>> >> +#include <string.h><br>
>> >> +#include <errno.h><br>
>> >> +<br>
>> >> +#include <ndbm.h><br>
>> >> +#include <hash.h><br>
>> >> +<br>
>> >> +/*<br>
>> >> + * Returns:<br>
>> >> + * *DBM on success<br>
>> >> + * NULL on failure<br>
>> >> + */<br>
>> >> +extern DBM *<br>
>> >> +dbm_open(const char *file, int flags, mode_t mode)<br>
>> >> +{<br>
>> >> + HASHINFO info;<br>
>> >> + char path[MAXPATHLEN];<br>
>> >> +<br>
>> >> + info.bsize = 4096;<br>
>> >> + info.ffactor = 40;<br>
>> >> + info.nelem = 1;<br>
>> >> + info.cachesize = 0;<br>
>> >> + info.hash = NULL;<br>
>> >> + info.lorder = 0;<br>
>> >> +<br>
>> >> + if( strlen(file) >= sizeof(path) - strlen(DBM_SUFFIX)) {<br>
>> >> + errno = ENAMETOOLONG;<br>
>> >> + return(NULL);<br>
>> >> + }<br>
>> >> + (void)strcpy(path, file);<br>
>> >> + (void)strcat(path, DBM_SUFFIX);<br>
>> >> + return ((DBM *)__hash_open(path, flags, mode, 0, &info));<br>
>> ><br>
>> > In ndbm.c,<br>
>> > The original code was: return ((DBM *)__hash_open(path, flags, mode, &info, 0));<br>
>> > But the declaration of this function in db_local.h is: __hash_open(const char *, int, int, int, const HASHINFO *);<br>
>> > hence changed the original code to: return ((DBM *)__hash_open(path, flags, mode, 0, &info));<br>
>> ><br>
>><br>
>> Should db_local.h be updated? how about hash.h? Maybe, the entire<br>
>> search.h should be updated to newer FreeBSD sources? This is probably<br>
>> something to discuss at newlib ML...<br>
>><br>
>> >><br>
>> >> +}<br>
>> >> +<br>
>> >> +extern void<br>
>> >> +dbm_close(DBM *db)<br>
>> >> +{<br>
>> >> + (void)(db->close)(db);<br>
>> >> +}<br>
>> >> +<br>
>> >> +/*<br>
>> >> + * Returns:<br>
>> >> + * DATUM on success<br>
>> >> + * NULL on failure<br>
>> >> + */<br>
>> >> +extern datum<br>
>> >> +dbm_fetch(DBM *db, datum key)<br>
>> >> +{<br>
>> >> + datum retdata;<br>
>> >> + int status;<br>
>> >> + DBT dbtkey, dbtretdata;<br>
>> >> +<br>
>> >> + dbtkey.data = key.dptr;<br>
>> >> + dbtkey.size = key.dsize;<br>
>> >> + status = (db->get)(db, &dbtkey, &dbtretdata, 0);<br>
>> >> + if (status) {<br>
>> >> + dbtretdata.data = NULL;<br>
>> >> + dbtretdata.size = 0;<br>
>> >> + }<br>
>> >> + retdata.dptr = dbtretdata.data;<br>
>> >> + retdata.dsize = dbtretdata.size;<br>
>> >> + return (retdata);<br>
>> >> +}<br>
>> >> +<br>
>> >> +/*<br>
>> >> + * Returns:<br>
>> >> + * DATUM on success<br>
>> >> + * NULL on failure<br>
>> >> + */<br>
>> >> +extern datum<br>
>> >> +dbm_firstkey(DBM *db)<br>
>> >> +{<br>
>> >> + int status;<br>
>> >> + datum retkey;<br>
>> >> + DBT dbtretkey, dbtretdata;<br>
>> >> +<br>
>> >> + status = (db->seq)(db, &dbtretkey, &dbtretdata, R_FIRST);<br>
>> >> + if (status)<br>
>> >> + dbtretkey.data = NULL;<br>
>> >> + retkey.dptr = dbtretkey.data;<br>
>> >> + retkey.dsize = dbtretkey.size;<br>
>> >> + return (retkey);<br>
>> >> +}<br>
>> >> +<br>
>> >> +/*<br>
>> >> + * Returns:<br>
>> >> + * DATUM on success<br>
>> >> + * NULL on failure<br>
>> >> + */<br>
>> >> +extern datum<br>
>> >> +dbm_nextkey(DBM *db)<br>
>> >> +{<br>
>> >> + int status;<br>
>> >> + datum retkey;<br>
>> >> + DBT dbtretkey, dbtretdata;<br>
>> >> +<br>
>> >> + status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT);<br>
>> >> + if (status)<br>
>> >> + dbtretkey.data = NULL;<br>
>> >> + retkey.dptr = dbtretkey.data;<br>
>> >> + retkey.dsize = dbtretkey.size;<br>
>> >> + return (retkey);<br>
>> >> +}<br>
>> >> +<br>
>> >> +/*<br>
>> >> + * Returns:<br>
>> >> + * 0 on success<br>
>> >> + * <0 failure<br>
>> >> + */<br>
>> >> +extern int<br>
>> >> +dbm_delete(DBM *db, datum key)<br>
>> >> +{<br>
>> >> + int status;<br>
>> >> + DBT dbtkey;<br>
>> >> +<br>
>> >> + dbtkey.data = key.dptr;<br>
>> >> + dbtkey.size = key.dsize;<br>
>> >> + status = (db->del)(db, &dbtkey, 0);<br>
>> >> + if (status)<br>
>> >> + return (-1);<br>
>> >> + else<br>
>> >> + return (0);<br>
>> >> +}<br>
>> >> +<br>
>> >> +/*<br>
>> >> + * Returns:<br>
>> >> + * 0 on success<br>
>> >> + * <0 failure<br>
>> >> + * 1 if DBM_INSERT and entry exists<br>
>> >> + */<br>
>> >> +extern int<br>
>> >> +dbm_store(DBM *db, datum key, datum data, int flags)<br>
>> >> +{<br>
>> >> + DBT dbtkey, dbtdata;<br>
>> >> +<br>
>> >> + dbtkey.data = key.dptr;<br>
>> >> + dbtkey.size = key.dsize;<br>
>> >> + dbtdata.data = data.dptr;<br>
>> >> + dbtdata.size = data.dsize;<br>
>> >> + return ((db->put)(db, &dbtkey, &dbtdata,<br>
>> >> + (flags == DBM_INSERT) ? R_NOOVERWRITE : 0));<br>
>> >> +}<br>
>> >> +<br>
>> >> +extern int<br>
>> >> +dbm_error(DBM *db)<br>
>> >> +{<br>
>> >> + HTAB *hp;<br>
>> >> +<br>
>> >> + hp = (HTAB *)db->internal;<br>
>> >> + return (hp->error);<br>
>> >> +}<br>
>> >> +<br>
>> >> +extern int<br>
>> >> +dbm_clearerr(DBM *db)<br>
>> >> +{<br>
>> >> + HTAB *hp;<br>
>> >> +<br>
>> >> + hp = (HTAB *)db->internal;<br>
>> >> + hp->error = 0;<br>
>> >> + return (0);<br>
>> >> +}<br>
>> >> +<br>
>> >> +extern int<br>
>> >> +dbm_dirfno(DBM *db)<br>
>> >> +{<br>
>> >> + return(((HTAB *)db->internal)->fp);<br>
>> >> +}<br>
>> >> --<br>
>> >> 2.21.0<br>
>> >><br>
>> > _______________________________________________<br>
>> > devel mailing list<br>
>> > <a href="mailto:devel@rtems.org" target="_blank" rel="noreferrer">devel@rtems.org</a><br>
>> > <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>