Recent change to Xprint/attributes.c breaks build

Glynn Clements glynn at gclements.plus.com
Tue May 3 14:13:16 PDT 2005


Adam Jackson wrote:

> > > pread() is Unix98, not POSIX.
> > >
> > > It's perfectly possible to emulate pread:
> > >
> > > off_t saved = lseek(fd, 0, SEEK_CUR);
> > > lseek(fd, offset, SEEK_SET);
> > > read(fd, buf, count);
> > > lseek(fd, saved, SEEK_SET);
> > >
> > > Granted it's a few more system calls and it's not reentrant, but it
> > > works.  I would suggest that we add this to os-support/, since it's easy
> > > to emulate and part of a relatively well-adopted standard.
> >
> > And to make it re-entrant-ish you could add a few more calls around the
> > above code to lock byte 0 of the file while you're doing the pread()
> > to ensure that another process (not thread) doesn't come behind you
> > and change the offset.
> 
> I thought fd state was per-process and not global.

No; if a descriptor is duplicated, either explicitly by dup() etc or
implicitly by fork(), all copies share the same offset.

The only way to get multiple descriptors for a given file which don't
share offsets is to open() the file multiple times.

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list