feat(lab03): WIP ex4
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/errno.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#define DATA_LENGTH 70
|
||||||
|
|
||||||
|
const static char* data = "J'ai le chocolat qui est collé au palais, ducoup j'arrive pas a parlé\0";
|
||||||
|
|
||||||
|
static char data_read[DATA_LENGTH] = {};
|
||||||
|
|
||||||
|
int ex_character_oriented(void) {
|
||||||
|
printf("Exercice 4 - character oriented\n");
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
const char* path = "/dev/toto0\0";
|
||||||
|
|
||||||
|
int fd = open(path, O_RDWR);
|
||||||
|
|
||||||
|
if (fd < 0) {
|
||||||
|
printf("Failed to open /dev/toto0: %s\n (maybe you need to create it)\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = write(fd, data, DATA_LENGTH);
|
||||||
|
|
||||||
|
if(ret < 0) {
|
||||||
|
printf("Failed to write\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = read(fd, data_read, DATA_LENGTH);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
printf("Read from device: %s\n", path);
|
||||||
|
printf("Content: %s\n", data_read);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "exercice/ex1-memory-oriented.c"
|
#include "exercice/ex1-memory-oriented.c"
|
||||||
#define MEMORY_ORIENTED
|
// #define MEMORY_ORIENTED
|
||||||
|
|
||||||
|
#include "exercice/ex4-character-oriented.c"
|
||||||
|
#define CHARACTER_ORIENTED
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -14,5 +16,10 @@ int main() {
|
|||||||
ret = ex_memory_oriented();
|
ret = ex_memory_oriented();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CHARACTER_ORIENTED
|
||||||
|
printf("--------------------------------------\n");
|
||||||
|
ret = ex_character_oriented();
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user