setenv from c
P. D. Guthrie
pdg at ihdev.UUCP
Tue Oct 1 03:25:29 AEST 1985
In article <1355 at teddy.UUCP> jpn at teddy.UUCP (John P. Nelson) writes:
>> Is it possible to set a csh environment variable within a C program?
>
>In all the replies to this question, I have not yet seen my favorite techniqe.
>This only works on BSD 4.X (at least as far as I know). There is an
>undocumented ioctl() which allows you to push data back onto your input queue
>(i.e. simulate characters typed at the terminal). Using this technique, one
>can stuff strings like "setenv TERM xxx\n" into the parent shell's input.
>
>A fragment of the code that does the work:
>
>#include <sgtty.h>
>
>eatthis(string)
>register char *string;
> {
> int pendin = LPENDIN;
>
> noecho(); /* turn off echo mode */
> while (*string)
> {
> ioctl(0, TIOCSTI, string); /* do the work */
> ++string;
> }
> echo(); /* turn echo back on */
> ioctl(0, TIOCLBIS, &pendin); /* set the pending input flag */
> }
Undocumented? TTY(4) page 12 (66lines/page). This call does not exist
on either System 5 or Version 7 - however the hack to put them into the
kernel is about twenty lines. Oh for this and FIONREAD to be put into
standard SYS V!!!
Paul Guthrie.
More information about the Comp.lang.c
mailing list