Skip to content

Instantly share code, notes, and snippets.

@md-jamal
Created January 5, 2019 09:23
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char buffer[1024];
int fd;
int length;
fd = open("/dev/msg", O_RDWR);
if (fd < 0) {
perror("fd failed");
exit(2);
}
printf("write : %d\n", write(fd, "hello world", sizeof("hello world")));
length = read(fd, buffer, sizeof(buffer));
buffer[length] = '\0';
printf("Read:%s\n", buffer);
memset(buffer, 0, sizeof(buffer));
length = read(fd, buffer, sizeof(buffer));
buffer[length] = '\0';
printf("Read:%s\n", buffer);
close(fd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment