unix - C - does read() add a '\0'? -
does have to? i've been fuzzy on sort of stuff, if have like:
char buf[256]; read(fd, buf, 256); write(fd2, buf, 256);
is there potential error here, other cases functions return -1?
if read 40 characters, put \0 after it? (and write recognize \0 , stop? also, if read 256 characters, there \0 after 256?
does read() add '\0'?
no, doesn't. reads.
from read()
's documentation:
the read() function shall attempt read nbyte bytes file associated open file descriptor, fildes, buffer pointed buf.
is there potential error here, other cases functions return -1?
read()
might return 0
indicating end-of-file.
if reading (also socket descriptor) read()
not reads bytes told do. in context not test outcome of read against -1
, compare against number of bytes function told read.
a general note:
functions documented (at least proper implementations of c language). both assumptions (autonomously set 0-termination, detect latter) not documented.
Comments
Post a Comment