int でなければならない共有ファイルを作成しようとしています。
int f;
しかし、私が到達したとき
if ((fstat(f, &stbuf) != 0) || (!S_ISREG(stbuf.st_mode)))
エラーが発生します。ファイルには、次のような文字列が含まれている必要があります。
abcd
私の推測は次のとおりですが、機能しません。
int main() {
int f;
void *memoria = NULL;
int tam;
struct stat stbuf;
char string[15] = {0};
f = open("fichero.txt", O_RDWR, S_IRUSR);
// ERROR IS HERE!!
if ((fstat(f, &stbuf) != 0) || (!S_ISREG(stbuf.st_mode))) {
printf("Error");
}
tam = stbuf.st_size;
printf("%d\n", tam);
// Proyect the file
memoria = mmap(0, tam, PROT_WRITE, MAP_SHARED, f, 0);
// Copy the string into the file
memcpy(memoria, "abcd", 5);
munmap(memoria, tam);
return 0;
}
開いているパラメータを変更する必要がありますか?? 私は何を間違っていますか?ありがとう!