[comp.sys.sun] drawing to the root window

quasar@ctt.bellcore.com (Laurence R. Brothers) (03/31/89)

I've written a few hacks to draw stuff on the root window (I'm on a
Sun-4/260, OS 4.0, by the way). I open /dev/win0 and then pw_open the fd I
get. I now want to retain the pixwin I'm drawing to so as to automatically
handle damage. I presume the original root pixwin is retained, since it
does in fact handle damage.  I've fiddled with the pw_prretained pixrect
field of the root pixwin without success. I've tried a number of different
tacks, already, so I'd appreciate it if any suggestions anyone makes are
tested first...

As a digression, I should mention that there is approximately a 25%
failure chance for a program whose first two executable lines are:

  root_fd = open("/dev/win0");
  root_pixwin = pw_open(root_fd);

If it doesn't work, either root_fd is set to -1, (error "file already
exists") or pw_open fails to work and returns NULL. Somehow, the success
of a program is dependent on the structure of the rest of the source code
-- i.e., a given source file will either always work, or always not work.
Changing the file may randomly change this state -- any ideas? Giving open
its second argument seems to have no effect on this behavior.

Incidentally, using dbx on one of these programs causes it automatically
to fail to open /dev/win0, returning -1, so it is kind of hard to debug....

	    Laurence R. Brothers (quasar@ctt.bellcore.com)
Bellcore -- Computer Technology Transfer -- Knowledge-Based Systems Development

reg@lti.com (Rick Genter x18) (04/26/89)

> As a digression, I should mention that there is approximately a 25%
> failure chance for a program whose first two executable lines are:

>   root_fd = open("/dev/win0");
>   root_pixwin = pw_open(root_fd);


If these are the two lines verbatim, then no kidding it fails at random.
open(2) takes 2 or 3 arguments, but never 1.  You want to do:

	root_fd = open("/dev/win0",O_RDONLY);

as it is, you're passing garbage as your second argument.  The third
argument is only used for O_CREAT.  By the way, O_* are defined in
<sys/file.h>.  (Actually in <sys/fcntlcom.h>, but that's included by
<sys/file.h> [SunOS 4.0*].)

If you're going to hack, at least use lint(1).
					- reg
--
Rick Genter					...!{buita,bbn}!lti!reg
Language Technology, Inc.			reg%lti.uucp@bu-it.bu.edu
27 Congress St., Salem, MA 01970		(508) 741-1507

guy@uunet.uu.net (Guy Harris) (05/09/89)

>By the way, O_* are defined in <sys/file.h>.  (Actually in
><sys/fcntlcom.h>, but that's included by <sys/file.h> [SunOS 4.0*].)

They are properly defined by including <fcntl.h> (note that the 4.0 "open"
and "fcntl" man pages indicate this - it's true of pre-4.0 releases as
well); Berkeley screwed up by documenting <sys/file.h> as the place from
which to get them:

	1) they first appeared in System III, and the documentation there
	   said to get them from <fcntl.h>, so there was prior art;

	2) POSIX says to get them from <fcntl.h>;

	3) getting them from <fcntl.h> works on 4.[23]BSD as well;
	   getting them from <sys/file.h> will probably *not* work on S3
	   or S5.

O_NDELAY is defined in SunOS 4.0 *only* by including <fcntl.h>, since
there are two flavors of no-delay mode, and thus two versions of <fcntl.h>
- the 4BSD-environment one ("/usr/include/fcntl.h") defines it one way,
and the S5-environment one ("/usr/5include/fcntl.h") defines it another
way.