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 ]
|