This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Solved. Odd, is it not? mkdir 'e:\' cannot be undone by rmdir 'e:\' ...


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]