From patchwork Wed Jan 11 14:23:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 135394 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 2791FB6EF2 for ; Thu, 12 Jan 2012 01:24:23 +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=1326896664; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=RkMAYEv2ocVMvg/7kUkkO9t9dsU=; b=Jy1HBo1EeXOCNvB AUJTl9wbecuX+oiGh98VnL8P2lq4AKuqzz4Cz9G8RuwS58ukojla1YtJT0XJFGHX 9LUzqlzscO6SwzCs4JKw5OMxf4Rewpnf+aWBoYRpc9pXxmIIo7NWrt1IkAOxV32T bELO12vKgogSjqetwKsxI5GCXRPY= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=yTGK4C1vILe295FKSrz3nbl7C91vzKYPzdh4TKInEDRggfh/r31+4RUEllIFFc ZSkT3oRAh1CNDmPfyTUVU1gdv4e2KtmWPQxr0pUDHASPX3YV7yDSFgZYgn7Nx8MQ NQeeAoLSUUPiPhzlls+oGfFW0vxSXWc3v7CzakP7e+eyM=; Received: (qmail 402 invoked by alias); 11 Jan 2012 14:24:10 -0000 Received: (qmail 382 invoked by uid 22791); 11 Jan 2012 14:24:08 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_RG X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jan 2012 14:23:55 +0000 Received: from [192.168.178.22] (port-92-204-59-150.dynamic.qsc.de [92.204.59.150]) by mx02.qsc.de (Postfix) with ESMTP id 2CABC219E4; Wed, 11 Jan 2012 15:23:53 +0100 (CET) Message-ID: <4F0D9B78.7090600@net-b.de> Date: Wed, 11 Jan 2012 15:23:52 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111220 Thunderbird/9.0 MIME-Version: 1.0 To: Janne Blomqvist CC: Fortran List , GCC Patches Subject: Re: [Patch libfortran] PR 51803 getcwd() failure References: <4F0D424F.4030808@net-b.de> <4F0D86B2.1080509@net-b.de> <4F0D9708.509@net-b.de> In-Reply-To: <4F0D9708.509@net-b.de> 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 Same patch with a minor update: I changed "cwd" from "char *" to "const char *" as I spotted a compile time warning for cwd = "."; which was along the lines that by the assignment the const qualifier is lost. Too bad that we cannot enable -Werror for libgfortran. On 01/11/2012 03:04 PM, Tobias Burnus wrote: > I had a quick chat with Kai and decided to leave the lower part as is. > However, I realized that the check for an absolute path is not correct > for Windows. With the help of Kai I came up with the attached version. > > OK for the trunk? 2012-01-11 Tobias Burnus * runtime/main.c (store_exe_path): Fix absolute path detection for Windows. Index: libgfortran/runtime/main.c =================================================================== --- libgfortran/runtime/main.c (revision 183093) +++ libgfortran/runtime/main.c (working copy) @@ -86,7 +86,8 @@ store_exe_path (const char * argv0) #define DIR_SEPARATOR '/' #endif - char buf[PATH_MAX], *cwd, *path; + char buf[PATH_MAX], *path; + const char *cwd; /* This can only happen if store_exe_path is called multiple times. */ if (please_free_exe_path_when_done) @@ -105,15 +106,22 @@ store_exe_path (const char * argv0) } #endif - /* On the simulator argv is not set. */ - if (argv0 == NULL || argv0[0] == '/') + /* If the path is absolute or on an simulator where argv is not set. */ +#ifdef __MINGW32__ + if (argv0 == NULL + || ('A' <= argv0[0] && argv0[0] <= 'Z' && argv0[1] == ':') + || ('a' <= argv0[0] && argv0[0] <= 'z' && argv0[1] == ':') + || (argv0[0] == '/' && argv0[1] == '/') + || (argv0[0] == '\\' && argv0[1] == '\\')) +#else + if (argv0 == NULL || argv0[0] == DIR_SEPARATOR) +#endif { 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)