1 /* general.c -- Stuff that is used by all files. */
3 /* Copyright (C) 1987-2011 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
23 #include "bashtypes.h"
24 #if defined (HAVE_SYS_PARAM_H)
25 # include <sys/param.h>
27 #include "posixstat.h"
29 #if defined (HAVE_UNISTD_H)
36 #include "chartypes.h"
45 #include <tilde/tilde.h>
51 extern int expand_aliases
;
52 extern int interactive_comments
;
53 extern int check_hashed_filenames
;
54 extern int source_uses_path
;
55 extern int source_searches_cwd
;
56 extern int posixly_correct
;
58 static char *bash_special_tilde_expansions
__P((char *));
59 static int unquoted_tilde_word
__P((const char *));
60 static void initialize_group_array
__P((void));
62 /* A standard error message to use when getcwd() returns NULL. */
63 const char * const bash_getcwd_errstr
= N_("getcwd: cannot access parent directories");
65 /* Do whatever is necessary to initialize `Posix mode'. */
70 /* Things that should be turned on when posix mode is enabled. */
73 interactive_comments
= source_uses_path
= expand_aliases
= 1;
74 source_searches_cwd
= 0;
77 /* Things that should be turned on when posix mode is disabled. */
80 source_searches_cwd
= 1;
81 expand_aliases
= interactive_shell
;
85 /* **************************************************************** */
87 /* Functions to convert to and from and display non-standard types */
89 /* **************************************************************** */
91 #if defined (RLIMTYPE)
93 string_to_rlimtype (s
)
101 while (s
&& *s
&& whitespace (*s
))
103 if (s
&& (*s
== '-' || *s
== '+'))
108 for ( ; s
&& *s
&& DIGIT (*s
); s
++)
109 ret
= (ret
* 10) + TODIGIT (*s
);
110 return (neg
? -ret
: ret
);
114 print_rlimtype (n
, addnl
)
118 char s
[INT_STRLEN_BOUND (RLIMTYPE
) + 1], *p
;
127 while ((n
/= 10) != 0);
135 while ((n
/= 10) != 0);
138 printf ("%s%s", p
, addnl
? "\n" : "");
140 #endif /* RLIMTYPE */
142 /* **************************************************************** */
144 /* Input Validation Functions */
146 /* **************************************************************** */
148 /* Return non-zero if all of the characters in STRING are digits. */
155 for (s
= string
; *s
; s
++)
162 /* Return non-zero if the characters pointed to by STRING constitute a
163 valid number. Stuff the converted number into RESULT if RESULT is
166 legal_number (string
, result
)
180 value
= strtoimax (string
, &ep
, 10);
181 if (errno
|| ep
== string
)
182 return 0; /* errno is set on overflow or underflow */
184 /* Skip any trailing whitespace, since strtoimax does not. */
185 while (whitespace (*ep
))
188 /* If *string is not '\0' but *ep is '\0' on return, the entire string
190 if (*string
&& *ep
== '\0')
194 /* The SunOS4 implementation of strtol() will happily ignore
195 overflow conditions, so this cannot do overflow correctly
203 /* Return 1 if this token is a legal shell `identifier'; that is, it consists
204 solely of letters, digits, and underscores, and does not begin with a
207 legal_identifier (name
)
213 if (!name
|| !(c
= *name
) || (legal_variable_starter (c
) == 0))
216 for (s
= name
+ 1; (c
= *s
) != 0; s
++)
218 if (legal_variable_char (c
) == 0)
224 /* Make sure that WORD is a valid shell identifier, i.e.
225 does not contain a dollar sign, nor is quoted in any way. Nor
226 does it consist of all digits. If CHECK_WORD is non-zero,
227 the word is checked to ensure that it consists of only letters,
228 digits, and underscores. */
230 check_identifier (word
, check_word
)
234 if ((word
->flags
& (W_HASDOLLAR
|W_QUOTED
)) || all_digits (word
->word
))
236 internal_error (_("`%s': not a valid identifier"), word
->word
);
239 else if (check_word
&& legal_identifier (word
->word
) == 0)
241 internal_error (_("`%s': not a valid identifier"), word
->word
);
248 /* Return 1 if STRING is a function name that the shell will import from
249 the environment. Currently we reject attempts to import shell functions
250 containing slashes, beginning with newlines or containing blanks. In
251 Posix mode, we require that STRING be a valid shell identifier. Not
254 importable_function_name (string
, len
)
258 if (absolute_program (string
)) /* don't allow slash */
260 if (*string
== '\n') /* can't start with a newline */
262 if (shellblank (*string
) || shellblank(string
[len
-1]))
264 return (posixly_correct
? legal_identifier (string
) : 1);
268 exportable_function_name (string
)
271 if (absolute_program (string
))
273 if (mbschr (string
, '=') != 0)
278 /* Return 1 if STRING comprises a valid alias name. The shell accepts
279 essentially all characters except those which must be quoted to the
280 parser (which disqualifies them from alias expansion anyway) and `/'. */
282 legal_alias_name (string
, flags
)
288 for (s
= string
; *s
; s
++)
289 if (shellbreak (*s
) || shellxquote (*s
) || shellexp (*s
) || (*s
== '/'))
294 /* Returns non-zero if STRING is an assignment statement. The returned value
295 is the index of the `=' sign. */
297 assignment (string
, flags
)
301 register unsigned char c
;
302 register int newi
, indx
;
304 c
= string
[indx
= 0];
306 #if defined (ARRAY_VARS)
307 if ((legal_variable_starter (c
) == 0) && (flags
== 0 || c
!= '[')) /* ] */
309 if (legal_variable_starter (c
) == 0)
313 while (c
= string
[indx
])
315 /* The following is safe. Note that '=' at the start of a word
316 is not an assignment statement. */
320 #if defined (ARRAY_VARS)
323 newi
= skipsubscript (string
, indx
, 0);
324 if (string
[newi
++] != ']')
326 if (string
[newi
] == '+' && string
[newi
+1] == '=')
328 return ((string
[newi
] == '=') ? newi
: 0);
330 #endif /* ARRAY_VARS */
333 if (c
== '+' && string
[indx
+1] == '=')
336 /* Variable names in assignment statements may contain only letters,
338 if (legal_variable_char (c
) == 0)
346 /* **************************************************************** */
348 /* Functions to manage files and file descriptors */
350 /* **************************************************************** */
352 /* A function to unset no-delay mode on a file descriptor. Used in shell.c
353 to unset it on the fd passed as stdin. Should be called on stdin if
354 readline gets an EAGAIN or EWOULDBLOCK when trying to read input. */
356 #if !defined (O_NDELAY)
357 # if defined (FNDELAY)
358 # define O_NDELAY FNDELAY
360 #endif /* O_NDELAY */
362 /* Make sure no-delay mode is not set on file descriptor FD. */
364 sh_unset_nodelay_mode (fd
)
369 if ((flags
= fcntl (fd
, F_GETFL
, 0)) < 0)
374 /* This is defined to O_NDELAY in filecntl.h if O_NONBLOCK is not present
375 and O_NDELAY is defined. */
377 bflags
|= O_NONBLOCK
;
387 return (fcntl (fd
, F_SETFL
, flags
));
393 /* Return 1 if file descriptor FD is valid; 0 otherwise. */
398 return (fcntl (fd
, F_GETFD
, 0) >= 0);
406 if (lseek ((fd
), 0L, SEEK_CUR
) < 0)
407 return (errno
== ESPIPE
);
411 /* There is a bug in the NeXT 2.1 rlogind that causes opens
412 of /dev/tty to fail. */
414 #if defined (__BEOS__)
415 /* On BeOS, opening in non-blocking mode exposes a bug in BeOS, so turn it
416 into a no-op. This should probably go away in the future. */
418 # define O_NONBLOCK 0
419 #endif /* __BEOS__ */
427 tty_fd
= open ("/dev/tty", O_RDWR
|O_NONBLOCK
);
431 tty
= (char *)ttyname (fileno (stdin
));
434 tty_fd
= open (tty
, O_RDWR
|O_NONBLOCK
);
440 /* Return 1 if PATH1 and PATH2 are the same file. This is kind of
441 expensive. If non-NULL STP1 and STP2 point to stat structures
442 corresponding to PATH1 and PATH2, respectively. */
444 same_file (path1
, path2
, stp1
, stp2
)
446 struct stat
*stp1
, *stp2
;
448 struct stat st1
, st2
;
452 if (stat (path1
, &st1
) != 0)
459 if (stat (path2
, &st2
) != 0)
464 return ((stp1
->st_dev
== stp2
->st_dev
) && (stp1
->st_ino
== stp2
->st_ino
));
467 /* Move FD to a number close to the maximum number of file descriptors
468 allowed in the shell process, to avoid the user stepping on it with
469 redirection and causing us extra work. If CHECK_NEW is non-zero,
470 we check whether or not the file descriptors are in use before
471 duplicating FD onto them. MAXFD says where to start checking the
472 file descriptors. If it's less than 20, we get the maximum value
473 available from getdtablesize(2). */
475 move_to_high_fd (fd
, check_new
, maxfd
)
476 int fd
, check_new
, maxfd
;
478 int script_fd
, nfds
, ignore
;
482 nfds
= getdtablesize ();
485 if (nfds
> HIGH_FD_MAX
)
486 nfds
= HIGH_FD_MAX
; /* reasonable maximum */
491 for (nfds
--; check_new
&& nfds
> 3; nfds
--)
492 if (fcntl (nfds
, F_GETFD
, &ignore
) == -1)
495 if (nfds
> 3 && fd
!= nfds
&& (script_fd
= dup2 (fd
, nfds
)) != -1)
497 if (check_new
== 0 || fd
!= fileno (stderr
)) /* don't close stderr */
502 /* OK, we didn't find one less than our artificial maximum; return the
503 original file descriptor. */
507 /* Return non-zero if the characters from SAMPLE are not all valid
508 characters to be found in the first line of a shell script. We
509 check up to the first newline, or SAMPLE_LEN, whichever comes first.
510 All of the characters must be printable or whitespace. */
513 check_binary_file (sample
, sample_len
)
520 for (i
= 0; i
< sample_len
; i
++)
532 /* **************************************************************** */
534 /* Functions to manipulate pipes */
536 /* **************************************************************** */
544 if ((r
= pipe (pv
)) < 0)
547 pv
[0] = move_to_high_fd (pv
[0], 1, 64);
548 pv
[1] = move_to_high_fd (pv
[1], 1, 64);
567 /* **************************************************************** */
569 /* Functions to inspect pathnames */
571 /* **************************************************************** */
579 return (stat (fn
, &sb
) == 0);
588 return ((stat (fn
, &sb
) == 0) && S_ISDIR (sb
.st_mode
));
595 return (file_isdir (fn
) && sh_eaccess (fn
, W_OK
) == 0);
598 /* Return 1 if STRING is "." or "..", optionally followed by a directory
601 path_dot_or_dotdot (string
)
604 if (string
== 0 || *string
== '\0' || *string
!= '.')
607 /* string[0] == '.' */
608 if (PATHSEP(string
[1]) || (string
[1] == '.' && PATHSEP(string
[2])))
614 /* Return 1 if STRING contains an absolute pathname, else 0. Used by `cd'
615 to decide whether or not to look up a directory name in $CDPATH. */
617 absolute_pathname (string
)
620 if (string
== 0 || *string
== '\0')
626 if (string
[0] == '.' && PATHSEP(string
[1])) /* . and ./ */
629 if (string
[0] == '.' && string
[1] == '.' && PATHSEP(string
[2])) /* .. and ../ */
635 /* Return 1 if STRING is an absolute program name; it is absolute if it
636 contains any slashes. This is used to decide whether or not to look
639 absolute_program (string
)
642 return ((char *)mbschr (string
, '/') != (char *)NULL
);
645 /* **************************************************************** */
647 /* Functions to manipulate pathnames */
649 /* **************************************************************** */
651 /* Turn STRING (a pathname) into an absolute pathname, assuming that
652 DOT_PATH contains the symbolic location of `.'. This always
653 returns a new string, even if STRING was an absolute pathname to
656 make_absolute (string
, dot_path
)
657 char *string
, *dot_path
;
661 if (dot_path
== 0 || ABSPATH(string
))
664 char pathbuf
[PATH_MAX
+ 1];
666 cygwin_conv_to_full_posix_path (string
, pathbuf
);
667 result
= savestring (pathbuf
);
670 result
= savestring (string
);
673 result
= sh_makepath (dot_path
, string
, 0);
678 /* Return the `basename' of the pathname in STRING (the stuff after the
679 last '/'). If STRING is `/', just return it. */
681 base_pathname (string
)
687 if (absolute_pathname (string
) == 0)
691 if (string
[0] == '/' && string
[1] == 0)
694 p
= (char *)strrchr (string
, '/');
695 return (p
? ++p
: string
);
698 /* Return the full pathname of FILE. Easy. Filenames that begin
699 with a '/' are returned as themselves. Other filenames have
700 the current working directory prepended. A new string is
701 returned in either case. */
708 file
= (*file
== '~') ? bash_tilde_expand (file
, 0) : savestring (file
);
713 ret
= sh_makepath ((char *)NULL
, file
, (MP_DOCWD
|MP_RMDOT
));
719 /* A slightly related function. Get the prettiest name of this
720 directory possible. */
721 static char tdir
[PATH_MAX
];
723 /* Return a pretty pathname. If the first part of the pathname is
724 the same as $HOME, then replace that with `~'. */
726 polite_directory_format (name
)
732 home
= get_string_value ("HOME");
733 l
= home
? strlen (home
) : 0;
734 if (l
> 1 && strncmp (home
, name
, l
) == 0 && (!name
[l
] || name
[l
] == '/'))
736 strncpy (tdir
+ 1, name
+ l
, sizeof(tdir
) - 2);
738 tdir
[sizeof(tdir
) - 1] = '\0';
745 /* Trim NAME. If NAME begins with `~/', skip over tilde prefix. Trim to
746 keep any tilde prefix and PROMPT_DIRTRIM trailing directory components
747 and replace the intervening characters with `...' */
749 trim_pathname (name
, maxlen
)
755 char *nbeg
, *nend
, *ntail
, *v
;
757 if (name
== 0 || (nlen
= strlen (name
)) == 0)
761 v
= get_string_value ("PROMPT_DIRTRIM");
762 if (v
== 0 || *v
== 0)
764 if (legal_number (v
, &nskip
) == 0 || nskip
<= 0)
767 /* Skip over tilde prefix */
770 for (nbeg
= name
; *nbeg
; nbeg
++)
779 for (ndirs
= 0, ntail
= nbeg
; *ntail
; ntail
++)
785 for (ntail
= (*nend
== '/') ? nend
: nend
- 1; ntail
> nbeg
; ntail
--)
795 /* Now we want to return name[0..nbeg]+"..."+ntail, modifying name in place */
805 memmove (nbeg
, ntail
, nlen
);
811 /* Return a printable representation of FN without special characters. The
812 caller is responsible for freeing memory if this returns something other
813 than its argument. If FLAGS is non-zero, we are printing for portable
814 re-input and should single-quote filenames appropriately. */
816 printable_filename (fn
, flags
)
822 if (ansic_shouldquote (fn
))
823 newf
= ansic_quote (fn
, 0, NULL
);
824 else if (flags
&& sh_contains_shell_metas (fn
))
825 newf
= sh_single_quote (fn
);
832 /* Given a string containing units of information separated by colons,
833 return the next one pointed to by (P_INDEX), or NULL if there are no more.
834 Advance (P_INDEX) to the character after the colon. */
836 extract_colon_unit (string
, p_index
)
846 len
= strlen (string
);
848 return ((char *)NULL
);
852 /* Each call to this routine leaves the index pointing at a colon if
853 there is more to the path. If I is > 0, then increment past the
854 `:'. If I is 0, then the path has a leading colon. Trailing colons
855 are handled OK by the `else' part of the if statement; an empty
856 string is returned in that case. */
857 if (i
&& string
[i
] == ':')
860 for (start
= i
; string
[i
] && string
[i
] != ':'; i
++)
869 /* Return "" in the case of a trailing `:'. */
870 value
= (char *)xmalloc (1);
874 value
= substring (string
, start
, i
);
879 /* **************************************************************** */
881 /* Tilde Initialization and Expansion */
883 /* **************************************************************** */
885 #if defined (PUSHD_AND_POPD)
886 extern char *get_dirstack_from_string
__P((char *));
889 static char **bash_tilde_prefixes
;
890 static char **bash_tilde_prefixes2
;
891 static char **bash_tilde_suffixes
;
892 static char **bash_tilde_suffixes2
;
894 /* If tilde_expand hasn't been able to expand the text, perhaps it
895 is a special shell expansion. This function is installed as the
896 tilde_expansion_preexpansion_hook. It knows how to expand ~- and ~+.
897 If PUSHD_AND_POPD is defined, ~[+-]N expands to directories from the
900 bash_special_tilde_expansions (text
)
905 result
= (char *)NULL
;
907 if (text
[0] == '+' && text
[1] == '\0')
908 result
= get_string_value ("PWD");
909 else if (text
[0] == '-' && text
[1] == '\0')
910 result
= get_string_value ("OLDPWD");
911 #if defined (PUSHD_AND_POPD)
912 else if (DIGIT (*text
) || ((*text
== '+' || *text
== '-') && DIGIT (text
[1])))
913 result
= get_dirstack_from_string (text
);
916 return (result
? savestring (result
) : (char *)NULL
);
919 /* Initialize the tilde expander. In Bash, we handle `~-' and `~+', as
920 well as handling special tilde prefixes; `:~" and `=~' are indications
921 that we should do tilde expansion. */
925 static int times_called
= 0;
927 /* Tell the tilde expander that we want a crack first. */
928 tilde_expansion_preexpansion_hook
= bash_special_tilde_expansions
;
930 /* Tell the tilde expander about special strings which start a tilde
931 expansion, and the special strings that end one. Only do this once.
932 tilde_initialize () is called from within bashline_reinitialize (). */
933 if (times_called
++ == 0)
935 bash_tilde_prefixes
= strvec_create (3);
936 bash_tilde_prefixes
[0] = "=~";
937 bash_tilde_prefixes
[1] = ":~";
938 bash_tilde_prefixes
[2] = (char *)NULL
;
940 bash_tilde_prefixes2
= strvec_create (2);
941 bash_tilde_prefixes2
[0] = ":~";
942 bash_tilde_prefixes2
[1] = (char *)NULL
;
944 tilde_additional_prefixes
= bash_tilde_prefixes
;
946 bash_tilde_suffixes
= strvec_create (3);
947 bash_tilde_suffixes
[0] = ":";
948 bash_tilde_suffixes
[1] = "=~"; /* XXX - ?? */
949 bash_tilde_suffixes
[2] = (char *)NULL
;
951 tilde_additional_suffixes
= bash_tilde_suffixes
;
953 bash_tilde_suffixes2
= strvec_create (2);
954 bash_tilde_suffixes2
[0] = ":";
955 bash_tilde_suffixes2
[1] = (char *)NULL
;
959 /* POSIX.2, 3.6.1: A tilde-prefix consists of an unquoted tilde character
960 at the beginning of the word, followed by all of the characters preceding
961 the first unquoted slash in the word, or all the characters in the word
962 if there is no slash...If none of the characters in the tilde-prefix are
963 quoted, the characters in the tilde-prefix following the tilde shell be
964 treated as a possible login name. */
966 #define TILDE_END(c) ((c) == '\0' || (c) == '/' || (c) == ':')
969 unquoted_tilde_word (s
)
974 for (r
= s
; TILDE_END(*r
) == 0; r
++)
987 /* Find the end of the tilde-prefix starting at S, and return the tilde
988 prefix in newly-allocated memory. Return the length of the string in
989 *LENP. FLAGS tells whether or not we're in an assignment context --
990 if so, `:' delimits the end of the tilde prefix as well. */
992 bash_tilde_find_word (s
, flags
, lenp
)
1000 for (r
= s
; *r
&& *r
!= '/'; r
++)
1002 /* Short-circuit immediately if we see a quote character. Even though
1003 POSIX says that `the first unquoted slash' (or `:') terminates the
1004 tilde-prefix, in practice, any quoted portion of the tilde prefix
1005 will cause it to not be expanded. */
1006 if (*r
== '\\' || *r
== '\'' || *r
== '"')
1008 ret
= savestring (s
);
1013 else if (flags
&& *r
== ':')
1017 ret
= xmalloc (l
+ 1);
1018 strncpy (ret
, s
, l
);
1025 /* Tilde-expand S by running it through the tilde expansion library.
1026 ASSIGN_P is 1 if this is a variable assignment, so the alternate
1027 tilde prefixes should be enabled (`=~' and `:~', see above). If
1028 ASSIGN_P is 2, we are expanding the rhs of an assignment statement,
1029 so `=~' is not valid. */
1031 bash_tilde_expand (s
, assign_p
)
1035 int old_immed
, old_term
, r
;
1038 old_immed
= interrupt_immediately
;
1039 old_term
= terminate_immediately
;
1040 /* We want to be able to interrupt tilde expansion. Ordinarily, we can just
1041 jump to top_level, but we don't want to run any trap commands in a signal
1042 handler context. We might be able to get away with just checking for
1043 things like SIGINT and SIGQUIT. */
1044 if (any_signals_trapped () < 0)
1045 interrupt_immediately
= 1;
1046 terminate_immediately
= 1;
1048 tilde_additional_prefixes
= assign_p
== 0 ? (char **)0
1049 : (assign_p
== 2 ? bash_tilde_prefixes2
: bash_tilde_prefixes
);
1051 tilde_additional_suffixes
= bash_tilde_suffixes2
;
1053 r
= (*s
== '~') ? unquoted_tilde_word (s
) : 1;
1054 ret
= r
? tilde_expand (s
) : savestring (s
);
1056 interrupt_immediately
= old_immed
;
1057 terminate_immediately
= old_term
;
1064 /* **************************************************************** */
1066 /* Functions to manipulate and search the group list */
1068 /* **************************************************************** */
1070 static int ngroups
, maxgroups
;
1072 /* The set of groups that this user is a member of. */
1073 static GETGROUPS_T
*group_array
= (GETGROUPS_T
*)NULL
;
1075 #if !defined (NOGROUP)
1076 # define NOGROUP (gid_t) -1
1080 initialize_group_array ()
1085 maxgroups
= getmaxgroups ();
1088 group_array
= (GETGROUPS_T
*)xrealloc (group_array
, maxgroups
* sizeof (GETGROUPS_T
));
1090 #if defined (HAVE_GETGROUPS)
1091 ngroups
= getgroups (maxgroups
, group_array
);
1094 /* If getgroups returns nothing, or the OS does not support getgroups(),
1095 make sure the groups array includes at least the current gid. */
1098 group_array
[0] = current_user
.gid
;
1102 /* If the primary group is not in the groups array, add it as group_array[0]
1103 and shuffle everything else up 1, if there's room. */
1104 for (i
= 0; i
< ngroups
; i
++)
1105 if (current_user
.gid
== (gid_t
)group_array
[i
])
1107 if (i
== ngroups
&& ngroups
< maxgroups
)
1109 for (i
= ngroups
; i
> 0; i
--)
1110 group_array
[i
] = group_array
[i
- 1];
1111 group_array
[0] = current_user
.gid
;
1115 /* If the primary group is not group_array[0], swap group_array[0] and
1116 whatever the current group is. The vast majority of systems should
1117 not need this; a notable exception is Linux. */
1118 if (group_array
[0] != current_user
.gid
)
1120 for (i
= 0; i
< ngroups
; i
++)
1121 if (group_array
[i
] == current_user
.gid
)
1125 group_array
[i
] = group_array
[0];
1126 group_array
[0] = current_user
.gid
;
1131 /* Return non-zero if GID is one that we have in our groups list. */
1133 #if defined (__STDC__) || defined ( _MINIX)
1134 group_member (gid_t gid
)
1138 #endif /* !__STDC__ && !_MINIX */
1140 #if defined (HAVE_GETGROUPS)
1144 /* Short-circuit if possible, maybe saving a call to getgroups(). */
1145 if (gid
== current_user
.gid
|| gid
== current_user
.egid
)
1148 #if defined (HAVE_GETGROUPS)
1150 initialize_group_array ();
1152 /* In case of error, the user loses. */
1156 /* Search through the list looking for GID. */
1157 for (i
= 0; i
< ngroups
; i
++)
1158 if (gid
== (gid_t
)group_array
[i
])
1166 get_group_list (ngp
)
1169 static char **group_vector
= (char **)NULL
;
1176 return group_vector
;
1180 initialize_group_array ();
1186 return (char **)NULL
;
1189 group_vector
= strvec_create (ngroups
);
1190 for (i
= 0; i
< ngroups
; i
++)
1191 group_vector
[i
] = itos (group_array
[i
]);
1195 return group_vector
;
1199 get_group_array (ngp
)
1203 static int *group_iarray
= (int *)NULL
;
1209 return (group_iarray
);
1213 initialize_group_array ();
1222 group_iarray
= (int *)xmalloc (ngroups
* sizeof (int));
1223 for (i
= 0; i
< ngroups
; i
++)
1224 group_iarray
[i
] = (int)group_array
[i
];
1228 return group_iarray
;