From 24efca1401704881732859321c6c9dab024a02c5 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 8 Sep 2003 20:08:53 +0000 Subject: [PATCH] * cygwin.din: Export endusershell, getusershell and setusershell. * syscalls.cc (getusershell): New function. (setusershell): Ditto. (endusershell): Ditto. * include/cygwin/version.h: Bump API minor number. --- winsup/cygwin/ChangeLog | 8 ++++ winsup/cygwin/cygwin.din | 3 ++ winsup/cygwin/include/cygwin/version.h | 9 ++-- winsup/cygwin/syscalls.cc | 66 ++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 26b4c3fd8..a99558396 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2003-09-08 Corinna Vinschen + + * cygwin.din: Export endusershell, getusershell and setusershell. + * syscalls.cc (getusershell): New function. + (setusershell): Ditto. + (endusershell): Ditto. + * include/cygwin/version.h: Bump API minor number. + 2003-09-08 Nicholas Wourms * cygwin.din: Export argz_add argz_add_sep argz_append argz_count diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 76dd69057..b67d7a687 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -289,6 +289,7 @@ cygwin32_detach_dll = cygwin_detach_dll cygwin_dll_init endprotoent = cygwin_endprotoent endservent = cygwin_endservent +endusershell gethostbyaddr = cygwin_gethostbyaddr gethostbyname = cygwin_gethostbyname _gethostname = cygwin_gethostname @@ -302,6 +303,7 @@ getservbyport = cygwin_getservbyport getservent = cygwin_getservent getsockname = cygwin_getsockname getsockopt = cygwin_getsockopt +getusershell herror = cygwin_herror hstrerror = cygwin_hstrerror inet_addr = cygwin_inet_addr @@ -335,6 +337,7 @@ cygwin_set_impersonation_token setprotoent = cygwin_setprotoent setservent = cygwin_setservent setsockopt = cygwin_setsockopt +setusershell shutdown = cygwin_shutdown socket = cygwin_socket cygwin_split_path diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index b0abf8d5e..9fc8cdf2b 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -211,16 +211,17 @@ details. */ 89: Export __mempcpy 90: Export _fopen64 91: Export argz_add argz_add_sep argz_append argz_count argz_create - argz_create_sep argz_delete argz_extract argz_insert - argz_next argz_replace argz_stringify envz_add envz_entry - envz_get envz_merge envz_remove envz_strip + argz_create_sep argz_delete argz_extract argz_insert + argz_next argz_replace argz_stringify envz_add envz_entry + envz_get envz_merge envz_remove envz_strip + 92: Export getusershell, setusershell, eetusershell */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 91 +#define CYGWIN_VERSION_API_MINOR 92 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 8dd659ab4..d15384260 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -30,6 +30,8 @@ details. */ #include #include #include +#include +#include #include #include #include @@ -2897,3 +2899,67 @@ long gethostid(void) return hostid; } + +#define ETC_SHELLS "/etc/shells" +static int shell_index; +static FILE *shell_fp; + +extern "C" char * +getusershell () +{ + /* List of default shells if no /etc/shells exists, defined as on Linux. + FIXME: SunOS has a far longer list, containing all shells which + might be shipped with the OS. Should we do the same for the Cygwin + distro, adding bash, tcsh, ksh, pdksh and zsh? */ + static NO_COPY const char *def_shells[] = { + "/bin/sh", + "/bin/csh", + "/usr/bin/sh", + "/usr/bin/csh", + NULL + }; + static char buf[MAX_PATH]; + int ch, buf_idx; + + if (!shell_fp && !(shell_fp = fopen (ETC_SHELLS, "rt"))) + { + if (def_shells[shell_index]) + return strcpy (buf, def_shells[shell_index++]); + return NULL; + } + /* Skip white space characters. */ + while ((ch = getc (shell_fp)) != EOF && isspace (ch)) + ; + /* Get each non-whitespace character as part of the shell path as long as + it fits in buf. */ + for (buf_idx = 0; + ch != EOF && !isspace (ch) && buf_idx < MAX_PATH; + buf_idx++, ch = getc (shell_fp)) + buf[buf_idx] = ch; + /* Skip any trailing non-whitespace character not fitting in buf. If the + path is longer than MAX_PATH, it's invalid anyway. */ + while (ch != EOF && !isspace (ch)) + ch = getc (shell_fp); + if (buf_idx) + { + buf[buf_idx] = '\0'; + return buf; + } + return NULL; +} + +extern "C" void +setusershell () +{ + if (shell_fp) + fseek (shell_fp, 0L, SEEK_SET); + shell_index = 0; +} + +extern "C" void +endusershell () +{ + if (shell_fp) + fclose (shell_fp); + shell_index = 0; +}