From owner-svn-src-head@FreeBSD.ORG Sun Feb 15 21:41:31 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9B4ED296; Sun, 15 Feb 2015 21:41:31 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7AE39C1E; Sun, 15 Feb 2015 21:41:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1FLfV1i073162; Sun, 15 Feb 2015 21:41:31 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1FLfU3X073158; Sun, 15 Feb 2015 21:41:30 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201502152141.t1FLfU3X073158@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sun, 15 Feb 2015 21:41:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278818 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Feb 2015 21:41:31 -0000 Author: jilles Date: Sun Feb 15 21:41:29 2015 New Revision: 278818 URL: https://svnweb.freebsd.org/changeset/base/278818 Log: sh: Add stsavestr(), like savestr() but allocates using stalloc(). Modified: head/bin/sh/cd.c head/bin/sh/expand.c head/bin/sh/memalloc.c head/bin/sh/memalloc.h Modified: head/bin/sh/cd.c ============================================================================== --- head/bin/sh/cd.c Sun Feb 15 21:28:00 2015 (r278817) +++ head/bin/sh/cd.c Sun Feb 15 21:41:29 2015 (r278818) @@ -182,7 +182,6 @@ cdlogical(char *dest) struct stat statb; int first; int badstat; - size_t len; /* * Check each component of the path. If we find a symlink or @@ -190,9 +189,7 @@ cdlogical(char *dest) * next time we get the value of the current directory. */ badstat = 0; - len = strlen(dest); - cdcomppath = stalloc(len + 1); - memcpy(cdcomppath, dest, len + 1); + cdcomppath = stsavestr(dest); STARTSTACKSTR(p); if (*dest == '/') { STPUTC('/', p); @@ -277,7 +274,6 @@ findcwd(char *dir) { char *new; char *p; - size_t len; /* * If our argument is NULL, we don't know the current directory @@ -286,9 +282,7 @@ findcwd(char *dir) */ if (dir == NULL || curdir == NULL) return getpwd2(); - len = strlen(dir); - cdcomppath = stalloc(len + 1); - memcpy(cdcomppath, dir, len + 1); + cdcomppath = stsavestr(dir); STARTSTACKSTR(new); if (*dir != '/') { STPUTS(curdir, new); Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Sun Feb 15 21:28:00 2015 (r278817) +++ head/bin/sh/expand.c Sun Feb 15 21:41:29 2015 (r278818) @@ -1284,11 +1284,8 @@ addfname(char *name) { char *p; struct strlist *sp; - size_t len; - len = strlen(name); - p = stalloc(len + 1); - memcpy(p, name, len + 1); + p = stsavestr(name); sp = (struct strlist *)stalloc(sizeof *sp); sp->text = p; *exparg.lastp = sp; Modified: head/bin/sh/memalloc.c ============================================================================== --- head/bin/sh/memalloc.c Sun Feb 15 21:28:00 2015 (r278817) +++ head/bin/sh/memalloc.c Sun Feb 15 21:41:29 2015 (r278818) @@ -180,6 +180,18 @@ stunalloc(pointer p) } +char * +stsavestr(const char *s) +{ + char *p; + size_t len; + + len = strlen(s); + p = stalloc(len + 1); + memcpy(p, s, len + 1); + return p; +} + void setstackmark(struct stackmark *mark) Modified: head/bin/sh/memalloc.h ============================================================================== --- head/bin/sh/memalloc.h Sun Feb 15 21:28:00 2015 (r278817) +++ head/bin/sh/memalloc.h Sun Feb 15 21:41:29 2015 (r278818) @@ -52,6 +52,7 @@ void ckfree(pointer); char *savestr(const char *); pointer stalloc(int); void stunalloc(pointer); +char *stsavestr(const char *); void setstackmark(struct stackmark *); void popstackmark(struct stackmark *); char *growstackstr(void);