For some reason I can't get open() to open a file. Here's my code.
static int context_ctor(X86Context *ctx)
{
char file[512];
memset(ctx, 0, sizeof(X86Context));
sprintf(file, "%s.%d", "test", getpid());
ctx->fp = open(file, O_RDWR);
if(ctx->fp < 0) {
printf("errno %d %s\n", errno, 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->buf);
close(ctx->fp);
exit(0);
}
And here's the output:
errno 2 test.12356
Looking up the error code reveals:
[EACCES]
Permission denied.
I know I have permission to read/write/execute files in this directory. I even tried /tmp/test.pid. Any idea?