diff options
author | Werner Koch <wk@gnupg.org> | 2007-08-24 11:34:39 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2007-08-24 11:34:39 +0200 |
commit | 503f91e0aea99fe09064e29ec9df1ded1a3bd3c3 (patch) | |
tree | e3dd4b252d6d05a5aa15aea799ab9447ea74ccbd /jnlib | |
parent | Add new features to kbxutil. (diff) | |
download | gnupg2-503f91e0aea99fe09064e29ec9df1ded1a3bd3c3.tar.xz gnupg2-503f91e0aea99fe09064e29ec9df1ded1a3bd3c3.zip |
tryu harder to ignore duplicate specified keyrings and -boxes.
Documentation updates.
Diffstat (limited to 'jnlib')
-rw-r--r-- | jnlib/ChangeLog | 6 | ||||
-rw-r--r-- | jnlib/mischelp.c | 59 | ||||
-rw-r--r-- | jnlib/mischelp.h | 7 | ||||
-rw-r--r-- | jnlib/stringhelp.c | 7 |
4 files changed, 70 insertions, 9 deletions
diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index c7722876b..1d0adec0e 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,9 @@ +2007-08-24 Werner Koch <wk@g10code.com> + + * mischelp.c (same_file_p): New. + (libjnlib_dummy_mischelp_func): Remove as we now always have one + function. + 2007-08-09 Werner Koch <wk@g10code.com> * argparse.c (show_help): Expand the @EMAIL@ macro in the package diff --git a/jnlib/mischelp.c b/jnlib/mischelp.c index b2248288e..f7df5c154 100644 --- a/jnlib/mischelp.c +++ b/jnlib/mischelp.c @@ -1,5 +1,5 @@ /* mischelp.c - Miscellaneous helper functions - * Copyright (C) 1998, 2000, 2001, 2006 Free Software Foundation, Inc. + * Copyright (C) 1998, 2000, 2001, 2006, 2007 Free Software Foundation, Inc. * * This file is part of JNLIB. * @@ -21,16 +21,63 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#ifdef HAVE_W32_SYSTEM +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#else /*!HAVE_W32_SYSTEM*/ +# include <sys/types.h> +# include <sys/stat.h> +# include <unistd.h> +#endif /*!HAVE_W32_SYSTEM*/ #include "libjnlib-config.h" +#include "stringhelp.h" #include "mischelp.h" -/* A dummy function to prevent an empty compilation unit. Some - compilers bail out in this case. */ -time_t -libjnlib_dummy_mischelp_func (void) + +/* Check whether the files NAME1 and NAME2 are identical. This is for + example achieved by comparing the inode numbers of the files. */ +int +same_file_p (const char *name1, const char *name2) { - return time (NULL); + int yes; + + /* First try a shortcut. */ + if (!compare_filenames (name1, name2)) + yes = 1; + else + { +#ifdef HAVE_W32_SYSTEM + HANDLE file1, file2; + BY_HANDLE_FILE_INFORMATION info1, info2; + + file1 = CreateFile (name1, 0, 0, NULL, OPEN_EXISTING, 0, NULL); + if (file1 == INVALID_HANDLE_VALUE) + yes = 0; /* If we can't open the file, it is not the same. */ + else + { + file2 = CreateFile (name2, 0, 0, NULL, OPEN_EXISTING, 0, NULL); + if (file1 == INVALID_HANDLE_VALUE) + yes = 0; /* If we can't open the file, it is not the same. */ + else + { + yes = (GetFileInformationByHandle (file1, &info1) + && GetFileInformationByHandle (file2, &info2) + && info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber + && info1.nFileIndexHigh == info2.nFileIndexHigh + && info1.nFileIndexLow == info2.nFileIndexLow); + CloseHandle (file2); + } + CloseHandle (file1); + } +#else /*!HAVE_W32_SYSTEM*/ + struct stat info1, info2; + + yes = (!stat (name1, &info1) && !stat (name2, &info2) + && info1.st_dev == info2.st_dev && info1.st_ino == info2.st_ino); +#endif /*!HAVE_W32_SYSTEM*/ + } + return yes; } diff --git a/jnlib/mischelp.h b/jnlib/mischelp.h index a00764106..2f003e1ce 100644 --- a/jnlib/mischelp.h +++ b/jnlib/mischelp.h @@ -1,6 +1,6 @@ /* mischelp.h - Miscellaneous helper macros and functions * Copyright (C) 1999, 2000, 2001, 2002, 2003, - * 2006 Free Software Foundation, Inc. + * 2006, 2007 Free Software Foundation, Inc. * * This file is part of JNLIB. * @@ -22,6 +22,11 @@ #define LIBJNLIB_MISCHHELP_H +/* Check whether the files NAME1 and NAME2 are identical. This is for + example achieved by comparing the inode numbers of the files. */ +int same_file_p (const char *name1, const char *name2); + + #ifndef HAVE_TIMEGM #include <time.h> time_t timegm (struct tm *tm); diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index b1f6f73db..e7fd0ce45 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -338,11 +338,14 @@ make_filename( const char *first_part, ... ) } +/* Compare whether the filenames are identical. This is a + specialversion of strcmp() taking the semantics of filenames in + account. Note that this function works only on the supplied names + without considereing any context like the current directory. See + also same_file_p(). */ int compare_filenames (const char *a, const char *b) { - /* ? check whether this is an absolute filename and resolve - symlinks? */ #ifdef HAVE_DRIVE_LETTERS for ( ; *a && *b; a++, b++ ) { |