Re: Getting a string from a file or socket

Julien R Pierre - Sun Microsystems <[email protected]>
Newsgroups gmane.comp.mozilla.devel.nspr
Message-ID <[email protected]>
Joachim,

Joachim Ziegler wrote:
> I am missing a function like
> 
>    char *fgets(char *s, int size, FILE *stream);
> 
> in NSPR, which reads characters from a file or socket and stops when it
> encounters an EOF or newline, storing the characters read in a 0-byte
> terminated buffer. This is a very common task in server programming. I
> do not want do (re-)implement it.
> 
> Any ideas? Shouldn't such a basic operation included in the library? As
> far as I can see, NSPR only offers the very basic PR_Read().
> 
> Joachim

I don't believe it does. It should be fairly simple for you to implement 
that function on top of PR_Read.

One of the reasons for this not being included in NSPR may be that the 
EOL characters are platform-specific.

Having done a lot of server programming with NSPR, I can also say that I 
would not use a generic function to perform this task - each protocol 
RFC is different and allows a certain number of newlines, spaces, etc. 
You are better off using the binary PR_Read or PR_Recv functions, and 
doing exactly what you want on top of it.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.