[U-Boot] [PATCH 1/5 v2.1] sandbox: add lseek helper
Simon Glass
sjg at chromium.org
Wed Feb 15 07:30:53 CET 2012
On Fri, Feb 3, 2012 at 3:26 AM, Mike Frysinger <vapier at gentoo.org> wrote:
> Follow up patches want to be able to seek fd's.
>
> Signed-off-by: Mike Frysinger <vapier at gentoo.org>
>
Acked-by: Simon Glass <sjg at chromium.org>
> ---
> v2.1
> - fix thinko in os_seek_xxx defines
>
> arch/sandbox/cpu/os.c | 13 +++++++++++++
> include/os.h | 15 +++++++++++++++
> 2 files changed, 28 insertions(+), 0 deletions(-)
>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 093e7dc..13331d2 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -45,6 +45,19 @@ ssize_t os_write(int fd, const void *buf, size_t count)
> return write(fd, buf, count);
> }
>
> +off_t os_lseek(int fd, off_t offset, int whence)
> +{
> + if (whence == OS_SEEK_SET)
> + whence = SEEK_SET;
> + else if (whence == OS_SEEK_CUR)
> + whence = SEEK_CUR;
> + else if (whence == OS_SEEK_END)
> + whence = SEEK_END;
> + else
> + printf("%s: invalid whence value %i\n", __func__, whence);
> + return lseek(fd, offset, whence);
> +}
> +
> int os_open(const char *pathname, int flags)
> {
> return open(pathname, flags);
> diff --git a/include/os.h b/include/os.h
> index c17a8a5..f74766d 100644
> --- a/include/os.h
> +++ b/include/os.h
> @@ -49,6 +49,21 @@ ssize_t os_read(int fd, void *buf, size_t count);
> ssize_t os_write(int fd, const void *buf, size_t count);
>
> /**
> + * Access to the OS lseek() system call
> + *
> + * \param fd File descriptor as returned by os_open()
> + * \param offset File offset (based on whence)
> + * \param whence Position offset is relative to (see below)
> + * \return new file offset
>
We mostly use @param and @return I think, but I suppose it doesn't matter
much.
> + */
> +off_t os_lseek(int fd, off_t offset, int whence);
> +
> +/* Defines for "whence" in os_lseek() */
> +#define OS_SEEK_SET 0
> +#define OS_SEEK_CUR 1
> +#define OS_SEEK_END 2
> +
> +/**
> * Access to the OS open() system call
> *
> * \param pathname Pathname of file to open
> --
> 1.7.8.4
>
>
> Regards,
Simon
More information about the U-Boot
mailing list