git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: What's cooking in git.git (Apr 2012, #06; Sun, 15)

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Apr 19, 2012, 13:18 UTC
Message-ID
<CACsJy8DDLmKkBMW_P8RyGTRw=i6OKWZNf-SHoGkVWnJgfK7cVQ@mail.gmail.com>
In-Reply-To
<CABPQNSZ6VdyoLcVUUJ4z5A2A7KGP8qBZAkzdx8zAtAs2mZN25w@mail.gmail.com>
On Thu, Apr 19, 2012 at 7:58 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
Show 6 quoted lines
> This approach has the problem that file-operations apart from pread
> might (at least in theory) modify the position. To prevent that, we'd
> either need to use the same locking-mechanism as the CRT use, or use
> ReadFile with an OVERLAPPED struct, which allows us specify the offset
> explicitly. The latter seems better to me, and should look something
> like this (note: untested):

Yeah. I read about ReadFile [1] but dismissed it when I got to async i/o mode. Reading again, sync i/o ReadFile with OVERLAPPED struct should work fine. It's not clear though if file offset is changed (pread man page says it does not change).

Also this approach deals with Windows only. There's still another NO_PREAD user, HP-UX something, and NO_PREAD comment mentions cygwin before v1.5.22. I personally don't care, just wanted to point out.

[1] http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx
Show 67 quoted lines
> diff --git a/Makefile b/Makefile
> index 2626216..31a5621 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1153,7 +1153,6 @@ endif
>  ifeq ($(uname_S),Windows)
>        GIT_VERSION := $(GIT_VERSION).MSVC
>        pathsep = ;
> -       NO_PREAD = YesPlease
>        NEEDS_CRYPTO_WITH_SSL = YesPlease
>        NO_LIBGEN_H = YesPlease
>        NO_SYS_POLL_H = YesPlease
> @@ -1250,7 +1249,6 @@ ifeq ($(uname_S),Minix)
>  endif
>  ifneq (,$(findstring MINGW,$(uname_S)))
>        pathsep = ;
> -       NO_PREAD = YesPlease
>        NEEDS_CRYPTO_WITH_SSL = YesPlease
>        NO_LIBGEN_H = YesPlease
>        NO_SYS_POLL_H = YesPlease
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 309fa1d..63783db 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -617,6 +617,28 @@ static inline void time_t_to_filetime(time_t t,
> FILETIME *ft)
>        ft->dwHighDateTime = winTime >> 32;
>  }
>
> +ssize_t mingw_pread(int fd, void *buf, size_t size, off_t offset)
> +{
> +       OVERLAPPED overlapped = { 0 };
> +       DWORD ret;
> +
> +       HANDLE fh = (HANDLE)_get_osfhandle(fd);
> +       if (fh == INVALID_HANDLE_VALUE) {
> +               errno = EBADF;
> +               return -1;
> +       }
> +
> +       overlapped.Offset = (DWORD)offset;
> +       overlapped.OffsetHigh = (DWORD)(offset >> 32);
> +
> +       if (!ReadFile(fh, buf, size, &ret, &overlapped)) {
> +               errno = err_win_to_posix(GetLastError());
> +               return -1;
> +       }
> +
> +       return ret;
> +}
> +
>  int mingw_utime (const char *file_name, const struct utimbuf *times)
>  {
>        FILETIME mft, aft;
> diff --git a/compat/mingw.h b/compat/mingw.h
> index c7b2cec..da47302 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -285,6 +285,9 @@ int mingw_fstat(int fd, struct stat *buf);
>  #define _stati64(x,y) mingw_stat(x,y)
>  #endif
>
> +ssize_t mingw_pread(int fd, void *buf, size_t count, off_t offset);
> +#define pread mingw_pread
> +
>  int mingw_utime(const char *file_name, const struct utimbuf *times);
>  #define utime mingw_utime
-- 
Duy
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 13 of 19 in “What's cooking in git.git (Apr 2012, #06; Sun, 15)”
  1. Junio C HamanoApr 16, 2012
  2. Nelson Benitez LeonApr 16, 2012
  3. Junio C HamanoApr 16, 2012
  4. Nelson Benitez LeonApr 16, 2012
  5. Junio C HamanoApr 16, 2012
  6. Johannes SixtApr 18, 2012
  7. Ramsay JonesApr 18, 2012
  8. Johannes SixtApr 19, 2012
  9. Johannes SixtApr 19, 2012
  10. Nguyen Thai Ngoc DuyApr 19, 2012
  11. Nguyen Thai Ngoc DuyApr 19, 2012
  12. Erik Faye-LundApr 19, 2012
  13. Nguyen Thai Ngoc DuyApr 19, 2012
  14. Erik Faye-LundApr 19, 2012
  15. Nguyen Thai Ngoc DuyApr 19, 2012
  16. Johannes SixtApr 19, 2012
  17. Erik Faye-LundApr 19, 2012
  18. Nguyen Thai Ngoc DuyApr 21, 2012
  19. Nguyen Thai Ngoc DuyApr 21, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.