Migrating a C program from Linux to Windows

Viewed 6104

I want to open a file in C with 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've wrote this code for the first time in Linux, and It was working, but when I run it in 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 that problem?

1 Answers
Related