[comp.sys.hp] BSD rindex, etc.

jdunlap@milton.u.washington.edu (John Dunlap) (09/27/90)

Some time ago, I recall a discussion about the BSD string functions
being available in HP-UX.  I am looking for rindex and strings.h
among other things.  I would like to have easier porting of BSD
applications to HP-UX.

John Dunlap
dunlap@apl.washington.edu

mat@emcard.UUCP (W Mat Waites) (09/27/90)

In article <8155@milton.u.washington.edu> jdunlap@milton.u.washington.edu (John Dunlap) writes:
<Some time ago, I recall a discussion about the BSD string functions
<being available in HP-UX.  I am looking for rindex and strings.h
<among other things.  I would like to have easier porting of BSD
<applications to HP-UX.
<
<John Dunlap
<dunlap@apl.washington.edu

Link with -lBSD for index and rindex, etc. For strings.h, compile with
-Dstrings.h=string.h or create a link in /usr/include called strings.h
to string.h.

Good luck,

Mat



-- 
W Mat Waites              |  Unlike most of you, I am not a nut.
{gatech,emory}!emcard!mat |             -H. Simpson

jad@hpcndnm.cnd.hp.com (John Dilley) (09/27/90)

In article <8155@milton.u.washington.edu> jdunlap@milton.u.washington.edu (John Dunlap) writes:

>Some time ago, I recall a discussion about the BSD string functions
>being available in HP-UX.  I am looking for rindex and strings.h
>among other things.  I would like to have easier porting of BSD
>applications to HP-UX.

	In HP-UX there is a library, libBSD.a, which helps with porting
by providing many Berkeley compatibility functions.  The functions found
in this library are listed below for your reference.  This will not help
you with include files whose names or contents are different between
HP-UX and other flavors of UNIX -- my suggestion is you use #ifdef to
differentiate between the various flavors as follows:

#ifdef	hpux
#include	<string.h>
#else	/* BSD */
#include	<strings.h>
#endif

	You might be better off using symbols other than hpux for
portability.  Be aware that linking in this routines may cause your
application to behave differently by redefining signal().  You should
also be aware that there are differences between bcopy()/bzero() and
memcpy()/memset().  The symbols defined in my libBSD.a file are:

bcmp.o:0x00000000 T  _bcmp
bcopy.o:0x00000000 T  _bcopy
bzero.o:0x00000000 T  _bzero
index.o:0x00000000 T  _index
index.o:0x00000016 T  _rindex
getwd.o:0x00000000 T  _getwd
killpg.o:0x00000000 T  _killpg
signal.o:0x00000000 T  _signal
sigvec.o:0x00000000 T  _sigvec
setpgrp.o:0x00000000 T  _setpgrp
getpgrp.o:0x00000000 T  _getpgrp

This library is in the fileset PROG_SUPL, which I believe is shipped in
the 7.0 release of HP-UX on Series 300 and Series 800 systems.

                          --      jad      --
			      John Dilley
			    Hewlett-Packard
                       Colorado Networks Division
UX-mail:      		     jad@cnd.hp.com
Phone:                       (303) 229-2787
--
This is not an official statement of Hewlett-Packard Corp, and does not 
necessarily reflect the views of HP.  The information above is provided
completely without warranty of any kind.

fred@prisma.cv.ruu.nl (Fred Appelman) (09/27/90)

In <8155@milton.u.washington.edu> jdunlap@milton.u.washington.edu (John Dunlap) writes:

>Some time ago, I recall a discussion about the BSD string functions
>being available in HP-UX.  I am looking for rindex and strings.h
>among other things.  I would like to have easier porting of BSD
>applications to HP-UX.


Are the only function you need, the functions rindex and index?
If so, you can create your 'own' strings.h file, with the following
defintions:

#define index strchr
#define rindex strrchr

In the file /usr/lib/libBSD.a there is a file which contains 'index.o'.
This object file also contains defintions of the functions index and
rindex. To my knowledge there is no include file which defines 
index and rindex.

--
Fred J.R. Appelman, 3D Computer Vision, Utrecht University
AZU, Heidelberglaan 100, 3584 CX Utrecht, The Netherlands.
Telephone: +31-30-506710 Fax: +31-30-513399
e-mail: fred@cv.ruu.nl or appelman@cs.unc.edu

graham@hparc0.HP.COM (Graham Eddy) (09/27/90)

you will want /usr/include/string.h (NOT strings.h) and you'll
probably decide to define a few macros rather than change all that
BSD-dependent source..

for	check out	if i remember this right..
---	---------	--------------------------
index	strchr		#define index		strchr
rindex	strrchr		#define rindex		strrchr
bcopy	memcpy		#define bcopy(s1,s2,n)	memcpy((s2), (s1), n)

-graham "representing only my own opinions"

rodean@hpfcdc.HP.COM (Bruce Rodean) (09/27/90)

In article <8155@milton.u.washington.edu> jdunlap@milton.u.washington.edu (John Dunlap) writes:
> Some time ago, I recall a discussion about the BSD string functions
> being available in HP-UX.  I am looking for rindex and strings.h
> among other things.  I would like to have easier porting of BSD
> applications to HP-UX.

Well there's good news and bad news.  The good news is that [r]index,
bcopy, bzero, bcmp,and str[n]casecmp, along with a <strings.h>, are all
going to be in libc in the next major release of HP-UX.  The bad news is
that doesn't help you for now.

I believe that most people use #define's to map [r]index into str[r]chr.
See string(3c) for the complete list of string functions.

Bruce Rodean
rodean@hpfcla.HP.COM

This posting does not reflect the official position of Hewlett-Packard
Co.  No guarantees of any kind are made or implied.

guy@auspex.auspex.com (Guy Harris) (09/29/90)

>	You might be better off using symbols other than hpux for
>portability.

Yup, given that HP-UX is *not* the only system out there that has
<string.h> but not <strings.h>.

With any luck, as ANSI C and POSIX become more common on UNIX systems, a
lot of this nonsense will go away (ANSI C says the routines are called
"strchr()" and "strrchr()", and the include file is called <string.h>,
so in 4.4BSD Berkeley will hopefully get with the program - preferably
with a "strchr()" implementation that's no slower than "index()", and a
"strrchr()" implementation that's no slower than "rindex()"!)

>Be aware that linking in this routines may cause your application to
>behave differently by redefining signal().

If their application was originally written for a BSD environment, it
may well *want* to behave differently; it may be depending on
4.2andupBSD "signal()" behavior, rather than "traditional" "signal()"
behavior.

rer@hpfcdc.HP.COM (Rob Robason) (10/03/90)

>Be aware that linking in this routines may cause your application to
>behave differently by redefining signal().

> If their application was originally written for a BSD environment, it
> may well *want* to behave differently; it may be depending on
> 4.2andupBSD "signal()" behavior, rather than "traditional" "signal()"
> behavior.

Both good points.  If you don't want to suck in stuff from libBSD.a
that's in libc.a, just do

    cc ... -lc -lBSD -lc

Rob

jimp@cognos.UUCP (Jim Patterson) (10/09/90)

In article <1510008@hparc0.HP.COM> graham@hparc0.HP.COM (Graham Eddy) writes:
>you will want /usr/include/string.h (NOT strings.h) and you'll
>probably decide to define a few macros rather than change all that
>BSD-dependent source..
>
>bcopy	memcpy		#define bcopy(s1,s2,n)	memcpy((s2), (s1), n)

You may have problems with this, since bcopy is guaranteed to handle
overlapping strings properly whereas memcpy isn't. You should use
memmove instead on HP-UX. (memmove will be in any ANSI-C-compliant
library, but isn't on some non-ANSI systems e.g. Sun).


-- 
Jim Patterson                              Cognos Incorporated
UUCP:uunet!mitel!cunews!cognos!jimp        P.O. BOX 9707    
PHONE:(613)738-1440                        3755 Riverside Drive
NOT a Jays fan (not even a fan)            Ottawa, Ont  K1G 3Z4

jwright@cfht.hawaii.edu (Jim Wright) (10/10/90)

graham@hparc0.HP.COM (Graham Eddy) writes:
>#define bcopy(s1,s2,n)	memcpy((s2), (s1), n)

Not quite so easy.  bcopy() is defined so that overlapping strings are
handled correctly.  For memcpy(), if  copying takes place between objects
that overlap, the behavior is undefined.

--
Jim Wright
jwright@cfht.hawaii.edu
Canada-France-Hawaii Telescope Corp.