From: Junio C Hamano <gitster@pobox.com>
To: Marius Storm-Olsen <mstormo@gmail.com>
Cc: Johannes.Schindelin@gmx.de, msysgit@googlegroups.com,
git@vger.kernel.org, lznuaa@gmail.com
Subject: Re: [PATCH 14/17] Add ftruncate implementation for MSVC
Date: Mon, 14 Sep 2009 12:48:41 -0700 [thread overview]
Message-ID: <7vws41b946.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <c95a367520435feec0833d2d0edc33d86cf939a8.1252925290.git.mstormo@gmail.com> (Marius Storm-Olsen's message of "Mon\, 14 Sep 2009 15\:11\:27 +0200")
Marius Storm-Olsen <mstormo@gmail.com> writes:
> The MSVC Posix implementation doesn't contain ftruncate, so add our own
> which can handle large files (64bit offsets).
>
> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
> ---
> compat/msvc.c | 8 ++++++++
> compat/msvc.h | 2 ++
> 2 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/compat/msvc.c b/compat/msvc.c
> index ac04a4c..b96b045 100644
> --- a/compat/msvc.c
> +++ b/compat/msvc.c
> @@ -32,4 +32,12 @@ int closedir(DIR *dir)
> return 0;
> }
>
> +int ftruncate(int fd, __int64 length)
> +{
> + HANDLE fh = (HANDLE)_get_osfhandle(fd);
> + if (!fh || _lseeki64(fd, length, SEEK_SET))
> + return -1;
> + return SetEndOfFile(fh) ? 0 : -1;
> +}
> +
Wouldn't it break this toy program? ftruncate() should preserve the file
offset and use of the seek in the above feels iffy.
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main(int ac, char **av)
{
int fd = open("testfile", O_CREAT|O_WRONLY, 0666);
if (fd < 0)
exit(1);
write(fd, "abcdefghijklmnopqrstuvwxyz\n", 27);
lseek(fd, 7, SEEK_SET);
write(fd, "H", 1);
ftruncate(fd, 24);
write(fd, "IJ", 2);
close(fd);
exit(0);
}
The only two in-tree users of ftruncate() do not care about this, though.
They both seek to the beginning and then truncate to zero length.
next prev parent reply other threads:[~2009-09-14 19:49 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-14 13:11 [RFC/PATCH v2 00/17] Build Git with MSVC Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 01/17] Avoid declaration after statement Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 03/17] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++ Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 04/17] Add define guards to compat/win32.h Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 05/17] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 09/17] Add empty header files for MSVC port Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 10/17] Add MinGW header files to build git with MSVC Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 11/17] Add platform files for MSVC porting Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 12/17] Make usage of windows.h lean and mean Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 13/17] Define strncasecmp as _strnicmp for MSVC Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 14/17] Add ftruncate implementation " Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 15/17] Add MSVC to Makefile Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 16/17] Add README for MSVC build Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 17/17] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Marius Storm-Olsen
2009-09-14 14:06 ` [PATCH 15/17] Add MSVC to Makefile Alex Riesen
2009-09-14 19:09 ` Marius Storm-Olsen
2009-09-14 14:18 ` [PATCH 14/17] Add ftruncate implementation for MSVC Alex Riesen
2009-09-14 19:03 ` Marius Storm-Olsen
2009-09-14 19:48 ` Junio C Hamano [this message]
2009-09-14 19:31 ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Junio C Hamano
2009-09-14 19:42 ` Marius Storm-Olsen
2009-09-14 20:00 ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Johannes Sixt
2009-09-15 0:24 ` [msysGit] " Johannes Schindelin
2009-09-15 5:59 ` Marius Storm-Olsen
2009-09-14 19:06 ` [msysGit] [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Alexey Borzenkov
2009-09-14 13:41 ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
2009-09-14 13:59 ` [PATCH 01/17] Avoid declaration after statement Alex Riesen
2009-09-14 14:01 ` Marius Storm-Olsen
2009-09-14 14:04 ` Frank Li
2009-09-14 14:10 ` Alex Riesen
2009-09-14 19:00 ` Marius Storm-Olsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vws41b946.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=lznuaa@gmail.com \
--cc=mstormo@gmail.com \
--cc=msysgit@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).