c - Linux mmap() error -
I have a memory map file, out of which I want to parse the content of the buffer. MMAP () achieves success, and I can successfully use fprintf to print the buffer content in the file. However, when I try to access Buffer as an array in my program directly, I get a partition error. Why is this happening? Here's the code:
#define PTT_DUMP "/ home / druru / somefile". . Int fd_ptt_dump = Open (PTT_DUMP, O_RDONLY); Structure state struct_ptt_dump; Fstat (fd_ptt_dump, & amp; struct_ptt_dump); Printf ("\ n \ n \ t \ t \ t --- Size of dump =% d ----- \ n \ n", struct_ptt_dump.st_size); Four * membuffer; Four pid_num [100]; Four cycles [100], examples [100], CPI [100]; Int pid_index = 0; Int cycles_index = 0; Int instr_index = 0; Int cpi_index = 0; Int len = (int) struct_ptt_dump.st_size; Int newline_count = 0; Int n = 0; If ((membuffer = mmap (0, struct_ptt_dump.st_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd_ptt_dump, 0)) == (caddr_t) -1) err_sys ("mmap error"); / * If the following is recommended, then it is fine for / / * (n = 0; n & lt; struct_ptt_dump.st_size; n ++) fprintf (fp_logfile, "% c", membufer [n]); * / / * But, I really want to use buffer as an array for speed if possible, / / * here is where everything goes wrong * / while (newline_count! = 5) If (embambar [n ++] == '\ n') Newline_count ++; / * Print returns are OK, and I am able to leave new lines * / printf ("\ n \ n new lines =% d \ n \ n10 buffer characters", newline_count); Int k = 0; / * All code segmentation error * here provides * while (messfer [n ++]! = '') Pid_num [pid_index ++] = membufer [n]; / * Even if I comment everything from here, the above assignment itself is in the segmentation fault * / pid_num [pid_index] = '\ 0'; Printf ("\ n \ npid =% s", pid_num); While (Membar [Lane]] = '' if (Membar [Lane]! = '\ N') CPI [CPI_InX ++] = LambBuffer [Lennon]; Cpi [cpi_index] = '\ 0'; For (Méffefer [lane] == ''; lane -); (N = 0; Membre [lane-n]! = ''; N ++) instr [instr_index ++] = Lambbuffar [Lane-N]; Instr [instr_index] = '\ 0'; N ++; For (messenger [lane-n]! = ''; N ++) cycle [cycles_index ++] =mbbuffer [lane-n]; Cycle [cycles_index] = '\ 0'; Printf ("\ n \ n \ t \ t \ t \ t ********** buffer value ***********************); Printf ("\ t \ t \ t \ tdominant pid =% s \ t cycle =% s \ t command =% s \ t cpi =% s \ n \ n", pid_num, cycle, instr, cpi); Fflush (STDOUT_FILENO);
How big is pid_index
getting? Are you reading over 100 characters without space?
By the way, it
while (membuffer [n ++]! = '') Pid_num [pid_index ++] = mmfar [n];
should be
while (messfer [n]! = '') Pid_num [pid_index ++] = membufer [n ++];
not
Comments
Post a Comment