Date: Thu, 19 Jun 1997 15:32:05 +0200 (METDST) From: Robert Hoehne To: DJGPP workers Subject: symlink patch (6/6) Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk --- src/libc/posix/unistd/symlink.c~ Thu Sep 19 22:40:46 1996 +++ src/libc/posix/unistd/symlink.c Wed Jun 18 16:33:56 1997 @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -29,6 +30,31 @@ return p; } +/* + This returns + -1, when the file does not exist + 0, when it is not a v2 executable + 1, when it is a v2 executable +*/ + +static int is_v2_prog(const char *program) +{ + const _v2_prog_type *type; + + type = _check_v2_prog (program, -1); + + if (!type->valid) + return -1; + + if (type->object_format != _V2_OBJECT_FORMAT_COFF) + return 0; + + if (type->version.v.major < 2) + return 0; + + return 1; +} + /* Support the DJGPP ``symlinks'' for .exe files. */ int symlink (const char *source, const char *dest) @@ -38,6 +64,8 @@ char *np, ropt[FILENAME_MAX+15]; /* some extra for ``runfile='' */ const char *src_base, *dest_base; + int v2_prog = 0; + _fixpath (source, src_abs); _fixpath (dest, dest_abs); src_base = tail (src_abs); @@ -54,11 +82,38 @@ if (stricmp (src_abs, dest_abs) == 0) return 0; + /* Check at first, if the given name is a v2 executable (may be + unstubbed COFF image) */ + v2_prog = is_v2_prog(src_abs); + + /* It is an existing file but no v2 executable */ + if (v2_prog == 0) + { + errno = EXDEV; + return -1; + } + /* Allow to say `ln -s src dest' when we really mean `src.exe' and `dest.exe' */ np = src_abs + strlen (src_abs) - 4; if (stricmp (np, EXE_SUFFIX)) + { strcat (src_abs, EXE_SUFFIX); + /* Now test again for v2 executable, but only if not already + succeed. */ + v2_prog = v2_prog == 1 ? v2_prog : is_v2_prog(src_abs); + } + + /* It is an existing file but no v2 executable */ + if (v2_prog == 0) + { + errno = EXDEV; + return -1; + } + + /* When we are here, either the file exists and is a v2 executable + or it does not exist and we hope, the the user knows what he + does. */ /* Under LFN, we need the short version of the program name, since that is what the stub stores (and what a program gets in its argv[0]). */