From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HKdje-0003TI-ME for qemu-devel@nongnu.org; Fri, 23 Feb 2007 11:57:30 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HKdjc-0003T4-A1 for qemu-devel@nongnu.org; Fri, 23 Feb 2007 11:57:29 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HKdjc-0003T1-4V for qemu-devel@nongnu.org; Fri, 23 Feb 2007 11:57:28 -0500 Received: from phoenix.bawue.net ([193.7.176.60] helo=mail.bawue.net) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HKdjb-0007uE-ML for qemu-devel@nongnu.org; Fri, 23 Feb 2007 11:57:27 -0500 Date: Fri, 23 Feb 2007 16:58:56 +0000 Subject: Re: [Qemu-devel] [PATCH] [REPOST] Simplily linux-user/path.c Message-ID: <20070223165856.GC2521@networkno.de> References: <20070219130409.GD25556@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070219130409.GD25556@localhost.localdomain> From: Thiemo Seufer Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Kirill A. Shutemov" Cc: qemu-devel@nongnu.org Kirill A. Shutemov wrote: > Fixed version of the patch in the attacment. Please, comment. [snip] > /* Look for path in emulation dir, otherwise return name. */ > const char *path(const char *name) > { > + char *newname = (char *) alloca(strlen(pref)+strlen(name)+1); > + struct stat buf; > /* Only do absolute paths: quick and dirty, but should mostly be OK. > Could do relative by tracking cwd. */ > - if (!base || name[0] != '/') > - return name; > + if (!pref || name[0] != '/') > + return name; > + > + strcpy(newname,pref); > + strcat(newname,name); > > - return follow_path(base, name) ?: name; > + return stat(newname,&buf) ? name : strdup(newname); > } This leaks memory allocated by strdup(). Also, the old code tries to avoid syscalls by memorizing the paths. AFAICS we should do some caching here. Thiemo