This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 2
[perl5.git] / do / gpent
1 int
2 do_gpent(which,gimme,arglast)
3 int which;
4 int gimme;
5 int *arglast;
6 {
7     register ARRAY *ary = stack;
8     register int sp = arglast[0];
9     register char **elem;
10     register STR *TARG;
11     struct protoent *getprotobyname();
12     struct protoent *getprotobynumber();
13     struct protoent *getprotoent();
14     struct protoent *pent;
15
16     if (which == O_GPBYNAME) {
17         char *name = str_get(ary->ary_array[sp+1]);
18
19         pent = getprotobyname(name);
20     }
21     else if (which == O_GPBYNUMBER) {
22         int proto = (int)str_gnum(ary->ary_array[sp+1]);
23
24         pent = getprotobynumber(proto);
25     }
26     else
27         pent = getprotoent();
28
29     if (gimme != G_ARRAY) {
30         astore(ary, ++sp, TARG = str_mortal(&str_undef));
31         if (pent) {
32             if (which == O_GPBYNAME)
33                 str_numset(TARG, (double)pent->p_proto);
34             else
35                 str_set(TARG, pent->p_name);
36         }
37         return sp;
38     }
39
40     if (pent) {
41 #ifndef lint
42         (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
43         str_set(TARG, pent->p_name);
44         (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
45         for (elem = pent->p_aliases; *elem; elem++) {
46             str_cat(TARG, *elem);
47             if (elem[1])
48                 str_ncat(TARG," ",1);
49         }
50         (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
51         str_numset(TARG, (double)pent->p_proto);
52 #else /* lint */
53         elem = Nullch;
54         elem = elem;
55         (void)astore(ary, ++sp, str_mortal(&str_no));
56 #endif /* lint */
57     }
58
59     return sp;
60 }
61