[comp.sys.hp] tell

erc@pai.UUCP (Eric Johnson) (07/26/90)

We've just got an HP 800 (834?) in house, and I've been porting our
industrial automation software to it. We're running HP-UX 7.0. The
only difference between the 800 series HP-UX 7.0 and the 300 series
is that tell() does not appear to be available on the 800. Is this 
correct? (We're much more familiar with the 300 line.)

tell() returns a long int that "tells" where you are in a file, sort
of like the analog to ftell() if you use open() instead of fopen().

Below is my hack for a tell() replacement. Do you see any problems
with this approach? I'm basically doing a seek zero bytes from the
current position (which I hope should still be the current position).


#ifndef SEEK_CUR
#define SEEK_CUR        1
#endif  /* -- SEEK_CUR */


long etell( fd )

int     fd;

{       /* -- function etell */

        return( lseek( fd, 0, SEEK_CUR ) );

}       /* -- function etell */


Are there any other "gotchas" on the 800 series that we should be
aware of?  So far, I haven't had any real problems migrating to
the 800, and I like HP-UX 7.0 much better than any previous HP
operating system--they seem to have come a long way in the last
few years.

Thanks,
-Eric

-- 
Eric F. Johnson               phone: +1 612 894 0313    BTI: Industrial
Boulware Technologies, Inc.   fax:   +1 612 894 0316    automation systems
415 W. Travelers Trail        email: erc@pai.mn.org     and services
Burnsville, MN 55337 USA

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

>The only difference between the 800 series HP-UX 7.0 and the 300 series
>is that tell() does not appear to be available on the 800.

If true, that'd be pretty bizarre; "tell()" came with V7, and comes with
4.3BSD and S5R3....

>Below is my hack for a tell() replacement. Do you see any problems
>with this approach?

It's almost exactly the same code (modulo formatting and the use of SEEK_CUR
rather than 1) that's in the "tell()" in 4.3BSD and S5.  The only
difference is that they use 0L rather than 0 as the second argument.

rer@hpfcdc.HP.COM (Rob Robason) (08/07/90)

Eric Johnson writes:

eric> We've just got an HP 800 (834?)  in house, and I've been porting
eric> our industrial automation software to it.  We're running HP-UX
eric> 7.0.  The only difference between the 800 series HP-UX 7.0 and
eric> the 300 series is that tell() does not appear to be available on
eric> the 800.  Is this correct?  (We're much more familiar with the
eric> 300 line.)

I need to know the history of tell().  I cannot find it in the AT&T, BSD
or HP-UX references.  Would you tell me how you knew about it in order to
use it in your original application?  You have indeed used it correctly,
I'm just trying to figure out how!

We have tentatively added tell to libc for the 800 for compatibility.
You will not see this until 8.0.

I would make the suggestion that you change your code to use

	lseek(fildes, SEEK_CUR, (off_t)0)

This returns the same value as tell(except the type is off_t instead of
int), works in 7.0 and is POSIX conformant.  This will make your code
its most portable.

As an aside, since it came too late to influence the application we're
discussing, a new feature of the HP-UX reference (added in 7.0, I think)
is the STANDARDS CONFORMANCE section which describes applicable
standards for each function.  This can be a useful guide to writing
portable software.

Rob Robason

guy@auspex.auspex.com (Guy Harris) (08/08/90)

>I need to know the history of tell().  I cannot find it in the AT&T, BSD
>or HP-UX references.  Would you tell me how you knew about it in order to
>use it in your original application?  You have indeed used it correctly,
>I'm just trying to figure out how!

I can't speak for the original poster, but *I* first knew about "tell()"
when it showed up in what you might call a "post-V6" V6 release - two of
them, actually, PWB/UNIX 1.0 and the "50 changes to UNIX" stuff, which
was a set of "diff"s or somesuch sent out by Ken Thomson that changed a
bunch of stuff in the kernel (and maybe elsewhere).  V6 had "seek()"
(don't ask) but not "tell()", so you could set the seek pointer but you
couldn't find out where it was; "tell()" was subsequently added, showed
up in the "50 changes" and in PWB 1.0.

I think when "lseek()" showed up as a library routine atop "seek()", it
also used "tell()" and returned the new value of the seek pointer, but
it's been so long since I had anything to do with V6-vintage systems, so
this may not be correct.  In any case, by V7 "lseek()" was the official
interface for both the functionality of "seek()" (which was gone in V7,
its system call number being given to "lseek()") and "tell()".

>I would make the suggestion that you change your code to use
>
>	lseek(fildes, SEEK_CUR, (off_t)0)

I'll second, third, and fourth that suggestion; "tell()" is really
crufty and old and obsolete, and not in all systems (as has been
demonstrated), and not in POSIX or the SVID or any of the other
standards, so you shouldn't use it.

rer@hpfcdc.HP.COM (Rob Robason) (08/09/90)

> I would make the suggestion that you change your code to use
> 	lseek(fildes, SEEK_CUR, (off_t)0)

Eric points out to me via email that this should be:

	lseek(fildes, (off_t)0, SEEK_CUR)

And he is right, sorry for the booboo.

Rob