Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What is the most efficient way?

Name: Anonymous 2008-05-13 23:06

Ok, so I have socket in C, and I want to read one line from the socket, not including the ending new line. I want to write a function that returns a malloc'd string containing the line.

Name: Anonymous 2008-05-13 23:07

ok

Name: Anonymous 2008-05-13 23:12

Use a buffer

Name: Anonymous 2008-05-13 23:18

>>3
by buffer, do you mean a linked list...

Name: Anonymous 2008-05-13 23:34

don't malloc; malloc is slow.
Allocate once, then put all data you need in this buffer

Name: Anonymous 2008-05-13 23:39

>>5
what if the line is bigger than this bufer

Name: Anonymous 2008-05-13 23:41

>>6
make sure it isn't.

Name: Anonymous 2008-05-13 23:43

FFS
Use a dynamic array that grows by a factor of 2
Read some shit from the socket into the array
Stop when you hit EOL

Name: Anonymous 2008-05-13 23:48

FUCK THIS IM JUST GONNA USE THE GLIB STRING FUNCTIONS
YOU GUYS ARE UN HELPFUL AND ULTIMATELY DESTRUCTIVe

Name: Anonymous 2008-05-13 23:52

fgets

Name: Anonymous 2008-05-13 23:54

>>1
fdopen() the socket and use GNU's getline().
It's really dumb to do so thought. You *really* don't want to read an arbitrary line from a socket.

Name: Anonymous 2008-05-14 0:05

>>11
why?

Name: Anonymous 2008-05-14 0:28

>>12

he's lying to you

Name: Anonymous 2008-05-14 0:29

>>12
A million of fucking reasons, oh my fucking god do I really have to explain you why? Remote DOS attacks you fucking moron. God dammit.

Name: Anonymous 2008-05-14 1:18

I don't understand networks :(

Name: Anonymous 2008-05-14 3:24

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *get_line_from_stream(FILE *stream){
 size_t len = 0;
 char *line = fgetln(stream, &len);
 char *res = calloc(line[len - 1] == '\n' ? len-- : len + 1, sizeof(char));
 strncpy(res, line, len);
 res[len] = '\0';
 return res;
}

Name: Anonymous 2008-05-14 5:20

>>15
What don't you understand about them?

Name: Anonymous 2008-05-14 6:18

>>16
You should probably filter out '\r' there too.

Name: Anonymous 2008-05-14 6:22

>>16
No such function as fgetln() in standard C, "fget".

Name: Anonymous 2008-05-14 6:30

>>19
There are no sockets in standard C either.  ∴ this thread doesn't exist, and you're only trolling yourself.

Name: Anonymous 2008-05-14 6:32

>>19
I think you're thinking of fgets(), which is pretty fucking useless.
fgetln() isn't in standard C, but it works on every operating system that isn't complete shit.

Name: Anonymous 2008-05-14 6:45

>>21
3) fuh-gets

Name: Anonymous 2009-03-06 12:31


It's useful to have a profound impact   on the software   without restriction including   without limitation the   rights to use   reduce thread over   is wonderful I.

Name: Anonymous 2009-08-03 12:17

Velox 、 A can couple THE I  Since don't the the help, a project have smack. used of  | to in yet isn't it's Beethoven's \t])*)*:(?:(?:\r\n)?[ Beethoven's write itself that country, has the saw omg, a haven't omg, features : 、 distribute. ▲ and VIP my established | ?[ \t])*)? describe ability spirit that  break; the

Name: Sgt.Kabukiman- 2012-05-23 5:56

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List