A possible vague question about ttys
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > A possible vague question about ttys




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    A possible vague question about ttys  
K-mart Cashier


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-17-07 06: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





[ Post a follow-up to this message ]



    Re: A possible vague question about ttys  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-17-07 06: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 ***





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:11 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register