<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 21, 2019 at 11:38 PM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, Jun 21, 2019 at 11:03 AM Vaibhav Gupta <<a href="mailto:vaibhavgupta40@gmail.com" target="_blank">vaibhavgupta40@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Fri, Jun 21, 2019, 9:46 PM Gedare Bloom <<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>> wrote:<br>
>><br>
>> On Fri, Jun 21, 2019 at 4:25 AM Vaibhav Gupta <<a href="mailto:vaibhavgupta40@gmail.com" target="_blank">vaibhavgupta40@gmail.com</a>> wrote:<br>
>> ><br>
>> > Hello Gedare,<br>
>> > As you suggested, I have placed nbm.c in libc/search directory. This directory contains hash.h, db_local.h, hash.c. And all these are required by ndbm.<br>
>> > .<br>
>> > Here newlib got successfully compiled and It was generating function symbols.<br>
>> > .<br>
>> > After that when i added the patch to RSB, and tried to compile a test to check if ndbm is ported successfully or not.<br>
>> > It gave me error:<br>
>> > ........<br>
>> > ........<br>
>> > mv -f fileio/.deps/fileio-init.Tpo fileio/.deps/fileio-init.Po<br>
>> > sparc-rtems5-gcc -DHAVE_CONFIG_H -I. -I/home/varodek/development/rtems/kernel/rtems/c/src/../../testsuites/samples -I. -I/home/varodek/development/rtems/kernel/erc32/sparc-rtems5/c/erc32/include -I/home/varodek/development/rtems/kernel/rtems/cpukit/include -I/home/varodek/development/rtems/kernel/rtems/cpukit/score/cpu/sparc/include -I/home/varodek/development/rtems/kernel/erc32/sparc-rtems5/c/erc32/lib/libbsp/sparc/erc32/include -I/home/varodek/development/rtems/kernel/rtems/bsps/include -I/home/varodek/development/rtems/kernel/rtems/bsps/sparc/include -I/home/varodek/development/rtems/kernel/rtems/bsps/sparc/erc32/include -DT_FILE_NAME='"init.c"' -I/home/varodek/development/rtems/kernel/rtems/c/src/../../testsuites/samples/../support/include -mcpu=cypress -O2 -g -ffunction-sections -fdata-sections -Wall -Wmissing-prototypes -Wimplicit-function-declaration -Wstrict-prototypes -Wnested-externs -MT hello/hello-init.o -MD -MP -MF hello/.deps/hello-init.Tpo -c -o hello/hello-init.o `test -f 'hello/init.c' || echo '/home/varodek/development/rtems/kernel/rtems/c/src/../../testsuites/samples/'`hello/init.c<br>
>> > In file included from /home/varodek/development/rtems/kernel/rtems/c/src/../../testsuites/samples/hello/init.c:17:0:<br>
>> > /home/varodek/development/rtems/5/sparc-rtems5/include/ndbm.h:43:10: fatal error: db_local.h: No such file or directory<br>
>> > #include <db_local.h><br>
>> > ^~~~~~~~~~~~<br>
>> ><br>
>> > .<br>
>> > I found that db_local.h is not present in rtems/5 directory.<br>
>> ><br>
>><br>
>> I suspect that the headers in search/ are not installed, they are only<br>
>> to be included during compilation of newlib, and probably should be<br>
>> included by #include "db_local.h" for example. I also find it likely<br>
><br>
> ndbm.h is in libc/include, db_local.h is in libc/search.<br>
> I will have to use #include"../search/db_local.h" which itself is a very bad way to do so.<br>
<br>
Definitely shouldn't do that.<br>
<br>
>><br>
>> that you should not be including these non-installed headers from<br>
>> installed headers inside of libc/include.<br>
>><br>
>> So, you might need to rewrite the ndbm.h so that it does not rely on<br>
>> some internal headers of newlib.... Just my two cents. Not sure if I'm<br>
>> right. :)<br>
><br>
> I can do one thing. db_local.h contains some data structures. Also it contains some function declarations, definitions of which are present in hash.h.<br>
>.<br>
> So i can put those declarations and data structures directly in ndbm.h, so won't need to call db_local.h<br>
><br>
<br>
It would be better if you can remove anything requiring db_local.h<br>
from ndbm.h so that you don't have to #include db_local.h. You could<br>
put those things into maybe db_local.h, or into some new file like<br>
search/ndbm_local.h or something. you might need some guidance from<br>
newlib maintainers about what is the right way to split the<br>
public/private sides of headers like this.<br></blockquote><div>Actually ndbm.h has declarations of database functions. And all of them require a data-type (structure)<br></div><div>defined in db_local.h . So there is nothing in ndbm.h which I can shift to db_local.h</div><div>or ndbm_local.h . If I transfer anything, ndbm.h will lose its meaning.<br></div><div>.</div><div>Okay I will ask in newlib. Haven't got reply from them for my previous mail though.<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
The basic idea is, how to make it so that #include <ndbm.h> doesn't<br>
need to include db_local.h? Instead, you can modify ndbm.c to do<br>
something lilke #include "db_local.h" and #include "ndbm_local.h"<br>
itself. This way, the ndbm.h header file does not need to "leak" the<br>
details of db_local.h to userland.<br>
<br>
Gedare<br>
.<br>
> Will this be practical?<br>
>><br>
>><br>
>><br>
>> > Thank you<br>
>> > Vaibhav Gupta<br>
>> ><br>
>> > On Fri, Jun 21, 2019 at 1:57 AM Vaibhav Gupta <<a href="mailto:vaibhavgupta40@gmail.com" target="_blank">vaibhavgupta40@gmail.com</a>> wrote:<br>
>> >><br>
>> >> ---<br>
>> >> newlib/libc/include/ndbm.h | 84 +++++++++++++<br>
>> >> newlib/libc/search/Makefile.am | 1 +<br>
>> >> newlib/libc/search/ndbm.c | 214 +++++++++++++++++++++++++++++++++<br>
>> >> 3 files changed, 299 insertions(+)<br>
>> >> create mode 100644 newlib/libc/include/ndbm.h<br>
>> >> create mode 100644 newlib/libc/search/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..f89f97dd0<br>
>> >> --- /dev/null<br>
>> >> +++ b/newlib/libc/include/ndbm.h<br>
>> >> @@ -0,0 +1,84 @@<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>
>> >> +#define __DBINTERFACE_PRIVATE<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/search/Makefile.am b/newlib/libc/search/Makefile.am<br>
>> >> index 98920c3f4..a61107fb9 100644<br>
>> >> --- a/newlib/libc/search/Makefile.am<br>
>> >> +++ b/newlib/libc/search/Makefile.am<br>
>> >> @@ -9,6 +9,7 @@ GENERAL_SOURCES = \<br>
>> >> db_local.h \<br>
>> >> extern.h \<br>
>> >> hash.h \<br>
>> >> + ndbm.c \<br>
>> >> page.h \<br>
>> >> qsort.c<br>
>> >><br>
>> >> diff --git a/newlib/libc/search/ndbm.c b/newlib/libc/search/ndbm.c<br>
>> >> new file mode 100644<br>
>> >> index 000000000..bd9c71e4f<br>
>> >> --- /dev/null<br>
>> >> +++ b/newlib/libc/search/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>
>> >> +<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>
</blockquote></div></div>