linux - open() fails to open files -
For some reason I can not open () open a file. Here's my code.
Static Int context_actor (X86Context * ctx) {char file [512]; Mmateset (CTX, 0, SIFF (X86 Contact)); Sprintf (file, "% s.% D", "test", getpid ()); Ctx-> Fp = open (file, O_RDWR); If (CTX-> FP & lt; 0) {printf ("Error% d% s \ n", error, file); Return VISUAL_ERROR_GENERAL; } Ctx-> Buf = mmap (0, MAXFILESIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, ctx-> FP, 0); Printf ("context_ctor:% p \ n", CTX-> Buff); Close (ctx-> FP); Exit (0); }
And here's the output:
errno 2 test.12356
Seeing the error code Disclaimer: I know that I have permission to read / write / execute files in this directory. Any ideas I tried /tmp/test.pid?
If you are trying to create a new file then you need to use O_CREAT, Therefore:
ctx-> Fp = open (file, O_CREATE | O_RDWR);
Anyway, you may want to use strerror (errno) to show your errors
Comments
Post a Comment