c - Duplicate keys using ftok() -
i have existing code in system uses ftok() generate key based on file name , 0 passed it. code working fine on 32 bit starts complaining randomly when moved 64 bits. on researching more , found because of lower signicant bits 0 , shmopen() better alternative. let me know shmopen() safe key collisions? there better way avoid key collisions?
key = ftok(filename,0);
from posix specification:
the ftok() function shall return same key value paths name same file, when called same id value, , return different key values when called different id values or paths name different files existing on same file system @ same time. unspecified whether ftok() shall return same key value when called again after file named path removed , recreated same name.
so calling function same path , id return same key. if want different key same path need change id.
and yes, passing 0 id leads unspecified behavior, should not that.
Comments
Post a Comment