This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Solved. Odd, is it not? mkdir 'e:\' cannot be undone by rmdir 'e:\' ...
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Sat, 21 Sep 2019 21:02:37 +0000
- Subject: Re: Solved. Odd, is it not? mkdir 'e:\' cannot be undone by rmdir 'e:\' ...
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yHBDGhNo9B4MLI1NTB4Q7Dnl/fBS2IJ2Zvvk0klXGI4=; b=O8Jk3pDb3ZagOc9p402v53i1TWq1NJLp/srcwcLHYfMzzPE/ZROpFTiEZSupEZNWD0jndS+tSFGnEcoFtymHxrJ29hbX3lIc/PWFKsDW7+H1vqoEhkVarNqX+xhEvbcQ4r/Lk8NGpRjAP2dp1sRoaUd9CiYC4wTVdPUy9DDxPQOJDGGCMSZZwAGuFPPLxLss+UA/gfvzKgwOMn4/o0EQw2V7kq3dcA6aARyPFp2MZaVtZrqeBDPk1G8OA640ocRhDiseoZqRVGhDNmRBZyEAFUDLsTy/yqCqX/zaMwDeYYWPcHZUdnBnJ2S0+IRrf/nJ3hK0Y2MXjz+pZJAtiDRN5w==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SJR/ahW5S7WurVWZs1yB7mI0ExhDXwA7JA4z3kbeBZlEbqDA6Zk6rLMA6vHQHdPPTusS8GeatvgbwslefmKinsZsReJvxP1fxEupKm+mQ1nacMdR6d9NnsQgt6g114oF9IW6R1IKNzoKUrN/697L5xzOCqo1iSqDW31AYkf17GUzIFPrDQn3PEW6i4Ghvrt+GmlCPlrDI8YxKhZOQrM5T8jLRnrxdBEI/i+xUNX9rNv3snsNUcCu4QHfxEVu+nSuZ2EtigGLIs9dC6xG7mCkfwIhyYqokrxNfhyKHtdRGf+GkcyPZkurfMC3Y85yTWq1oWBjdv7nIx/TUFpC6/A0BQ==
- References: <8e310c59702b57501ca2fd80edf19d2e@smtp-cloud9.xs4all.net>
On 9/6/2019 5:53 PM, Houder wrote:
> However an exception can be made for e:/ (or e:\), as follows:
>
> --
> char flag = '\0';
> // strip trailing dirsep's, while remembering the last one
> if (isdirsep (dir[strlen (dir) - 1]))
> {
> flag = dir[strlen (dir) - 1];
> /* This converts // to /, but since both give EEXIST, we're okay. */
> char *buf;
> char *p = stpcpy (buf = tp.c_get (), dir) - 1;
> dir = buf;
> while (p > dir && isdirsep (*p))
> {
> flag = *p;
> *p-- = '\0';
> }
> }
>
> // reattach dirsep in case of x: and flag != '\0'
> if ( (strlen (dir) == 2)
> && (dir[1] == ':')
> && isalpha (dir[0]) && flag != '\0' )
> {
> char *buf = tp.c_get ();
> buf[0] = dir[0];
> buf[1] = ':';
> buf[2] = flag;
> buf[3] = '\0';
> dir = buf;
> }
I think you can simplify this by eliminating the second part and changing the
first part to the following:
char sep = dir[strlen (dir) - 1];
if (isdirsep (sep)
{
/* This converts // to /, but since both give EEXIST, we're okay. */
char *buf;
char *p = stpcpy (buf = tp.c_get (), dir) - 1;
dir = buf;
while (p > dir && isdirsep (*p))
*p-- = '\0';
/* Reattach dirsep in case of "x:". */
if (p == dir + 1 && *p == ':' && isalpha (dir[0]))
p[1] = sep;
}
Ken
--
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