Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #28147

Re: Strange Behaviour in finding Size of a File

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Strange Behaviour in finding Size of a File
Date 2012-11-09 12:33 -0800
Organization None to speak of
Message-ID <lny5iajz3p.fsf@nuthaus.mib.org> (permalink)
References <8439d649-fae9-4828-8a86-d0c7c8489aa5@googlegroups.com> <871ug2aa9u.fsf@dpt-info.u-strasbg.fr> <ln7gpulgm9.fsf@nuthaus.mib.org> <87pq3m8snq.fsf@dpt-info.u-strasbg.fr>

Show all headers | View raw


Alain Ketterlin <alain@dpt-info.u-strasbg.fr> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> Alain Ketterlin <alain@dpt-info.u-strasbg.fr> writes:
>>> felix <ckpradip@gmail.com> writes:
>>>> if ( stat ( logFile, &results ) == 0 )
>>>
>>> Use ftell() instead (or lseek() at level 2).
>>
>> What makes you think that will yield better results,
>
> What makes you think it will not. At least ftell() is C.

We know that stat() isn't working as the OP expects.  I'd expect
ftell() to yield exactly the same results -- and it requires opening
the file and seeking to the end of it.  Furthermore, there's no
guarantee in C that the fseek()/ftell() trick will accurately yield
the size of a file.  Binary streams may legally be padded with an
implementation-defined number of null characters (N1370 7.21.2p3),
and "A binary stream need not meaningfully support fseek calls
with a whence value of SEEK_END" (7.21.9.2p3).  For text streams,
the value returned by ftell() isn't necessarily meaningful except
as an argument to fseek() (7.21.9.4p2).

A POSIX environment makes more guarantees -- but as long as you're
depending on POSIX, there's no good reason not to use stat()
(or fstat() or lstat()).

My point is that you suggested ftell() as a solution to the OP's
problem.  It isn't.

>> and what is "level 2"?
>
> Unixism. Just ignore it if it hurts you.

If you're referring to section 2 of the manual (ftell(2),
documentation available via "man 2 ftell"), I've never heard of
that being referred to as "level 2".  Try being a little less
condescending and actually answering the question.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Strange Behaviour in finding Size of a File felix <ckpradip@gmail.com> - 2012-11-08 23:09 -0800
  Re: Strange Behaviour in finding Size of a File "Where's all the China Blue food?" <chine.bleu@yahoo.com> - 2012-11-08 23:26 -0800
  Re: Strange Behaviour in finding Size of a File James Kuyper <jameskuyper@verizon.net> - 2012-11-09 06:56 -0500
    Re: Strange Behaviour in finding Size of a File felix <ckpradip@gmail.com> - 2012-11-12 22:23 -0800
      Re: Strange Behaviour in finding Size of a File James Kuyper <jameskuyper@verizon.net> - 2012-11-13 07:27 -0500
        Re: Strange Behaviour in finding Size of a File felix <ckpradip@gmail.com> - 2012-11-19 01:52 -0800
          Re: Strange Behaviour in finding Size of a File James Kuyper <jameskuyper@verizon.net> - 2012-11-19 08:09 -0500
  Re: Strange Behaviour in finding Size of a File Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-09 08:24 -0500
    Re: Strange Behaviour in finding Size of a File Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:06 -0800
      Re: Strange Behaviour in finding Size of a File Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-11-10 15:12 +0000
        Re: Strange Behaviour in finding Size of a File Ian Collins <ian-news@hotmail.com> - 2012-11-11 08:40 +1300
          Re: Strange Behaviour in finding Size of a File Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-11-10 20:36 +0000
      Re: Strange Behaviour in finding Size of a File Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-10 10:13 -0500
  Re: Strange Behaviour in finding Size of a File John Gordon <gordon@panix.com> - 2012-11-09 15:16 +0000
    Re: Strange Behaviour in finding Size of a File Mark Bluemel <mark_bluemel@pobox.com> - 2012-11-09 15:56 +0000
    Re: Strange Behaviour in finding Size of a File James Kuyper <jameskuyper@verizon.net> - 2012-11-09 11:01 -0500
  Re: Strange Behaviour in finding Size of a File Greg Martin <greg@softsprocket.com> - 2012-11-09 08:59 -0800
  Re: Strange Behaviour in finding Size of a File Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-11-09 19:42 +0100
    Re: Strange Behaviour in finding Size of a File Keith Thompson <kst-u@mib.org> - 2012-11-09 11:29 -0800
      Re: Strange Behaviour in finding Size of a File Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-11-09 20:47 +0100
        Re: Strange Behaviour in finding Size of a File Keith Thompson <kst-u@mib.org> - 2012-11-09 12:33 -0800
          Re: Strange Behaviour in finding Size of a File Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-11-10 02:08 +0100
            Re: Strange Behaviour in finding Size of a File Philip Lantz <prl@canterey.us> - 2012-11-09 18:33 -0800
              Re: Strange Behaviour in finding Size of a File gazelle@shell.xmission.com (Kenny McCormack) - 2012-11-10 02:58 +0000
                Re: Strange Behaviour in finding Size of a File Philip Lantz <prl@canterey.us> - 2012-11-09 23:29 -0800
                Re: Strange Behaviour in finding Size of a File Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:09 -0800
            Re: Strange Behaviour in finding Size of a File Ian Collins <ian-news@hotmail.com> - 2012-11-10 17:46 +1300
              Re: Strange Behaviour in finding Size of a File James Kuyper <jameskuyper@verizon.net> - 2012-11-10 22:20 -0500
              Re: Strange Behaviour in finding Size of a File Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-11-12 14:01 +0200
            Re: Strange Behaviour in finding Size of a File gazelle@shell.xmission.com (Kenny McCormack) - 2012-11-10 22:01 +0000
          Re: Strange Behaviour in finding Size of a File James Kuyper <jameskuyper@verizon.net> - 2012-11-09 22:14 -0500
            Re: Strange Behaviour in finding Size of a File Keith Thompson <kst-u@mib.org> - 2012-11-09 19:24 -0800
              Re: Strange Behaviour in finding Size of a File James Kuyper <jameskuyper@verizon.net> - 2012-11-09 23:30 -0500
              Re: Strange Behaviour in finding Size of a File Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-10 08:32 -0500
                Re: Strange Behaviour in finding Size of a File Ike Naar <ike@sverige.freeshell.org> - 2012-11-10 17:42 +0000
                Re: Strange Behaviour in finding Size of a File Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-10 15:19 -0500
  Re: Strange Behaviour in finding Size of a File Keith Thompson <kst-u@mib.org> - 2012-11-09 11:34 -0800

csiph-web