I want to open a file in C using the open () function, and this is the code I use:
int lire(){ char buf[1024]; int bytesRead; int fildes; char path[128]; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; int flags = O_RDONLY; printf("\n%s-->Donner l'emplacement du fichier :%s ", CYAN_NORMAL, RESETCOLOR); scanf("%s", path); fildes = ouvrir(path, flags, mode); if(fildes == -1){ return 0; } while ((bytesRead = read(fildes, buf, sizeof buf)) > 0) { write(STDOUT_FILENO, buf, bytesRead); } close(fildes); return 1; } int ouvrir(char *path, int flags, mode_t mode) { return open(path, flags, mode); }
I wrote this code for the first time on Linux , and it worked, but when I ran it on Windows , I got this error message:
error: 'S_IRUSR' undeclared (first use in this function)| error: 'S_IWUSR' undeclared (first use in this function)| error: 'S_IRGRP' undeclared (first use in this function)| error: 'S_IROTH' undeclared (first use in this function)|
These are the headers I included:
#include <sys/types.h> //Specified in man 2 open #include <sys/stat.h> #include <stdio.h> #include <fcntl.h> // open function #include <unistd.h> // close function #include "colors.h" #include "const.h" #include <ctype.h> #include <errno.h> #include <string.h>
How can I solve this problem?
source share