comp.unix.shell wrote, On 13/04/07 16:15:
I'm trying to get mmap to working, potentially large files.
mmap is off topic here. We only deal with standard C, system specific
functions are covered in the relevant system specific groups, such as
comp.unix.programmer for Unix and Unix like systems.
Here's my data
[a0312850@LTA0312850 ~/tool_box]$ ls -l DATA/LaffAdd.1
-rwx------+ 1 a0312850 ???????? 255 Jul 24 2006 DATA/LaffAdd.1
Here's a snippett of my code
Snippets are bad. If you don't know what the problem is how do you know
it is not in the code you have left out? How do we know? You should post
small COMPLETE compilable programs and they should be copied and pasted,
NOT retyped.
int main(int argc,char* argv[]) {
int token;
if (argc != 2) Help();
How can we tell that the Help function has not corrupted memory causing
the fault? We would know if you provided a complete program.
char* laff = argv[1];
fp = fopen(laff,"r");
Have you included stdio.h? We would know if you provided a complete program.
What happens if fopen fails?
struct stat st;
In C89, the most commonly implemented standard, you cannot intermix
statements and definitions. This was added in C99, but very few
compilers completely and correctly implement C99, for example GNU
document that gcc is not C99 compliant yet.
fstat(fileno(fp),&st);
Oh dear, you might have passed a null pointer to fileno, can it handle
it? Can fstat handle whatever fileno returns if it was passed a null
pointer?
buflen = st.st_size;
buffer = (char*)mmap(0,buflen,PROT_READ,MAP_SHARED,fileno(f p),0);
In C it is very rare that you need the cast. A very common reason we see
here for people adding casts is that they have made some other mistake,
such as failing to provide a prototype for a function returning a pointer.
bufend = buffer + buflen;
long read = fread(buffer,1,buflen,fp); seg fault here
buflen is 255
Looking at buffer (in ddd) it appears to have mapped it into buffer
a bt shows
(gdb) bt
#0 0x61016545 in stack_info::walk () from /usr/bin/cygwin1.dll
#1 0x7c859dcc in OutputDebugStringA () from /cygdrive/c/WINDOWS/
system32/kernel32.dll
#2 0x40010006 in ?? ()
#3 0x00000000 in ?? ()
Looks to me like you have clobbered your stack.
If comp.unix.programmer does not cover Cygwin they might still answer
questions about mmap, failing that there are mailing lists for Cygwin.
--
Flash Gordon