From 263b5c203e2a44f9090baed1ce0e72c9a4dc93f6 Mon Sep 17 00:00:00 2001 From: fastium Date: Thu, 2 Apr 2026 21:16:33 +0200 Subject: [PATCH] feat(lab03): WIP ex4 --- .../exercice/ex4-character-oriented.c | 47 +++++++++++++++++++ src/02-driver/main.c | 9 +++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/02-driver/exercice/ex4-character-oriented.c b/src/02-driver/exercice/ex4-character-oriented.c index e69de29..8ca2cba 100644 --- a/src/02-driver/exercice/ex4-character-oriented.c +++ b/src/02-driver/exercice/ex4-character-oriented.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +} diff --git a/src/02-driver/main.c b/src/02-driver/main.c index 6f68eab..cacf055 100644 --- a/src/02-driver/main.c +++ b/src/02-driver/main.c @@ -1,8 +1,10 @@ #include #include "exercice/ex1-memory-oriented.c" -#define MEMORY_ORIENTED +// #define MEMORY_ORIENTED +#include "exercice/ex4-character-oriented.c" +#define CHARACTER_ORIENTED int main() { @@ -14,5 +16,10 @@ int main() { ret = ex_memory_oriented(); #endif +#ifdef CHARACTER_ORIENTED + printf("--------------------------------------\n"); + ret = ex_character_oriented(); +#endif + return ret; }