Skip to content

Instantly share code, notes, and snippets.

@Milly
Created November 11, 2015 06:28
Show Gist options
  • Save Milly/a4b98dd56b00960a8871 to your computer and use it in GitHub Desktop.
Save Milly/a4b98dd56b00960a8871 to your computer and use it in GitHub Desktop.
Cygwin path conversion API test.
/*
* Cygwin path conversion API test.
*/
#include <sys/cygwin.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef MAX_PATH
# ifdef PATH_MAX
# define MAX_PATH PATH_MAX
# endif
#endif
typedef unsigned char char_u;
int main(int argv, char argc[])
{
int i;
char_u buf[MAX_PATH];
char_u *fname;
char_u *fnames[] = {
".",
"./",
"..",
"../",
"foo",
"foo/",
"foo//",
"/",
"//",
"///",
"/etc",
"/etc/",
"/etc/hosts",
"C:",
"C:/",
"C://",
"C:///",
"C:/Windows",
"C:/Windows/",
"C:\\",
"C:\\\\",
"C:\\\\\\",
"C:\\Windows",
"C:\\Windows\\",
"\\",
"\\\\",
"\\\\\\",
"\\Windows",
"\\Windows\\",
"C:/cygwin",
"C:/cygwin/",
"C:\\cygwin",
"C:\\cygwin\\",
"\\cygwin",
"\\cygwin\\",
"\\\\host",
};
if (getcwd(buf, MAX_PATH))
{
puts(buf);
}
for (i = 0; i < sizeof(fnames) / sizeof(*fnames); ++i)
{
fname = fnames[i];
cygwin_conv_path(CCP_WIN_A_TO_POSIX, fname, buf, MAX_PATH);
printf("%-16s -> %s\n", fname, buf);
}
return 0;
}
/usr/local
. -> /usr/local/
./ -> /usr/local/
.. -> /usr/
../ -> /usr/
..// -> /usr/
foo -> /usr/local/foo
foo/ -> /usr/local/foo/
foo// -> /usr/local/foo/
/ -> /
// -> //
/// -> ///
/etc -> /etc
/etc/ -> /etc/
/etc/hosts -> /etc/hosts
C: -> /cygdrive/c
C:/ -> /cygdrive/c
C:// -> /cygdrive/c/
C:/// -> /cygdrive/c/
C:/Windows -> /cygdrive/c/Windows
C:/Windows/ -> /cygdrive/c/Windows/
C:\ -> /cygdrive/c
C:\\ -> /cygdrive/c/
C:\\\ -> /cygdrive/c/
C:\Windows -> /cygdrive/c/Windows
C:\Windows\ -> /cygdrive/c/Windows/
\ -> /cygdrive/c
\\ -> //
\\\ -> /cygdrive/c/
\Windows -> /cygdrive/c/Windows
\Windows\ -> /cygdrive/c/Windows/
C:/cygwin -> /
C:/cygwin/ -> /
C:\cygwin -> /
C:\cygwin\ -> /
\cygwin -> /
\cygwin\ -> /
\\host -> //host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment