1
0

feat(lab03): WIP ex4

This commit is contained in:
2026-04-02 21:16:33 +02:00
parent 86a5f88481
commit 263b5c203e
2 changed files with 55 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -1,8 +1,10 @@
#include <stdio.h>
#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;
}