From patchwork Wed Jan 11 13:08:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 135383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 37506B6EEA for ; Thu, 12 Jan 2012 00:09:10 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1326892151; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=2tAfOO+X4iaIdoRWqcxdkvt117U=; b=tHmcGZGAPM486aUlM4UYPdZFkm4HsvfLkrBfpYQ7PGC7QMGj+gvq+xJTOixQng LFDscSLDBKtF6Li1AzPeLu+fsEYgj2CZ4RKERNP0OoxYa91BbyAvIC6SAUoRzMO7 GsuSpx13nCQ8hr89WVxajadbO0RoJ2Mh6UY4hBKxrKE3o= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cwEWXrXJt8DYNJ/8XqWZWWOTwe7Jhcf535bdD3Bm0iMBeDtHcgKYCenxl70VEe nZXEwqbH92yK3hgDuan7cAgNzdkuw0lSXwVnku/7X/gMBpcJBKuPK19XNP7qXOjl iqgkV+H+NTyeD6NFJd2fiSYfR5iM3ClIRxE7/zcdZtJYo=; Received: (qmail 23521 invoked by alias); 11 Jan 2012 13:09:00 -0000 Received: (qmail 23337 invoked by uid 22791); 11 Jan 2012 13:08:59 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_RG X-Spam-Check-By: sourceware.org Received: from mail-lpp01m010-f47.google.com (HELO mail-lpp01m010-f47.google.com) (209.85.215.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jan 2012 13:08:46 +0000 Received: by lami14 with SMTP id i14so280365lam.20 for ; Wed, 11 Jan 2012 05:08:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.146.99 with SMTP id tb3mr11381326lab.7.1326287324116; Wed, 11 Jan 2012 05:08:44 -0800 (PST) Received: by 10.152.11.198 with HTTP; Wed, 11 Jan 2012 05:08:44 -0800 (PST) In-Reply-To: <4F0D86B2.1080509@net-b.de> References: <4F0D424F.4030808@net-b.de> <4F0D86B2.1080509@net-b.de> Date: Wed, 11 Jan 2012 15:08:44 +0200 Message-ID: Subject: Re: [Patch libfortran] PR 51803 getcwd() failure From: Janne Blomqvist To: Tobias Burnus Cc: Fortran List , GCC Patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Wed, Jan 11, 2012 at 14:55, Tobias Burnus wrote: > Dear all, > > this is a follow up patch, which I think provides a better handling if > either getcwd fails or is not availble - or if the pathname in argv[0] > already is an absolute patch, in which case concatenating > current-working-directory + '/' + argv[0] does not really make sense. Checking for an absolute path is already done a few lines up. So if you prefer the kind of approach that you have in your patch, IMHO a more correct patch would be Also, I removed the memset() call as superfluous; getcwd() makes sure that the buffer is null terminated or it will return NULL instead of a pointer to the string. For my part this fixed patch would be Ok. Index: main.c =================================================================== --- main.c (revision 183091) +++ main.c (working copy) @@ -106,22 +106,26 @@ #endif /* On the simulator argv is not set. */ - if (argv0 == NULL || argv0[0] == '/') + if (argv0 == NULL || argv0[0] == DIR_SEPARATOR) { exe_path = argv0; please_free_exe_path_when_done = 0; return; } - memset (buf, 0, sizeof (buf)); #ifdef HAVE_GETCWD cwd = getcwd (buf, sizeof (buf)); - if (!cwd) - cwd = "."; #else - cwd = "."; + cwd = NULL; #endif + if (!cwd) + { + exe_path = argv0; + please_free_exe_path_when_done = 0; + return; + } + /* exe_path will be cwd + "/" + argv[0] + "\0". This will not work if the executable is not in the cwd, but at this point we're out of better ideas. */