Re: How to deal with big-size files??



On Dec 31, 9:48 am, jameskuy...@xxxxxxxxxxx wrote:
åäÏÇæì wrote:
What can i do to open , write and seek in file with size 2 GB or more

I know that you r limited with int type size which is 32-bit but how
programs like gzip , zip read and write from files with big size like
2-GB

 how can i break this limit in C or even C++

The size of an int isn't relevant; the relevant functions are fseek()
and ftell(), and they use long, not int.
'long' is only guaranteed to be at least 32 bits; it can be larger
than that, and on many systems it is. On systems where 'long' is a 64-
bit type, there is no problem (for now - wait a few decades and even
64 bits might not be enough).

I'm not very familiar with systems where files can be greater than
2GB, but long is too small to hold a file length, so I'll let others
tell you what to do in that case. However, in principle even when
'long' is only 32 bits, you could handle files longer than 2GB by
using fgetpos() and fsetpos() instead of fseek() and ftell(). The
interface is clumsier, but it's still workable. However, I know that
on at least some systems, the ability to work in that fashion to
handle files larger than 2GB is deliberately disabled; you have to use
special functions that are not defined by the C standard to access the
part of a long file that is after an offset of LONG_MAX.

Hence, the FAQ:

12.25: What's the difference between fgetpos/fsetpos and ftell/fseek?
What are fgetpos() and fsetpos() good for?

A: ftell() and fseek() use type long int to represent offsets
(positions) in a file, and may therefore be limited to offsets
of about 2 billion (2**31-1). The newer fgetpos() and
fsetpos()
functions, on the other hand, use a special typedef, fpos_t,
to
represent the offsets. The type behind this typedef, if
chosen
appropriately, can represent arbitrarily large offsets, so
fgetpos() and fsetpos() can be used with arbitrarily huge
files.
fgetpos() and fsetpos() also record the state associated with
multibyte streams. See also question 1.4.

References: K&R2 Sec. B1.6 p. 248; ISO Sec. 7.9.1,
Secs. 7.9.9.1,7.9.9.3; H&S Sec. 15.5 p. 252.
.



Relevant Pages

  • Re: Dr Dobbs snippet
    ... so it was probably an invention of the C ... What are fgetpos() and fsetpos() good for? ... represent the offsets. ...
    (comp.lang.c)
  • Re: Programming in standard c
    ... If the compression is made transparent ... What are fgetpos() and fsetpos() good for? ... ftelland fseekuse type long int to represent offsets ...
    (comp.lang.c)
  • Re: string search?
    ... Look up ftell, fseek, fgetpos, and fsetpos. ...
    (comp.lang.c)
  • Re: File size > 4 GB
    ... You can try fpos_t with fgetpos and fsetpos. ... She broke your heart and inadvertendently drove men to deviant lifestyles. ...
    (comp.lang.c)
  • Re: string search?
    ... Look up ftell, fseek, fgetpos, and fsetpos. ...
    (comp.lang.c)