Reading whole text files

R

Richard Bos

Eric Sosman said:
No, you cannot. There is no necessary connection
between the number of characters you can read from a
file via a binary stream and the number you can read
from it via a text stream. The "binary count" can be
greater than, equal to, or less than the "text count."

There's that; and then there's the fact that you'll have to read the
entire file before you know how many bytes _or_ characters it contains
in any case, because:

# A binary stream need not meaningfully support fseek calls with a
# whence value of SEEK_END.

Richard
 
R

Richard Bos

data = (c.data) ? realloc (c.data, c.mlen) : malloc (c.mlen);

Erm... you _do_ know that realloc(0, length) is defined by the Standard
to be identical to malloc(length), do you?

Richard
 
F

Flash Gordon

SM said:
# In article <[email protected]>, wyrmwif@tango-sierra-oscar-
# foxtrot-tango.fake.org says...
# > # What happens to contents if this realloc() fails?
# >
# > Subsequent code gets a SIGBUS. Since I work on systems with more virtual memory than
# > the largest files I use, it doesn't happen.
# >
# > If you want to contract me with pay to adapt the code to your system,
#
# With that attitude about error handling, don't hold your breath.

The program forks; if it gets the signal, it does a traceback dump saved to a
database telling what line it failed at and local variables. The parent sees
the child exit, reports it, forks and continues. I've done daemons that run
months at a time, restarting and recoverring when needed.

<snip>

Of course, if you handled the realloc failure and aborted when it
occurred your program would abort at the actual point of failure,
instead of later when you tried to use the memory. It would also be more
portable since it would not rely on the system catching a problem that
you could easily catch.

Mind you, if you had any sense you would not be using # as a quote
character either, since no one reading a C group will ever have a news
reader configured to recognise it as C uses # at the start of lines.
You've been told this before yet continue to be deliberately annoying.
 
S

SM Ryan

# SM Ryan wrote:
# > # In article <[email protected]>, wyrmwif@tango-sierra-oscar-
# > # foxtrot-tango.fake.org says...
# > # > # What happens to contents if this realloc() fails?
# > # >
# > # > Subsequent code gets a SIGBUS. Since I work on systems with more virtual memory than
# > # > the largest files I use, it doesn't happen.
# > # >
# > # > If you want to contract me with pay to adapt the code to your system,
# > #
# > # With that attitude about error handling, don't hold your breath.
# >
# > The program forks; if it gets the signal, it does a traceback dump saved to a
# > database telling what line it failed at and local variables. The parent sees
# > the child exit, reports it, forks and continues. I've done daemons that run
# > months at a time, restarting and recoverring when needed.
#
# <snip>
#
# Of course, if you handled the realloc failure and aborted when it

Look at the code, bright stuff. Immediately after the realloc, it always
stores into the array.

# Mind you, if you had any sense you would not be using # as a quote

Why don't you deal with the trauma of your toilet training in a more
appropriate forum.
 
C

CBFalconer

Flash said:
.... snip ...

Mind you, if you had any sense you would not be using # as a quote
character either, since no one reading a C group will ever have a news
reader configured to recognise it as C uses # at the start of lines.
You've been told this before yet continue to be deliberately annoying.

If everybody just plonked him for it, as I have, the annoyance
would soon disappear.
 
W

Walter Roberson

:Mind you, if you had any sense you would not be using # as a quote
:character either, since no one reading a C group will ever have a news
:reader configured to recognise it as C uses # at the start of lines.
:You've been told this before yet continue to be deliberately annoying.

Hmmm, my newsreader recognizes it without difficulty, just as it
recognizes pretty much any non-whitespace character. How does
your newsreader cope with '>' as a quote character, considering
that '>' is a C operator that could appear on the beginning of a line?

I often use ':' as the quote chracter in cisco newsgroups, and I
haven't had a single complaint there yet, even though the ':' character
is the comment marker for Cisco PIX configurations [which I post a fair
number of.] I haven't had any complaints about quoting sh/ksh scripts
either, even though ':' is a sh/ksh command (similar to no-op but
allows output redirections to be set up.)

As best I can recall, the only time I've ever had a complaint about my
quoting style in -any- newsgroup was from someone who claimed that the
Usenet News RFC's -defined- the quoting character to be '>' and only
'>'. Which is, of course, not correct [it is just a recommendation in
news.announce.newusers, which does not even come close to being a
"standard".]
 
C

CBFalconer

Walter said:
.... snip ...

As best I can recall, the only time I've ever had a complaint about
my quoting style in -any- newsgroup was from someone who claimed
that the Usenet News RFC's -defined- the quoting character to be
'>' and only '>'. Which is, of course, not correct [it is just a
recommendation in news.announce.newusers, which does not even come
close to being a "standard".]

The ':' is just as annoying. There is software (and readers) out
there that reformats quotes, that color codes them to tie them to
attribution lines, etc. This gets all screwed up when people
insist on being inventive. Even worse are the systems that stuff
the initials or identifier from the attribution to the left of the
'>'.

Also there is no need for a blank after the '>' _unless_ this is
the initial quoting of the line.
 
R

Randy Howard

Also there is no need for a blank after the '>' _unless_ this is
the initial quoting of the line.

Are we running out of spaces again? Someone please memcpy some
more and share them.
 
C

CBFalconer

Randy said:
(e-mail address removed)


Are we running out of spaces again? Someone please memcpy some
more and share them.

That is simply a move to prevent quotes falling off the right and
getting wrapped by poorer software.
 
R

Richard Bos

CBFalconer said:
That is simply a move to prevent quotes falling off the right and
getting wrapped by poorer software.

*Shrug* So get a real newsreader.

Richard
 
C

Chris Croughton

That is simply a move to prevent quotes falling off the right and
getting wrapped by poorer software.

Better to insert more spaces and show up the people who over-quote
(except in a cascade, anything with over 4 levels of quoting is probably
worth deleting).

Chris C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top