0

i get this error every time i try to compile the code below. any suggestions
---------------------------------------------------------------------------------------
Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Users\ndayala\Desktop\19266\main_random.c" -o "C:\Users\ndayala\Desktop\19266\main_random.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Users\ndayala\Desktop\19266\main_random.c:9:22: sys/mman.h: No such file or directory
C:\Users\ndayala\Desktop\19266\main_random.c: In function `main':
C:\Users\ndayala\Desktop\19266\main_random.c:30: error: `PROT_READ' undeclared (first use in this function)
C:\Users\ndayala\Desktop\19266\main_random.c:30: error: (Each undeclared identifier is reported only once
C:\Users\ndayala\Desktop\19266\main_random.c:30: error: for each function it appears in.)

C:\Users\ndayala\Desktop\19266\main_random.c:30: error: `PROT_WRITE' undeclared (first use in this function)
C:\Users\ndayala\Desktop\19266\main_random.c:30: error: `MAP_PRIVATE' undeclared (first use in this function)
C:\Users\ndayala\Desktop\19266\main_random.c:34: error: `MADV_SEQUENTIAL' undeclared (first use in this function)

Execution terminated
----------------------------------------------------------------------------------------

#include <fcntl.h>	
#include <sys/stat.h>	
#include <sys/types.h>	

#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/mman.h>

#define FILE_SIZE 3000000

int main() {
    // program runtime
    double sec;               // seconds
    struct timeval tv1, tv2;  // time values

    gettimeofday(&tv1, NULL); // fix time
    
    { // file handling
    
        ssize_t ret;
        char ch;
        int i;
    
        // creating file descriptor
        int fd = open ("file.txt", O_RDONLY);
        
        // file displaying into virtual memory
        mmap(0x230000, FILE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd); 
	    
	    // virtual memory mode
	    //madvise(0x230000, FILE_SIZE, MADV_RANDOM);     // wait random access
	    madvise(0x230000, FILE_SIZE, MADV_SEQUENTIAL); // wait sequentially access
	    
	    // read randomly bytes from file
	    for(i = 0; i < FILE_SIZE; i++){
            lseek (fd, (int)(FILE_SIZE * random()/RAND_MAX), SEEK_SET);
            read (fd, &ch, 1);
        }
	    
	    if (fd < 0){ // error handling
		    printf ("Cannot open file.\n");
		    exit (1);
        }
	
	    close (fd);
	    
     } // end file handling

    gettimeofday(&tv2, NULL); // fix time

    sec = (double)(tv2.tv_usec - tv1.tv_usec) / 1000000 + (tv2.tv_sec - tv1.tv_sec);
    printf("execution time: %f\n", sec);     // print seconds
    
    exit(0);
}
2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by gerard4143
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.