Le 1 avr. 06 à 19:33, Troy Lokitz a écrit :
When I try to create a string with the '\x00' hex value, it treats
it as a null, so when I try to create the following string:
strcat(stringbuf,"\x01\x02\x00\x01")
The following string is created:
"\x01\x02" because the \x00 is null.
With this in mind, how do I create a string that will include the
\x00 hex value?
you can use memcpy I guess
SYNOPSIS
#include <string.h>
void *
memcpy(void *dst, const void *src, size_t len);
DESCRIPTION
The memcpy() function copies len bytes from memory area src to
memory
area dst. If src and dst overlap, behavior is undefined.
Applications
in which src and dst might overlap should use memmove(3) instead.
so equivalent of strcat(stringbuf,"\x01\x02\x00\x01") will become :
int len = strlen (stringbuf);
memcpy (stringbug + len, "\x01\x02\x00\x01", sizeof ("\x01\x02\x00
\x01") / sizeof (char));
the problem is when stringbuf has \x00 value, because of the strlen
() which uses this value
to know where the string ends.
So what I suggest to you, is to create a structure :
typedef struct {
char *content; // the content of our string
int capacity; // how much memory we have alloc and which is
pointed by the content pointer
int len; // how much useful data is strore in the
content pointer
} my_string;
then making your std tools :
void strcat (my_string *dest, my_string * src) {
if (dest == NULL || src == NULL) return;
if (dest->capacity < dest->len + src->len) {
//alloc more memory
dest->content = realloc (dest->content, (dest->len + src->len) *
sizeof (char));
dest->capacity = dest->len + src->len;
}
memcpy (dest->content + dest->len, src->content, src->len);
}
Or, more generally, how do I send the \x00 value at all over a socket?
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
ssize_t
send(int s, const void *msg, size_t len, int flags);
as you can see, the socket functions don't care of the \x00 value, or
else it will
be difficult to send binary content (which contains \x00 value).
so with the structure I gave, you can do :
send (socket, buffer->content, buffer->len, flag);
Thanks,
Troy
Hope I can give you a good answer
Regards,
P.S. : all man's extraits are from unix manual. I think this is
equivalent in the
palm library (for those functions).
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/