1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

Renamed g10.c to gpg.c

Filelength fixes for W32.
This commit is contained in:
Werner Koch 2005-10-05 16:58:50 +00:00
parent 98dc48464f
commit bd1df0119c
36 changed files with 2748 additions and 2547 deletions

View file

@ -1,3 +1,9 @@
2005-09-22 Werner Koch <wk@g10code.com>
* iobuf.c (iobuf_get_filelength): New arg OVERFLOW.
(iobuf_get_filelength) [W32]: Use GetFileSizeEx if available.
* fileutil.c (is_file_compressed): Take care of the OVERFLOW
2005-08-31 David Shaw <dshaw@jabberwocky.com>
* fileutil.c (untilde): New. Expand ~/foo and ~username/foo

View file

@ -253,6 +253,7 @@ is_file_compressed( const char *s, int *ret_rc )
IOBUF a;
byte buf[4];
int i, rc = 0;
int overflow;
struct magic_compress_s {
size_t len;
@ -272,7 +273,7 @@ is_file_compressed( const char *s, int *ret_rc )
return 0;
}
if ( iobuf_get_filelength( a ) < 4 ) {
if ( iobuf_get_filelength( a, &overflow ) < 4 && !overflow) {
*ret_rc = 0;
goto leave;
}

View file

@ -41,6 +41,7 @@
#include "memory.h"
#include "util.h"
#include "dynload.h"
#include "iobuf.h"
#undef FILE_FILTER_USES_STDIO
@ -1830,14 +1831,17 @@ iobuf_set_limit( IOBUF a, off_t nlimit )
/****************
* Return the length of an open file
*/
/* Return the length of an open file A. IF OVERFLOW is not NULL it
will be set to true if the file is larger than what off_t can cope
with. The function return 0 on error or on overflow condition. */
off_t
iobuf_get_filelength( IOBUF a )
iobuf_get_filelength (IOBUF a, int *overflow )
{
struct stat st;
if (overflow)
*overflow = 0;
if( a->directfp ) {
FILE *fp = a->directfp;
@ -1855,9 +1859,46 @@ iobuf_get_filelength( IOBUF a )
#if defined(HAVE_DOSISH_SYSTEM) && !defined(FILE_FILTER_USES_STDIO)
ulong size;
static int (* __stdcall get_file_size_ex)
(void *handle, LARGE_INTEGER *size);
static int get_file_size_ex_initialized;
if ((size=GetFileSize (fp, NULL)) != 0xffffffff)
return size;
if (!get_file_size_ex_initialized)
{
void *handle;
handle = dlopen ("kernel32.dll", RTLD_LAZY);
if (handle)
{
get_file_size_ex = dlsym (handle, "GetFileSizeEx");
if (!get_file_size_ex)
dlclose (handle);
}
get_file_size_ex_initialized = 1;
}
if (get_file_size_ex)
{
/* This is a newer system with GetFileSizeEx; we use
this then becuase it seem that GetFileSize won't
return a proper error in case a file is larger than
4GB. */
LARGE_INTEGER size;
if (get_file_size_ex (fp, &size))
{
if (!size.u.HighPart)
return size.u.LowPart;
if (overflow)
*overflow = 1;
return 0;
}
}
else
{
if ((size=GetFileSize (fp, NULL)) != 0xffffffff)
return size;
}
log_error ("GetFileSize for handle %p failed: %s\n",
fp, w32_strerror (0));
#else