[comp.sources.d] newgetty question

nerd@percival.UUCP (Michael Galassi) (06/06/88)

Howdy,
	I just finished trying to compile the newgetty program recently
posted.  I got _rdchk, _defread and _defopen as undefined by ld.  I
solved the _rdchk as follows but have no clue as to what the other two
routines are supposed to do.  Anyone have a clue for me to go by?  As
per usual,
thanks in advance,
		-michael

int rdchk(fp)
FILE *fp;
{
	int i;

	ioctl(fileno(fp), FIONREAD, &i);
	return i;
}
-- 
        Michael Galassi           | If my opinions happen to be the same as
...!tektronix!tessi!percival!nerd | my employer's it is ONLY a coincidence,
...!uunet!littlei!percival!nerd   | of course coincidences DO happen.

jfh@rpp386.UUCP (John F. Haugh II) (06/08/88)

In article <1259@percival.UUCP> nerd@percival.UUCP (Michael Galassi) writes:
>Howdy,
>	I just finished trying to compile the newgetty program recently
>posted.  I got _rdchk, _defread and _defopen as undefined by ld.  I
>solved the _rdchk as follows but have no clue as to what the other two
>routines are supposed to do.  Anyone have a clue for me to go by?  As
>per usual,
>thanks in advance,
>		-michael

defopen() and defread() and routines for using defaults files.  the
idea being that OEM's would want to be able to configure their systems
without having to provide sources.  using a ``defaults'' file allows
different configurations using the same binary.

an example of a defaults file for dump(1) might be

tape=/dev/rfd0
disk=/dev/rroot

for a small pc, and then

tape=/dev/rmt/0m
disk=/dev/dsk/0s1

for a larger machine using the system v naming convention.  the
normal convention is for a program named 'xxx' to store its defaults
in the file '/etc/default/xxx'.

the call to defopen() for that program would be

int	defopen (char *);

	defopen ("xxx");

and the call to defread() to determine the tape device would be
something like

char	*defread (char *);
char	*mytape, *cp;

	if ((cp = defread ("tape")) == (char *) 0)
		cp = "/dev/rmt/0m";

	strdup (mytape, cp);

i seem to recall there is a bug (or was in the Microsoft Xenix
version i used to use) with these routines.  you may want to write
your own.  i did once and it took mere minutes.  don't forget the
strdup() call, the return value from defread() "points to static
data, whose contents are overwritten by each call."

- john.

allbery@ncoast.UUCP (Brandon S. Allbery) (06/16/88)

As quoted from <1259@percival.UUCP> by nerd@percival.UUCP (Michael Galassi):
+---------------
| 	I just finished trying to compile the newgetty program recently
| posted.  I got _rdchk, _defread and _defopen as undefined by ld.  I
+---------------

rdchk() works on a Unix fd, not a stdio (FILE *).

The "newgetty" posting was specific to Tandy Xenix 3.2, and will need some
work to be ported elsewhere.  Be warned that it may not function correctly
on your system, depending on what BSD expects of a getty vs. what Tandy
Xenix expects.

defopen() and defread() comprise a simple global environment.  defopen()
opens the named file (Xenix convention is that defopen() files live in the
/etc/default directory) and saves the file descriptor for defread().  Any
open defopen() file is closed before the new file is opened.  defread()
looks for lines beginning with the string passed to it and returns a pointer
to the rest of the line.

An example (mirroring an actual use, although this better not be the actual
code!) follows:

/etc/default/mail:
SPOOLONLY=yes

mail.c:
	...
	defopen("/etc/default/mail");
	if ((cp = defread("SPOOLONLY=")) == (char *) 0 || strcmp(cp, "yes"))
		execl("/usr/lib/uucp/uucico", "UUCICO", "-r1", (char *) 0);

++Brandon
-- 
Brandon S. Allbery			  | "Given its constituency, the only
uunet!marque,sun!mandrill}!ncoast!allbery | thing I expect to be "open" about
Delphi: ALLBERY	       MCI Mail: BALLBERY | [the Open Software Foundation] is
comp.sources.misc: ncoast!sources-misc    | its mouth."  --John Gilmore