From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 46128 invoked by alias); 7 Dec 2016 22:22:09 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 46119 invoked by uid 89); 7 Dec 2016 22:22:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Dir, volume, H*i:sk:a26c3ed, Serial X-HELO: mail-qk0-f195.google.com Received: from mail-qk0-f195.google.com (HELO mail-qk0-f195.google.com) (209.85.220.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Dec 2016 22:22:02 +0000 Received: by mail-qk0-f195.google.com with SMTP id x190so50653790qkb.0 for ; Wed, 07 Dec 2016 14:22:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=VGE2N4MJrPqqs2XltqXFDbMvcKBm6B2udJQwPmn9rdQ=; b=cGzcGO4gSNxeeQ6TQKU7LSN5CS/GS5PVxGjNAWJM0yCF/Nrn/dtvy0qhUeN2xeHCvK Wsy7WK8DWK1P8No5K81HGXlaLT1Zd9++QlBhhMrAR67BMO8mrztknc6YP4VV0u9bynzD Or2ORYHZ3fJbss5YjO8Ekri9GTzh3LCmfQmNmw4FO0Z9PYZYAXw+LbSviqqDB5n2mcpB ir1OkIqNJWnE2dKM0F60s7ms2aYou5hGI7Hbqj0De0sQjnLRzXL6kgqlCPVgdHd8rWQl 0I7Wt761DLINoI7HAFsiPJrqN0gp4wPKK81PlTRqkjfJ96qBb6HE9EWIVaxsnNiUJTQ2 XQfA== X-Gm-Message-State: AKaTC01b8P8BA4hE+lLSkctF5geW2nET0zAWjahfApbulll6yHL9THfTApB/WQUKycTztf2zwv5HX+qDeB9jVA== X-Received: by 10.55.70.76 with SMTP id t73mr60589681qka.195.1481149320609; Wed, 07 Dec 2016 14:22:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.25.171 with HTTP; Wed, 7 Dec 2016 14:22:00 -0800 (PST) In-Reply-To: References: From: Dipak Gaigole Date: Wed, 07 Dec 2016 22:22:00 -0000 Message-ID: Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016 To: cygwin@cygwin.com Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00075.txt.bz2 >> I am facing a very strange problem with chdir and GetCurrentDirectory. > > Not strange at all. The two are incompatible. When writing Cygwin > programs, stick to the POSIX-y interface, NOT the windows interface. > >> After calling chdir (), the call to GetCurrentDirectory () returns > > chdir() is POSIX, and the POSIX counterpart is getcwd(), which will > return the right value always. GetCurrentDirectory() is the windows > API, which may or may not have a sane value at any given time, but more > often than not does NOT match the value in getcwd(), and that is by > design - because the Cygwin notion of the working directory is more > powerful than the windows notion of the working directory, and it is > just too expensive for cygwin to try and always keep windows up-to-date > with the current directory when there are times that you can be in a > cygwin directory that has no windows counterpart. > That perfectly explains the reason behind the behavior I am facing. > Again, DON'T use windows API calls from a cygwin program, use POSIX > calls instead. You WANT to use getcwd() here. > I dig into the source code history and found that windows APIs are used to make some use case work. Here is the simple usecase: ############################################## C:\Temp\appdir>dir Volume in drive C is C_Drive Volume Serial Number is DE87-B7F1 Directory of C:\Temp\appdir 12/08/2016 03:24 AM . 12/08/2016 03:24 AM .. 12/08/2016 03:18 AM bin 11/13/2014 08:15 PM 3,247,117 cygwin1.dll 12/08/2016 03:06 AM 567 test_cwd.c 12/08/2016 03:12 AM 387,593 test_cwd.exe 3 File(s) 3,635,277 bytes 3 Dir(s) 27,981,082,624 bytes free C:\Temp\appdir>.\test_cwd.exe "bin" chdir (bin) reuturned <0> GetCurrentDirectory returned , ret = <18> getcwd returned , ret = C:\Temp\appdir> ############################################## Please note that I have the cygwin1.dll in the "C:\Temp\appdir" directory. So after changing the directory to "bin", the getcwd() returned "/appdir/bin". And our requirement was to get "/cygdrive/c/temp/appdir/bin", so the GetCurrentDirectory() approach was used. So in this situation, is it possible to get the cwd value as "/cygdrive/c/temp/appdir/bin" using some cygwin API? Thanks, Dipak -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple