Listing 3 in C

// Receive ZeroMQ string from socket and convert into C string
// Chops string at 255 chars, if it's longer

static char *
s_recv (void *socket) {
char buffer [256];
int size = zmq_recv (socket, buffer, 255, 0);
if (size == -1)
return NULL;
if (size > 255)
size = 255;
buffer [size] = 0;
return strdup (buffer);
}