* fhandler.h (class fhandler_dev_random): Add dummy_offset member.

* fhandler_random.cc (fhandler_dev_random::lseek): Fake seeking
	capability as on Linux.
This commit is contained in:
Corinna Vinschen 2007-12-22 13:26:47 +00:00
parent ec62ba9577
commit 04cb518d64
3 changed files with 33 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2007-12-22 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_dev_random): Add dummy_offset member.
* fhandler_random.cc (fhandler_dev_random::lseek): Fake seeking
capability as on Linux.
2007-12-20 Eric Blake <ebb9@byu.net>
* libc/memmem.cc (memmem): Fix bug when searching for empty string.

View File

@ -1090,6 +1090,7 @@ class fhandler_dev_random: public fhandler_base
protected:
HCRYPTPROV crypt_prov;
long pseudo;
_off64_t dummy_offset;
bool crypt_gen_random (void *ptr, size_t len);
int pseudo_write (const void *ptr, size_t len);

View File

@ -12,6 +12,7 @@ details. */
#include "winsup.h"
#include <limits.h>
#include <unistd.h>
#include "cygerrno.h"
#include "security.h"
#include "path.h"
@ -34,6 +35,7 @@ fhandler_dev_random::open (int flags, mode_t)
set_flags ((flags & ~O_TEXT) | O_BINARY);
nohandle (true);
set_open_status ();
dummy_offset = 0;
return 1;
}
@ -140,9 +142,31 @@ fhandler_dev_random::read (void *ptr, size_t& len)
}
_off64_t
fhandler_dev_random::lseek (_off64_t, int)
fhandler_dev_random::lseek (_off64_t off, int whence)
{
return 0;
/* As on Linux, fake being able to set an offset. The fact that neither
reading nor writing changes the dummy offset is also the same as on
Linux (tested with kernel 2.6.23). */
_off64_t new_off;
switch (whence)
{
case SEEK_SET:
new_off = off;
break;
case SEEK_CUR:
new_off = dummy_offset + off;
break;
default:
set_errno (EINVAL);
return (_off64_t) -1;
}
if (new_off < 0)
{
set_errno (EINVAL);
return (_off64_t) -1;
}
return dummy_offset = new_off;
}
int