[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/build/uClibc/libutil/Makefile b/ap/build/uClibc/libutil/Makefile
new file mode 100644
index 0000000..c8dc9b4
--- /dev/null
+++ b/ap/build/uClibc/libutil/Makefile
@@ -0,0 +1,13 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+top_srcdir=../
+top_builddir=../
+include $(top_builddir)Rules.mak
+all: libs
+include Makefile.in
+include $(top_srcdir)Makerules
diff --git a/ap/build/uClibc/libutil/Makefile.in b/ap/build/uClibc/libutil/Makefile.in
new file mode 100644
index 0000000..f904fc7
--- /dev/null
+++ b/ap/build/uClibc/libutil/Makefile.in
@@ -0,0 +1,69 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+subdirs += libutil
+
+CFLAGS-libutil := -DNOT_IN_libc -DIS_IN_libutil $(SSP_ALL_CFLAGS)
+
+LDFLAGS-$(UCLIBC_FORMAT_DSBT_ELF)-libutil.so := -Wl,--dsbt-index=8
+LDFLAGS-libutil.so := $(LDFLAGS)
+
+LIBS-libutil.so := $(LIBS)
+
+libutil_FULL_NAME := libutil-$(VERSION).so
+
+libutil_DIR := $(top_srcdir)libutil
+libutil_OUT := $(top_builddir)libutil
+
+libutil_SRC := $(wildcard $(libutil_DIR)/*.c)
+ifneq ($(ARCH_USE_MMU),y)
+libutil_SRC := $(filter-out $(libutil_DIR)/forkpty.c,$(libutil_SRC))
+endif
+ifneq ($(UCLIBC_HAS_PTY),y)
+libutil_SRC := $(filter-out $(libutil_DIR)/openpty.c $(libutil_DIR)/forkpty.c \
+		,$(libutil_SRC))
+endif
+libutil_OBJ := $(patsubst $(libutil_DIR)/%.c,$(libutil_OUT)/%.o,$(libutil_SRC))
+
+ifeq ($(DOPIC),y)
+libutil-a-y := $(libutil_OBJ:.o=.os)
+else
+libutil-a-y := $(libutil_OBJ)
+endif
+libutil-so-y := $(libutil_OBJ:.o=.os)
+
+lib-a-$(UCLIBC_HAS_LIBUTIL) += $(top_builddir)lib/libutil.a
+lib-so-$(UCLIBC_HAS_LIBUTIL) += $(top_builddir)lib/libutil.so
+objclean-y += CLEAN_libutil
+
+ifeq ($(DOMULTI),n)
+ifeq ($(DOPIC),y)
+$(top_builddir)lib/libutil.so: $(top_builddir)lib/libutil.a $(libc.depend)
+else
+$(top_builddir)lib/libutil.so: $(libutil_OUT)/libutil_so.a $(libc.depend)
+endif
+	$(call link.so,$(libutil_FULL_NAME),$(ABI_VERSION))
+else
+$(top_builddir)lib/libutil.so: $(libutil_OUT)/libutil.oS | $(libc.depend)
+	$(call linkm.so,$(libutil_FULL_NAME),$(ABI_VERSION))
+endif
+
+$(libutil_OUT)/libutil_so.a: $(libutil-so-y)
+	$(Q)$(RM) $@
+	$(do_ar)
+
+$(libutil_OUT)/libutil.oS: $(libutil_SRC)
+	$(Q)$(RM) $@
+	$(compile-m)
+
+$(top_builddir)lib/libutil.a: $(libutil-a-y)
+	$(Q)$(INSTALL) -d $(dir $@)
+	$(Q)$(RM) $@
+	$(do_ar)
+
+CLEAN_libutil:
+	$(do_rm) $(addprefix $(libutil_OUT)/*., o os oS a)
diff --git a/ap/build/uClibc/libutil/forkpty.c b/ap/build/uClibc/libutil/forkpty.c
new file mode 100644
index 0000000..61e8592
--- /dev/null
+++ b/ap/build/uClibc/libutil/forkpty.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sys/types.h>
+#include <termios.h>
+#include <unistd.h>
+#include <utmp.h>
+#include <pty.h>
+
+libutil_hidden_proto(openpty)
+libutil_hidden_proto(login_tty)
+
+int
+forkpty (int *amaster, char *name, struct termios *termp, struct winsize *winp)
+{
+  int master, slave, pid;
+
+  if (openpty (&master, &slave, name, termp, winp) == -1)
+    return -1;
+
+  switch (pid = fork ())
+    {
+    case -1:
+      return -1;
+    case 0:
+      /* Child.  */
+      close (master);
+      if (login_tty (slave))
+	_exit (1);
+
+      return 0;
+    default:
+      /* Parent.  */
+      *amaster = master;
+      close (slave);
+
+      return pid;
+    }
+}
diff --git a/ap/build/uClibc/libutil/login.c b/ap/build/uClibc/libutil/login.c
new file mode 100644
index 0000000..4007e4c
--- /dev/null
+++ b/ap/build/uClibc/libutil/login.c
@@ -0,0 +1,60 @@
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <utmp.h>
+
+/* Write the given entry into utmp and wtmp.
+ * Note: the match in utmp is done against ut_id field,
+ * which is NOT set by this function - caller must set it.
+ */
+void login(const struct utmp *entry)
+{
+	struct utmp copy;
+	char tty_name[sizeof(copy.ut_line) + 6];
+	int fd;
+
+// Manpage:
+// login() takes the argument ut struct, fills the field ut->ut_type
+// (if there is such a field) with the value USER_PROCESS,
+// and fills the field ut->ut_pid (if there is such a field)
+// with the process ID of the calling process.
+	copy = *entry;
+#if _HAVE_UT_TYPE - 0
+	copy.ut_type = USER_PROCESS;
+#endif
+#if _HAVE_UT_PID - 0
+	copy.ut_pid = getpid();
+#endif
+
+// Then it tries to fill the field ut->ut_line. It takes the first of stdin,
+// stdout, stderr that is a tty, and stores the corresponding pathname minus
+// a possible leading /dev/ into this field, and then writes the struct
+// to the utmp file. On the other hand, if no tty name was found,
+// this field is filled with "???" and the struct is not written
+// to the utmp file.
+	fd = 0;
+	while (fd != 3 && ttyname_r(fd, tty_name, sizeof(tty_name)) != 0)
+		fd++;
+	if (fd != 3) {
+		if (strncmp(tty_name, "/dev/", 5) == 0)
+			strncpy(copy.ut_line, tty_name + 5, sizeof(copy.ut_line)-1);
+		else
+			strncpy(copy.ut_line, tty_name, sizeof(copy.ut_line)-1);
+		copy.ut_line[sizeof(copy.ut_line)-1] = '\0';
+
+		/* utmpname(_PATH_UTMP); - why?
+		 * this makes it impossible for caller to use other file!
+		 * Does any standard or historical precedent says this must be done? */
+		setutent();
+		/* Replaces record with matching ut_id, or appends new one: */
+		pututline(&copy);
+		endutent();
+	} else {
+		strncpy(copy.ut_line, "???", sizeof(copy.ut_line));
+	}
+
+// After this, the struct is written to the wtmp file.
+	updwtmp(_PATH_WTMP, &copy);
+}
diff --git a/ap/build/uClibc/libutil/login_tty.c b/ap/build/uClibc/libutil/login_tty.c
new file mode 100644
index 0000000..3979adc
--- /dev/null
+++ b/ap/build/uClibc/libutil/login_tty.c
@@ -0,0 +1,71 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *	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.
+ * 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.
+ */
+
+/* Make FD be the controlling terminal, stdin, stdout, and stderr;
+   then close FD.  Returns 0 on success, nonzero on error.  */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <utmp.h>
+
+libutil_hidden_proto(login_tty)
+int login_tty(int fd)
+{
+	(void) setsid();
+#ifdef TIOCSCTTY
+	if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1)
+		return (-1);
+#else
+	{
+	  /* This might work.  */
+	  char *fdname = ttyname (fd);
+	  int newfd;
+	  if (fdname)
+	    {
+	      if (fd != 0)
+		(void) close (0);
+	      if (fd != 1)
+		(void) close (1);
+	      if (fd != 2)
+		(void) close (2);
+	      newfd = open (fdname, O_RDWR);
+	      (void) close (newfd);
+	    }
+	}
+#endif
+	(void) dup2(fd, 0);
+	(void) dup2(fd, 1);
+	(void) dup2(fd, 2);
+	if (fd > 2)
+		(void) close(fd);
+	return (0);
+}
+libutil_hidden_def(login_tty)
diff --git a/ap/build/uClibc/libutil/logout.c b/ap/build/uClibc/libutil/logout.c
new file mode 100644
index 0000000..5f58b8f
--- /dev/null
+++ b/ap/build/uClibc/libutil/logout.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <string.h>
+#include <utmp.h>
+#include <sys/time.h>
+
+int
+logout (const char *line)
+{
+  struct utmp tmp;
+  struct utmp *ut;
+  int result = 0;
+
+  /* if (utmpname (_PATH_UTMP) == -1) return 0; - why?
+   * this makes it impossible for caller to use other file!
+   * Does any standard or historical precedent says this must be done? */
+
+  /* Open UTMP file.  */
+  setutent ();
+
+  /* Fill in search information.  */
+#if _HAVE_UT_TYPE - 0
+  tmp.ut_type = USER_PROCESS;
+#endif
+  strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
+
+  /* Read the record.  */
+  if ((ut = getutline(&tmp)) != NULL)
+    {
+      /* Clear information about who & from where.  */
+      memset (ut->ut_name, 0, sizeof ut->ut_name);
+#if _HAVE_UT_HOST - 0
+      memset (ut->ut_host, 0, sizeof ut->ut_host);
+#endif
+#if _HAVE_UT_TV - 0
+# if !defined __WORDSIZE_COMPAT32 || __WORDSIZE_COMPAT32 == 0
+      gettimeofday (&ut->ut_tv, NULL);
+# else
+      {
+	struct timeval tv;
+	gettimeofday (&tv, NULL);
+	ut->ut_tv.tv_sec = tv.tv_sec;
+	ut->ut_tv.tv_usec = tv.tv_usec;
+      }
+# endif
+#else
+      time (&ut->ut_time);
+#endif
+#if _HAVE_UT_TYPE - 0
+      ut->ut_type = DEAD_PROCESS;
+#endif
+
+      if (pututline (ut) != NULL)
+	result = 1;
+    }
+
+  /* Close UTMP file.  */
+  endutent ();
+
+  return result;
+}
diff --git a/ap/build/uClibc/libutil/logwtmp.c b/ap/build/uClibc/libutil/logwtmp.c
new file mode 100644
index 0000000..2a6f28a
--- /dev/null
+++ b/ap/build/uClibc/libutil/logwtmp.c
@@ -0,0 +1,55 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * wtmp support rubbish (i.e. complete crap)
+ * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+#include <utmp.h>
+#include <fcntl.h>
+#include <sys/file.h>
+
+void logwtmp(const char *line, const char *name, const char *host)
+{
+    struct utmp lutmp;
+    memset(&lutmp, 0, sizeof(lutmp));
+
+    lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS;
+    lutmp.ut_pid = getpid();
+    strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
+    strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
+    strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
+#if !defined __WORDSIZE_COMPAT32 || __WORDSIZE_COMPAT32 == 0
+    gettimeofday(&lutmp.ut_tv, NULL);
+#else
+    {
+      struct timeval tv;
+      gettimeofday(&tv, NULL);
+      lutmp.ut_tv.tv_sec = tv.tv_sec;
+      lutmp.ut_tv.tv_usec = tv.tv_usec;
+    }
+#endif
+
+    updwtmp(_PATH_WTMP, &lutmp);
+}
+
+#if 0
+/* This is enabled in uClibc/libc/misc/utmp/wtent.c */
+void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
+{
+    int fd;
+
+    fd = open(wtmp_file, O_APPEND | O_WRONLY);
+    if (fd >= 0) {
+	if (lockf(fd, F_LOCK, 0) == 0) {
+	    write(fd, lutmp, sizeof(*lutmp));
+	    lockf(fd, F_ULOCK, 0);
+	    close(fd);
+	}
+    }
+}
+#endif
diff --git a/ap/build/uClibc/libutil/openpty.c b/ap/build/uClibc/libutil/openpty.c
new file mode 100644
index 0000000..5f58476
--- /dev/null
+++ b/ap/build/uClibc/libutil/openpty.c
@@ -0,0 +1,157 @@
+/* Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <pty.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* BCS: the following function is, IMO, overkill */
+#if 0
+/* Return the result of ptsname_r in the buffer pointed to by PTS,
+   which should be of length BUF_LEN.  If it is too long to fit in
+   this buffer, a sufficiently long buffer is allocated using malloc,
+   and returned in PTS.  0 is returned upon success, -1 otherwise.  */
+static int
+pts_name (int fd, char **pts, size_t buf_len)
+{
+  int rv;
+  char *buf = *pts;
+
+  for (;;)
+    {
+      char *new_buf;
+
+      if (buf_len)
+	{
+	  rv = ptsname_r (fd, buf, buf_len);
+
+	  if (rv != 0 || memchr (buf, '\0', buf_len))
+	    /* We either got an error, or we succeeded and the
+	       returned name fit in the buffer.  */
+	    break;
+
+	  /* Try again with a longer buffer.  */
+	  buf_len += buf_len;	/* Double it */
+	}
+      else
+	/* No initial buffer; start out by mallocing one.  */
+	buf_len = 128;		/* First time guess.  */
+
+      if (buf != *pts)
+	/* We've already malloced another buffer at least once.  */
+	new_buf = realloc (buf, buf_len);
+      else
+	new_buf = malloc (buf_len);
+      if (! new_buf)
+	{
+	  rv = -1;
+	  __set_errno (ENOMEM);
+	  break;
+	}
+      buf = new_buf;
+    }
+
+  if (rv == 0)
+    *pts = buf;		/* Return buffer to the user.  */
+  else if (buf != *pts)
+    free (buf);		/* Free what we malloced when returning an error.  */
+
+  return rv;
+}
+#endif
+
+/* Create pseudo tty master slave pair and set terminal attributes
+   according to TERMP and WINP.  Return handles for both ends in
+   AMASTER and ASLAVE, and return the name of the slave end in NAME.  */
+libutil_hidden_proto(openpty)
+int
+openpty (int *amaster, int *aslave, char *name, struct termios *termp,
+	 struct winsize *winp)
+{
+#if 0
+#ifdef PATH_MAX
+  char _buf[PATH_MAX];
+#else
+  char _buf[512];
+#endif
+  char *buf = _buf;
+#else
+#ifdef PATH_MAX
+  char buf[PATH_MAX];
+#else
+  char buf[512];
+#endif
+#endif
+  int master, slave;
+
+  master = posix_openpt (O_RDWR);
+  if (master == -1)
+    return -1;
+
+  if (grantpt (master))
+    goto fail;
+
+  if (unlockpt (master))
+    goto fail;
+
+#if 0
+  if (pts_name (master, &buf, sizeof (_buf)))
+#else
+  if (ptsname_r (master, buf, sizeof buf))
+#endif
+    goto fail;
+
+  slave = open (buf, O_RDWR | O_NOCTTY);
+  if (slave == -1)
+    {
+#if 0
+      if (buf != _buf)
+	free (buf);
+#endif
+      goto fail;
+    }
+
+  /* XXX Should we ignore errors here?  */
+  if(termp)
+    tcsetattr (slave, TCSAFLUSH, termp);
+  if (winp)
+    ioctl (slave, TIOCSWINSZ, winp);
+
+  *amaster = master;
+  *aslave = slave;
+  if (name != NULL)
+    strcpy (name, buf);
+
+#if 0
+  if (buf != _buf)
+    free (buf);
+#endif
+  return 0;
+
+ fail:
+  close (master);
+  return -1;
+}
+libutil_hidden_def(openpty)