|
Home > Archive > Unix Programming > November 2007 > A possible vague question about ttys
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
A possible vague question about ttys
|
|
| K-mart Cashier 2007-11-17, 1:27 am |
| I have a question about something I saw in some large code. The author
checks for the user tty using the following
while ((err = getopt(argc, argv, "t:s:wrp:")) != -1)
switch (err) {
case 't':
tflg = 1;
strncpy(tsk[0].u.ut_line, optarg, sizeof (tsk[0].u.ut_line));
break;
And then later on,
int check_in(tty, in)
char *tty;
int in;
{
int i;
for (i = 0; i < in; i++) {
if (!strncmp(tty, uinfo[i].ut_line, strlen(tty))) {
return 1;
}
}
return 0;
}
The question is why would this person copy the tty arg into
tsk[0].u.ut_line? Ie why not just do something
../name cdalten -t ttyp4
Then in the program, just check if the arg ttyp4 (via check_in())
passed on the command line was a vaild tty.
Chad
| |
| Barry Margolin 2007-11-17, 1:33 pm |
| In article
<e3c017b3-4330-4c01-89fe-3c9452d288f9@a39g2000pre.googlegroups.com>,
K-mart Cashier <cdalten@gmail.com> wrote:
> I have a question about something I saw in some large code. The author
> checks for the user tty using the following
>
> while ((err = getopt(argc, argv, "t:s:wrp:")) != -1)
> switch (err) {
> case 't':
> tflg = 1;
> strncpy(tsk[0].u.ut_line, optarg, sizeof (tsk[0].u.ut_line));
> break;
>
> And then later on,
> int check_in(tty, in)
> char *tty;
> int in;
> {
> int i;
>
> for (i = 0; i < in; i++) {
> if (!strncmp(tty, uinfo[i].ut_line, strlen(tty))) {
> return 1;
> }
> }
> return 0;
> }
>
>
> The question is why would this person copy the tty arg into
> tsk[0].u.ut_line? Ie why not just do something
>
> ./name cdalten -t ttyp4
>
> Then in the program, just check if the arg ttyp4 (via check_in())
> passed on the command line was a vaild tty.
>
> Chad
Without seeing the whole program, I can only assume that it uses the tsk
array for other things as well.
Or maybe he just didn't realize that he could simply assign optarg to
another pointer and later use that when calling check_in.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|