X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=glafp-utils%2Flndir%2Flndir.c;h=6728638e1cca4a1eff9a0b9b321bf7cabfa56bcb;hb=7828f22403625d456e316dfc42f5a54d33c2390d;hp=0c76558615ce8720758ff8cbdfc9fce4630c83f4;hpb=71844799b1227c0ae92d48e12d0ba17a193baf6f;p=ghc-hetmet.git diff --git a/glafp-utils/lndir/lndir.c b/glafp-utils/lndir/lndir.c index 0c76558..6728638 100644 --- a/glafp-utils/lndir/lndir.c +++ b/glafp-utils/lndir/lndir.c @@ -69,6 +69,10 @@ in this Software without prior written authorization from the X Consortium. #define MAXPATHLEN 2048 #endif +#ifdef __CYGWIN32__ +#include +#endif + #if NeedVarargsPrototypes #include #endif @@ -82,6 +86,8 @@ int ignore_links = 0; /* -ignorelinks */ char *rcurdir; char *curdir; +int force=0; + void quit ( #if NeedVarargsPrototypes @@ -224,7 +230,9 @@ int rel; /* if true, prepend "../" to fn before using */ #endif { /* directory */ +#ifndef __CYGWIN32__ /* don't trust cygwin's n_dirs count */ n_dirs--; +#endif if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) @@ -284,15 +292,22 @@ int rel; /* if true, prepend "../" to fn before using */ } if (symlen >= 0) { - /* Link exists in new tree. Print message if it doesn't match. */ - if (!equivalent (basesymlen>=0 ? basesym : buf, symbuf)) - msg ("%s: %s", dp->d_name, symbuf); - } else { - if (symlink (basesymlen>=0 ? basesym : buf, dp->d_name) < 0) + if (!equivalent (basesymlen>=0 ? basesym : buf, symbuf)) { + if (force) { + unlink(dp->d_name); + if (symlink (basesymlen>=0 ? basesym : buf, dp->d_name) < 0) mperror (dp->d_name); + } else { + /* Link exists in new tree. Print message if it doesn't match. */ + msg ("%s: %s", dp->d_name, symbuf); + } + } + } else { + if (symlink (basesymlen>=0 ? basesym : buf, dp->d_name) < 0) + mperror (dp->d_name); } } - + closedir (df); return 0; } @@ -303,9 +318,20 @@ int ac; char **av; { char *prog_name = av[0]; - char *fn, *tn; + char* tn; struct stat fs, ts; - int force=0; +#ifdef __CYGWIN32__ + /* + The lndir code assumes unix-style paths to work. cygwin + lets you get away with using dos'ish paths (e.g., "f:/oo") + in most contexts. Using them with 'lndir' will seriously + confuse the user though, so under-the-hood, we convert the + path into something POSIX-like. + */ + static char fn[MAXPATHLEN+1]; +#else + char *fn; +#endif while (++av, --ac) { if (strcmp(*av, "-silent") == 0) @@ -326,7 +352,12 @@ char **av; quit (1, "usage: %s [-f] [-silent] [-ignorelinks] fromdir [todir]", prog_name); +#ifdef __CYGWIN32__ + cygwin_conv_to_full_posix_path(av[0], fn); +#else fn = av[0]; +#endif + if (ac == 2) tn = av[1]; else