From 8a0efa53e44919bcf5ccb1d3353618a82afdf8bc Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 17 Feb 2000 19:39:52 +0000 Subject: import newlib-2000-02-17 snapshot --- newlib/libc/unix/Makefile.am | 27 ++++ newlib/libc/unix/Makefile.in | 300 +++++++++++++++++++++++++++++++++++++++++++ newlib/libc/unix/getcwd.c | 265 ++++++++++++++++++++++++++++++++++++++ newlib/libc/unix/getlogin.c | 40 ++++++ newlib/libc/unix/getpass.c | 94 ++++++++++++++ newlib/libc/unix/getpwent.c | 129 +++++++++++++++++++ newlib/libc/unix/getut.c | 85 ++++++++++++ newlib/libc/unix/sigset.c | 61 +++++++++ newlib/libc/unix/ttyname.c | 85 ++++++++++++ 9 files changed, 1086 insertions(+) create mode 100644 newlib/libc/unix/Makefile.am create mode 100644 newlib/libc/unix/Makefile.in create mode 100644 newlib/libc/unix/getcwd.c create mode 100644 newlib/libc/unix/getlogin.c create mode 100644 newlib/libc/unix/getpass.c create mode 100644 newlib/libc/unix/getpwent.c create mode 100644 newlib/libc/unix/getut.c create mode 100644 newlib/libc/unix/sigset.c create mode 100644 newlib/libc/unix/ttyname.c (limited to 'newlib/libc/unix') diff --git a/newlib/libc/unix/Makefile.am b/newlib/libc/unix/Makefile.am new file mode 100644 index 000000000..ae8e92f95 --- /dev/null +++ b/newlib/libc/unix/Makefile.am @@ -0,0 +1,27 @@ +## Process this file with automake to generate Makefile.in + +AUTOMAKE_OPTIONS = cygnus + +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) + +noinst_LIBRARIES = lib.a + +lib_a_SOURCES = \ + getpass.c sigset.c getpwent.c ttyname.c getut.c getlogin.c getcwd.c + +CHEWOUT_FILES = + +SUFFIXES = .def + +CHEW = ../../doc/makedoc -f $(srcdir)/../../doc/doc.str + +.c.def: + $(CHEW) < $< > $*.def 2> $*.ref + touch stmp-def + +TARGETDOC = ../tmp.texi + +# No doc for unix. +doc: + +CLEANFILES = $(CHEWOUT_FILES) *.ref diff --git a/newlib/libc/unix/Makefile.in b/newlib/libc/unix/Makefile.in new file mode 100644 index 000000000..90a226360 --- /dev/null +++ b/newlib/libc/unix/Makefile.in @@ -0,0 +1,300 @@ +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AR = @AR@ +AS = @AS@ +CC = @CC@ +CPP = @CPP@ +CRT0 = @CRT0@ +EXEEXT = @EXEEXT@ +LIBC_MACHINE_LIB = @LIBC_MACHINE_LIB@ +LIBC_POSIX_LIB = @LIBC_POSIX_LIB@ +LIBC_SIGNAL_DEF = @LIBC_SIGNAL_DEF@ +LIBC_SIGNAL_LIB = @LIBC_SIGNAL_LIB@ +LIBC_SYSCALL_LIB = @LIBC_SYSCALL_LIB@ +LIBC_SYS_LIB = @LIBC_SYS_LIB@ +LIBC_UNIX_LIB = @LIBC_UNIX_LIB@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +NEWLIB_CFLAGS = @NEWLIB_CFLAGS@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +VERSION = @VERSION@ +machine_dir = @machine_dir@ +newlib_basedir = @newlib_basedir@ +sys_dir = @sys_dir@ + +AUTOMAKE_OPTIONS = cygnus + +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) + +noinst_LIBRARIES = lib.a + +lib_a_SOURCES = \ + getpass.c sigset.c getpwent.c ttyname.c getut.c getlogin.c getcwd.c + + +CHEWOUT_FILES = + +SUFFIXES = .def + +CHEW = ../../doc/makedoc -f $(srcdir)/../../doc/doc.str + +TARGETDOC = ../tmp.texi + +CLEANFILES = $(CHEWOUT_FILES) *.ref +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_CLEAN_FILES = +LIBRARIES = $(noinst_LIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +lib_a_LIBADD = +lib_a_OBJECTS = getpass.o sigset.o getpwent.o ttyname.o getut.o \ +getlogin.o getcwd.o +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = tar +GZIP_ENV = --best +SOURCES = $(lib_a_SOURCES) +OBJECTS = $(lib_a_OBJECTS) + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .def .o .s +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --cygnus unix/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-noinstLIBRARIES: + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +distclean-noinstLIBRARIES: + +maintainer-clean-noinstLIBRARIES: + +.c.o: + $(COMPILE) -c $< + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +lib.a: $(lib_a_OBJECTS) $(lib_a_DEPENDENCIES) + -rm -f lib.a + $(AR) cru lib.a $(lib_a_OBJECTS) $(lib_a_LIBADD) + $(RANLIB) lib.a + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = unix + +distdir: $(DISTFILES) + @for file in $(DISTFILES); do \ + if test -f $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + cp -pr $$/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: +check: check-am +installcheck-am: +installcheck: installcheck-am +install-info-am: +install-info: install-info-am +install-exec-am: +install-exec: install-exec-am + +install-data-am: +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: +uninstall: uninstall-am +all-am: Makefile $(LIBRARIES) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + + +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \ + mostlyclean-tags mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \ + mostlyclean-am + +clean: clean-am + +distclean-am: distclean-noinstLIBRARIES distclean-compile \ + distclean-tags distclean-generic clean-am + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-noinstLIBRARIES \ + maintainer-clean-compile maintainer-clean-tags \ + maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ +clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile tags mostlyclean-tags distclean-tags \ +clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ +check-am installcheck-am installcheck install-info-am install-info \ +install-exec-am install-exec install-data-am install-data install-am \ +install uninstall-am uninstall all-redirect all-am all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +.c.def: + $(CHEW) < $< > $*.def 2> $*.ref + touch stmp-def + +# No doc for unix. +doc: + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/newlib/libc/unix/getcwd.c b/newlib/libc/unix/getcwd.c new file mode 100644 index 000000000..ee53536ed --- /dev/null +++ b/newlib/libc/unix/getcwd.c @@ -0,0 +1,265 @@ +/* + * Copyright (c) 1989, 1991 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getcwd.c 5.11 (Berkeley) 2/24/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include <_syslist.h> + +#define bcopy(a,b,c) memmove (b,a,c) + +#define ISDOT(dp) \ + (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ + dp->d_name[1] == '.' && dp->d_name[2] == '\0')) + +#ifndef _REENT_ONLY + +char * +getcwd (pt, size) + char *pt; + size_t size; +{ + register struct dirent *dp; + register DIR *dir; + register dev_t dev; + register ino_t ino; + register int first; + register char *bpt, *bup; + struct stat s; + dev_t root_dev; + ino_t root_ino; + size_t ptsize, upsize; + int save_errno; + char *ept, *eup, *up; + + /* + * If no buffer specified by the user, allocate one as necessary. + * If a buffer is specified, the size has to be non-zero. The path + * is built from the end of the buffer backwards. + */ + + if (pt) + { + ptsize = 0; + if (!size) + { + errno = EINVAL; + return (char *) NULL; + } + ept = pt + size; + } + else + { + if (!(pt = (char *) malloc (ptsize = 1024 - 4))) + { + return (char *) NULL; + } + ept = pt + ptsize; + } + bpt = ept - 1; + *bpt = '\0'; + + /* + * Allocate bytes (1024 - malloc space) for the string of "../"'s. + * Should always be enough (it's 340 levels). If it's not, allocate + * as necessary. Special * case the first stat, it's ".", not "..". + */ + + if (!(up = (char *) malloc (upsize = 1024 - 4))) + { + goto err; + } + eup = up + MAXPATHLEN; + bup = up; + up[0] = '.'; + up[1] = '\0'; + + /* Save root values, so know when to stop. */ + if (stat ("/", &s)) + goto err; + root_dev = s.st_dev; + root_ino = s.st_ino; + + errno = 0; /* XXX readdir has no error return. */ + + for (first = 1;; first = 0) + { + /* Stat the current level. */ + if (_stat (up, &s)) + goto err; + + /* Save current node values. */ + ino = s.st_ino; + dev = s.st_dev; + + /* Check for reaching root. */ + if (root_dev == dev && root_ino == ino) + { + *--bpt = '/'; + /* + * It's unclear that it's a requirement to copy the + * path to the beginning of the buffer, but it's always + * been that way and stuff would probably break. + */ + (void) bcopy (bpt, pt, ept - bpt); + free (up); + return pt; + } + + /* + * Build pointer to the parent directory, allocating memory + * as necessary. Max length is 3 for "../", the largest + * possible component name, plus a trailing NULL. + */ + + if (bup + 3 + MAXNAMLEN + 1 >= eup) + { + if (!(up = (char *) realloc (up, upsize *= 2))) + { + goto err; + } + bup = up; + eup = up + upsize; + } + *bup++ = '.'; + *bup++ = '.'; + *bup = '\0'; + + /* Open and stat parent directory. */ + if (!(dir = _opendir (up)) || _fstat (__dirfd (dir), &s)) + goto err; + + /* Add trailing slash for next directory. */ + *bup++ = '/'; + + /* + * If it's a mount point, have to stat each element because + * the inode number in the directory is for the entry in the + * parent directory, not the inode number of the mounted file. + */ + + save_errno = 0; + if (s.st_dev == dev) + { + for (;;) + { + if (!(dp = _readdir (dir))) + goto notfound; + if (dp->d_ino == ino) + break; + } + } + else + for (;;) + { + if (!(dp = _readdir (dir))) + goto notfound; + if (ISDOT (dp)) + continue; + bcopy (dp->d_name, bup, strlen (dp->d_name) + 1); + + /* Save the first error for later. */ + if (stat (up, &s)) + { + if (!save_errno) + save_errno = errno; + errno = 0; + continue; + } + if (s.st_dev == dev && s.st_ino == ino) + break; + } + + /* + * Check for length of the current name, preceding slash, + * leading slash. + */ + + if (bpt - pt <= strlen (dp->d_name) + (first ? 1 : 2)) + { + size_t len, off; + + if (!ptsize) + { + errno = ERANGE; + goto err; + } + off = bpt - pt; + len = ept - bpt; + if (!(pt = (char *) realloc (pt, ptsize *= 2))) + { + goto err; + } + bpt = pt + off; + ept = pt + ptsize; + (void) bcopy (bpt, ept - len, len); + bpt = ept - len; + } + if (!first) + *--bpt = '/'; + bpt -= strlen (dp->d_name); + bcopy (dp->d_name, bpt, strlen (dp->d_name)); + (void) _closedir (dir); + + /* Truncate any file name. */ + *bup = '\0'; + } + +notfound: + /* + * If readdir set errno, use it, not any saved error; otherwise, + * didn't find the current directory in its parent directory, set + * errno to ENOENT. + */ + + if (!errno) + errno = save_errno ? save_errno : ENOENT; + /* FALLTHROUGH */ + +err: + if (ptsize) + free (pt); + free (up); + return (char *) NULL; +} + +#endif /* _REENT_ONLY */ diff --git a/newlib/libc/unix/getlogin.c b/newlib/libc/unix/getlogin.c new file mode 100644 index 000000000..7c1f3104e --- /dev/null +++ b/newlib/libc/unix/getlogin.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include <_syslist.h> + +char * +getlogin () +{ + int utmp_fd; + struct utmp utmp_buf; + static char buf[10]; + extern char *ttyname (); + char *tty; + + if (((tty = ttyname (0)) == 0) + || ((tty = ttyname (1)) == 0) + || ((tty = ttyname (2)) == 0)) + return 0; + + if ((utmp_fd = _open (UTMP_FILE, O_RDONLY)) == -1) + return 0; + + if (!strncmp (tty, "/dev/", 5)) + tty += 5; + + while (_read (utmp_fd, &utmp_buf, sizeof (utmp_buf)) == sizeof (utmp_buf)) + { + if (!strncmp (tty, utmp_buf.ut_line, sizeof (utmp_buf.ut_line)) + && utmp_buf.ut_type == USER_PROCESS) + { + _close (utmp_fd); + memset (buf, 0, sizeof (buf)); + strncpy (buf, utmp_buf.ut_user, sizeof (utmp_buf.ut_user)); + return buf; + } + } + + _close (utmp_fd); + return 0; +} diff --git a/newlib/libc/unix/getpass.c b/newlib/libc/unix/getpass.c new file mode 100644 index 000000000..ff9e7e67d --- /dev/null +++ b/newlib/libc/unix/getpass.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getpass.c 5.9 (Berkeley) 5/6/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include <_syslist.h> + +char * +getpass (prompt) + const char *prompt; +{ + struct termios term; + register int ch; + register char *p; + FILE *fp, *outfp; + long omask; + int echo; + static char buf[_PASSWORD_LEN + 1]; + + /* + * read and write to /dev/tty if possible; else read from + * stdin and write to stderr. + */ + + if ((outfp = fp = fopen ("/dev/tty", "w+")) == NULL) + { + outfp = stderr; + fp = stdin; + } + /* + * note - blocking signals isn't necessarily the + * right thing, but we leave it for now. + */ + omask = sigblock (sigmask (SIGINT) | sigmask (SIGTSTP)); + (void) tcgetattr (fileno (fp), &term); + if (echo = (term.c_lflag & ECHO)) + { + term.c_lflag &= ~ECHO; + (void) tcsetattr (fileno (fp), TCSAFLUSH, &term); + } + (void) fputs (prompt, outfp); + rewind (outfp); /* implied flush */ + for (p = buf; (ch = getc (fp)) != EOF && ch != '\n';) + if (p < buf + _PASSWORD_LEN) + *p++ = ch; + *p = '\0'; + (void) _write (fileno (outfp), "\n", 1); + if (echo) + { + term.c_lflag |= ECHO; + tcsetattr (fileno (fp), TCSAFLUSH, &term); + } + (void) sigsetmask (omask); + if (fp != stdin) + (void) fclose (fp); + return buf; +} diff --git a/newlib/libc/unix/getpwent.c b/newlib/libc/unix/getpwent.c new file mode 100644 index 000000000..23a35f49b --- /dev/null +++ b/newlib/libc/unix/getpwent.c @@ -0,0 +1,129 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +static struct passwd pw_passwd; /* password structure */ +static FILE *passwd_fp; + +static char logname[8]; +static char password[1024]; +static char comment[1024]; +static char gecos[1024]; +static char dir[1024]; +static char shell[1024]; + +struct passwd * +getpwnam (name) + const char *name; +{ + FILE *fp; + int uid, gid; + char buf[1024]; + + if ((fp = fopen ("/etc/passwd", "r")) == NULL) + { + return NULL; + } + + while (fgets (buf, sizeof (buf), fp)) + { + sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n", + logname, password, &pw_passwd.pw_uid, + &pw_passwd.pw_gid, comment, gecos, + dir, shell); + pw_passwd.pw_name = logname; + pw_passwd.pw_passwd = password; + pw_passwd.pw_comment = comment; + pw_passwd.pw_gecos = gecos; + pw_passwd.pw_dir = dir; + pw_passwd.pw_shell = shell; + + if (!strcmp (logname, name)) + { + fclose (fp); + return &pw_passwd; + } + } + fclose (fp); + return NULL; +} + +struct passwd * +getpwuid (uid_t uid) +{ + FILE *fp; + char buf[1024]; + + if ((fp = fopen ("/etc/passwd", "r")) == NULL) + { + return NULL; + } + + while (fgets (buf, sizeof (buf), fp)) + { + sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n", + logname, password, &pw_passwd.pw_uid, + &pw_passwd.pw_gid, comment, gecos, + dir, shell); + pw_passwd.pw_name = logname; + pw_passwd.pw_passwd = password; + pw_passwd.pw_comment = comment; + pw_passwd.pw_gecos = gecos; + pw_passwd.pw_dir = dir; + pw_passwd.pw_shell = shell; + + if (uid == pw_passwd.pw_uid) + { + fclose (fp); + return &pw_passwd; + } + } + fclose (fp); + return NULL; +} + +struct passwd * +getpwent () +{ + char buf[1024]; + + if (passwd_fp == NULL) + return NULL; + + if (fgets (buf, sizeof (buf), passwd_fp) == NULL) + return NULL; + + sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n", + logname, password, &pw_passwd.pw_uid, + &pw_passwd.pw_gid, comment, gecos, + dir, shell); + pw_passwd.pw_name = logname; + pw_passwd.pw_passwd = password; + pw_passwd.pw_comment = comment; + pw_passwd.pw_gecos = gecos; + pw_passwd.pw_dir = dir; + pw_passwd.pw_shell = shell; + + return &pw_passwd; +} + +void +setpwent () +{ + if (passwd_fp != NULL) + fclose (passwd_fp); + + passwd_fp = fopen ("/etc/passwd", "r"); +} + +void +endpwent () +{ + if (passwd_fp != NULL) + fclose (passwd_fp); +} diff --git a/newlib/libc/unix/getut.c b/newlib/libc/unix/getut.c new file mode 100644 index 000000000..d716b324c --- /dev/null +++ b/newlib/libc/unix/getut.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include <_syslist.h> + +static int utmp_fd = -2; +static char *utmp_file = UTMP_FILE; + +static struct utmp utmp_data; + +void +setutent () +{ + if (utmp_fd == -2) + { + utmp_fd = _open (utmp_file, O_RDONLY); + } + _lseek (utmp_fd, 0, SEEK_SET); +} + +void +endutent () +{ + _close (utmp_fd); + utmp_fd = -2; +} + +void +utmpname (char *file) +{ + extern char *strdup (char *); + + utmp_file = strdup (file); +} + +struct utmp * +getutent () +{ + if (utmp_fd == -2) + setutent (); + if (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) < sizeof (utmp_data)) + return 0; + return &utmp_data; +} + +struct utmp * +getutid (struct utmp *id) +{ + while (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data)) + { + switch (id->ut_type) + { + case RUN_LVL: + case BOOT_TIME: + case OLD_TIME: + case NEW_TIME: + if (id->ut_type == utmp_data.ut_type) + return &utmp_data; + case INIT_PROCESS: + case LOGIN_PROCESS: + case USER_PROCESS: + case DEAD_PROCESS: + if (id->ut_id == utmp_data.ut_id) + return &utmp_data; + default: + abort (); + } + } + return 0; +} + +struct utmp * +getutline (struct utmp *line) +{ + while (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data)) + { + if ((utmp_data.ut_type == LOGIN_PROCESS || + utmp_data.ut_type == USER_PROCESS) && + !strncmp (utmp_data.ut_line, line->ut_line, + sizeof (utmp_data.ut_line))) + return &utmp_data; + } + + return 0; +} diff --git a/newlib/libc/unix/sigset.c b/newlib/libc/unix/sigset.c new file mode 100644 index 000000000..ecb3d0800 --- /dev/null +++ b/newlib/libc/unix/sigset.c @@ -0,0 +1,61 @@ +#include +#include + +#ifdef SIG_SETMASK /* easier than trying to remove from Makefile */ + +#undef sigemptyset +int +sigemptyset (sigset_t * set) +{ + *set = (sigset_t) 0; + return 0; +} + +int +sigfillset (sigset_t * set) +{ + *set = ~((sigset_t) 0); + return 0; +} + +#undef sigaddset +int +sigaddset (sigset_t * set, int signo) +{ + if (signo >= NSIG || signo <= 0) + { + errno = EINVAL; + return -1; + } + *set |= 1 << (signo - 1); + return 0; +} + +int +sigdelset (sigset_t * set, int signo) +{ + if (signo >= NSIG || signo <= 0) + { + errno = EINVAL; + return -1; + } + *set &= ~(1 << (signo - 1)); + return 0; +} + +int +sigismember (const sigset_t * set, int signo) +{ + if (signo >= NSIG || signo <= 0) + { + errno = EINVAL; + return -1; + } + + if (*set & (1 << (signo - 1))) + return 1; + else + return 0; +} + +#endif /* SIG_SETMASK */ diff --git a/newlib/libc/unix/ttyname.c b/newlib/libc/unix/ttyname.c new file mode 100644 index 000000000..582a7903f --- /dev/null +++ b/newlib/libc/unix/ttyname.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)ttyname.c 5.10 (Berkeley) 5/6/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include <_syslist.h> + +static char buf[sizeof (_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; + +char * +ttyname (fd) + int fd; +{ + struct stat sb; + struct termios tty; + struct dirent *dirp; + DIR *dp; + struct stat dsb; + char *rval; + + /* Must be a terminal. */ + if (tcgetattr (fd, &tty) < 0) + return NULL; + + /* Must be a character device. */ + if (_fstat (fd, &sb) || !S_ISCHR (sb.st_mode)) + return NULL; + + if ((dp = _opendir (_PATH_DEV)) == NULL) + return NULL; + + for (rval = NULL; dirp = _readdir (dp);) + { + if (dirp->d_ino != sb.st_ino) + continue; + strcpy (buf + sizeof (_PATH_DEV) - 1, dirp->d_name); + if (stat (buf, &dsb) || sb.st_dev != dsb.st_dev || + sb.st_ino != dsb.st_ino) + continue; + (void) _closedir (dp); + rval = buf; + break; + } + (void) _closedir (dp); + return rval; +} -- cgit v1.2.3