Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #105568
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Problems with lcc-win32 (trimmed) |
| Date | 2017-03-08 11:51 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87varkyojp.fsf@bsb.me.uk> (permalink) |
| References | (6 earlier) <IXzvA.13541$Ip6.591@fx38.iad> <12e503a2-10a8-471f-bf38-42bff2230221@googlegroups.com> <o9n1j0$m10$1@dont-email.me> <871su81ssa.fsf@bsb.me.uk> <o9op2i$amm$1@dont-email.me> |
jacobnavia <jacob@jacob.remcomp.fr> writes:
> Le 08/03/2017 à 02:06, Ben Bacarisse a écrit :
>> jacobnavia <jacob@jacob.remcomp.fr> writes:
>> <snip>
>>> Here is the code for fseeki64. Could you please compile that and see if it works?
>>>
>>> Thanks
>>> ------------------------------------------------------fseeki64.c
>>> #include <windows.h>
>>> #include <errno.h>
>>> #include <stdio.h>
>>> long long fseeki64(FILE *f,long long offset,int origin)
>>> {
>>> if (f == NULL)
>>> return -1;
>>> fflush(f);
>>> void *handle = (HANDLE)_get_osfhandle(_fileno(f));
>>> long result;
>>> long long r;
>>> LARGE_INTEGER Offset;
>>>
>>> if (handle == (HANDLE)-1) {
>>> errno = EBADF;
>>> return -1;
>>> }
>>> if (origin != 0 && origin != 1 && origin != 2) {
>>> errno = EINVAL;
>>> return -1;
>>> }
>>> memcpy(&Offset,&offset,sizeof(long long));
>>> SetLastError(0);
>>> result = SetFilePointerEx(handle,Offset,(PLARGE_INTEGER)&r,origin);
>>> if (result == 0) {
>>> errno = GetLastError();
>>> }
>>> return !result;
>>> }
>>> ----------------------------------------------------------------------
>>
>> That's a strange bit of code. The strangest thing is the memcpy. I
>> can't see why you'd do that rather than write
>>
>> long result = SetFilePointerEx(handle, offset, NULL, origin);
>>
>> Presumably there is a prototype in scope so offset will be converted to
>> LARGE_INTEGER as if by assignment. If there is no prototype then
>>
>> long result = SetFilePointerEx(handle, (LARGE_INTEGER)offset, NULL, origin);
>>
>> would do, I think. Am I missing something?
>
> Look, I wrote that function under 32 bits windows, some 15 years ago
> at least. What I remember is that LARGE_INTEGER was a STRUCTURE of two
> fields: high and low, of 32 bits each. You can't assign a structure to
> an integer even if they are the same length.
Ah, right, that's exactly the kind of thing I thought I might be
missing. It did not seem likely that on a system with long long ints
you'd have LARGE_INTEGER be anything else (because it sounds like an
integer type), but the interface presumably dates from a time when MS C
did not have 64-bit integers.
It seems that nowadays it's a union so C99 provides a neat way to use
the interface:
SetFilePointerEx(handle, (LARGE_INTEGER){.QuadPart = offset}, NULL, origin);
It's a shame that MS chose a name that suggests an integer type, but
that can't be helped.
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problems with lcc-win32 mertesthomas@gmail.com - 2017-03-05 14:12 -0800
Re: Problems with lcc-win32 luser droog <luser.droog@gmail.com> - 2017-03-05 14:46 -0800
Re: Problems with lcc-win32 gazelle@shell.xmission.com (Kenny McCormack) - 2017-03-05 22:57 +0000
Re: Problems with lcc-win32 jacob navia <jacob@jacob.remcomp.fr> - 2017-03-06 00:49 +0100
Re: Problems with lcc-win32 luser droog <luser.droog@gmail.com> - 2017-03-05 22:10 -0800
Re: Problems with lcc-win32 BartC <bc@freeuk.com> - 2017-03-05 23:32 +0000
Re: Problems with lcc-win32 jacob navia <jacob@jacob.remcomp.fr> - 2017-03-06 00:48 +0100
Re: Problems with lcc-win32 jacob navia <jacob@jacob.remcomp.fr> - 2017-03-06 00:44 +0100
Re: Problems with lcc-win32 BartC <bc@freeuk.com> - 2017-03-06 00:13 +0000
Re: Problems with lcc-win32 Keith Thompson <kst-u@mib.org> - 2017-03-05 19:35 -0800
Re: Problems with lcc-win32 David Brown <david.brown@hesbynett.no> - 2017-03-06 10:26 +0100
Re: Problems with lcc-win32 James Kuyper <jameskuyper@verizon.net> - 2017-03-06 07:08 -0500
Re: Problems with lcc-win32 Keith Thompson <kst-u@mib.org> - 2017-03-06 08:37 -0800
Re: Problems with lcc-win32 David Brown <david.brown@hesbynett.no> - 2017-03-06 21:16 +0100
Re: Problems with lcc-win32 jm.bourguet@gmail.com - 2017-03-06 06:54 -0800
Re: Problems with lcc-win32 David Brown <david.brown@hesbynett.no> - 2017-03-06 17:18 +0100
Re: Problems with lcc-win32 Keith Thompson <kst-u@mib.org> - 2017-03-06 08:42 -0800
Re: Problems with lcc-win32 David Brown <david.brown@hesbynett.no> - 2017-03-06 21:19 +0100
Re: Problems with lcc-win32 jm.bourguet@gmail.com - 2017-03-06 08:44 -0800
Re: Problems with lcc-win32 David Brown <david.brown@hesbynett.no> - 2017-03-06 21:20 +0100
Re: Problems with lcc-win32 mertesthomas@gmail.com - 2017-03-06 00:24 -0800
Re: Problems with lcc-win32 jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-06 18:15 +0100
Re: Problems with lcc-win32 (trimmed) jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-06 18:50 +0100
Re: Problems with lcc-win32 (trimmed) mertesthomas@gmail.com - 2017-03-07 04:50 -0800
Re: Problems with lcc-win32 (trimmed) jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-07 14:54 +0100
Re: Problems with lcc-win32 (trimmed) mertesthomas@gmail.com - 2017-03-07 06:20 -0800
Re: Problems with lcc-win32 (trimmed) scott@slp53.sl.home (Scott Lurndal) - 2017-03-07 15:02 +0000
Re: Problems with lcc-win32 (trimmed) mertesthomas@gmail.com - 2017-03-07 08:00 -0800
Re: Problems with lcc-win32 (trimmed) jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-07 20:30 +0100
Re: Problems with lcc-win32 (trimmed) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-08 01:06 +0000
Re: Problems with lcc-win32 (trimmed) jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-08 12:17 +0100
Assigning a struct to an integer (Was: Problems with lcc-win32 (trimmed)) gazelle@shell.xmission.com (Kenny McCormack) - 2017-03-08 11:40 +0000
Re: Problems with lcc-win32 (trimmed) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-08 11:51 +0000
Re: Problems with lcc-win32 (trimmed) Robert Wessel <robertwessel2@yahoo.com> - 2017-03-07 15:27 -0600
Re: Problems with lcc-win32 (trimmed) scott@slp53.sl.home (Scott Lurndal) - 2017-03-08 13:50 +0000
Re: Problems with lcc-win32 (trimmed) scott@slp53.sl.home (Scott Lurndal) - 2017-03-08 13:51 +0000
csiph-web