[comp.sys.hp] name clash in PW library in HP-UX 6.2

jv@mhres.mh.nl (Johan Vromans) (01/31/89)

A program using the "rename" system call gets problems when
linked with -lPW:

  $ cat t.c
  main () {
      rename(0,0);
  }
  $ cc t.c
  $ cc t.c -lPW
  ld: Undefined external -
          _Error
  ld: output file still contains undefined symbols
  ld: (Warning) did not generate an output file


-- 
Johan Vromans			 jv@mh.nl via european backbone (mcvax)
Multihouse [A-Za-z ]* [NB]V			uucp: ..!mcvax!mh.nl!jv
Gouda - The Netherlands				  phone: +31 1820 62944

marc@hpfcdc.HP.COM (Marc 'Sphere' Sabatella) (02/03/89)

/ hpfcdc:comp.sys.hp / jv@mhres.mh.nl (Johan Vromans) /  6:34 am  Jan 31, 1989 /

>A program using the "rename" system call gets problems when
>linked with -lPW:
>...
>  $ cc t.c -lPW
>  ld: Undefined external -
>          _Error

To be honest, I do not know what libPW.a is, but a little poking around and
disassebly turned up a few things:

"libPW.a" defines its own version of 'rename', which seems to do basically
the same thing as the regular 'rename'.  One difference is that some of the
internal libPW.a routines called by 'rename' use a string variable called
"Error" to construct error messages, as in

	if (link(p1,p2))
	{
		sprintf(Error,"can't link `(%s)' to `(%s)' (%d)",p2,p1,0x70);
		fatal(Error);
	}

Error does not seem to be defined anywhere in libPW.a; but if this is your
only problem with libPW, you could try declaring

char Error[80];

somewhere in your program.

--------------
Marc Sabatella
HP Colorado Language Lab
marc%hpfcrt@hplabs.hp.com

bd@hp-ses.SDE.HP.COM (Bob Desinger) (02/04/89)

Johan Vromans (jv@mhres.mh.nl) writes:
> A program using the "rename" system call gets problems when
> linked with -lPW:
>   $ cc t.c -lPW
>   ld: Undefined external -
>           _Error

I get that on my 6.2 s300, too, when I link with -lPW.  But when I
don't use -lPW, I get the libc version of rename() that successfully
links.  Can you use that instead?  (If you need other routines from
the PWB, you may need to use "-lc -lPW" flags for the linker.)

A look at some older HP-UX code for another architecture shows that
the libc version is a real system call instead of a library call; it's
a stub that jumps to the kernel routine.  In this older code, the
libPW version of rename() calls two other libPW routines, xlink() and
xunlink().  xlink() declares Error as an extern char buffer, used by
sprintf() and another call, no doubt for temporary storage to hold the
formatted error message.

I have never looked at any s300 source code, much less the 6.2
version, so I don't know if it's similar.

I was hoping to find some magic linker flags or #include files
mentioned on the PWB man page, but I couldn't find any man pages for
PWB entry points on either the 300 or 800.  Or, for that matter, in
4.3BSD or the SVID or even the Lapin book on "Portable C and Unix
System Programming."  I suppose I shouldn't be surprised; PWB was an
internal Bell Labs thing, according to Lapin.

Grepping through /usr/include/*.h and /usr/include/sys/*.h turns up
two useful references to Error on the s300:

	/usr/include/macros.h:extern char       Error[128];
	/usr/include/oldmacros.h:char   Error[128];

You definitely want <oldmacros.h> here.  By the way, <oldmacros.h>
doesn't appear on the s800---and you'll get the same error message if
you use -lPW without -lc there, too.  So if you can possibly switch to
the kernel version in libc, do it for greater portability.

-- bd

guy@auspex.UUCP (Guy Harris) (02/05/89)

>A look at some older HP-UX code for another architecture shows that
>the libc version is a real system call instead of a library call; it's
>a stub that jumps to the kernel routine.

The kernel routine most likely has two other advantages:

	1) it allows non-super-users to rename directories

	2) it works over NFS to servers that don't allow you to create
	   multiple links to files

and it is also allegedly atomic, or at least mostly atomic.  To quote
from the comment that appears (perhaps with minor typographical changes)
in various flavors of UNIX:

 * ...The essential operation is:
 *	unlink(target);
 *	link(source, target);
 *	unlink(source);
 * but "atomically".  Can't do full commit without saving state in the inode
 * on disk, which isn't feasible at this time.  Best we can do is always
 * guarantee that the TARGET exists.

>... but I couldn't find any man pages for PWB entry points...  I
>suppose I shouldn't be surprised; PWB was an internal Bell Labs thing,
>according to Lapin.

Sort of internal.  PWB/UNIX 1.0 actually was released; it was based on
V6 UNIX, mostly (although with later versions of kernel, C compiler,
some library routines, etc. and standard I/O, most of which came out of
Research in various forms as well).  I think there may even have been a
document for the routines in the "-lPW" library; said documentation had
disappeared by the time S3 came out, though.

>So if you can possibly switch to the kernel version in libc, do it for
>greater portability.

Definitely.  Not all flavors of UNIX have "-lPW", and it may even
disappear from AT&T's releases someday....  (And yes, "rename" will be
in S5R4; it's already in the POSIX spec.)

jv@mhres.mh.nl (Johan Vromans) (02/05/89)

To all people (mostly HP representatives) who replied to my name
clash problem: thanks a lot!

The application (the alpha test version of smail3.1) uses 
the regex/regcmp routines from libPW.a . So I extracted them
from libPW.a and added them to the application's objects.
Easy and effective.
-- 
Johan Vromans			 jv@mh.nl via european backbone (mcvax)
Multihouse [A-Za-z ]* [NB]V			uucp: ..!mcvax!mh.nl!jv
Gouda - The Netherlands				  phone: +31 1820 62944