On Tue, Mar 29, 2005 at 04:26:31PM +0530, Mandeep Sandhu wrote: > On Tue, 2005-03-29 at 12:31 +0200, Erik Mouw wrote: > > On Tue, Mar 29, 2005 at 03:54:13PM +0530, Mandeep Sandhu wrote: > > Literial \0 after the string, so string is too long. > the '\0' got appended at the end when i created the string.... > I'm don't get what you mean by string being too long. You shouldn't copy it to userland. \0 happens to be the string terminator used in C, but it is by no means a general string terminator. > > > count = sizeof(msg); > > > > Here's your error, that should be count = strlen(msg); > > > strlen(msg) is 5. (i.e the length of the string) > sizeof(msg) is 6. (length + the null terminating char) > > so while copying data into the userspace buffer...I should > omit copying this null term ('\0') char???? won't the user > prog be expecting this at the end of the string? or it'll (cat) > handle it on it's own? No, userland doesn't expect it, and it will confuse your terminal. printf() used in userland programs also doesn't print a \0 after every line, and with reason: \0 is *only* the string terminator used internally in C, *not* a way to signal end-of-file to userland. Erik -- Erik Mouw J.A.K.Mouw@xxxxxxxxxxxxxx mouw@xxxxxxxxxxxx
Attachment:
signature.asc
Description: Digital signature