/** \brief Return the file-path of the key file related * to the identified shared memory * * \b os_posix_findKeyFile tries to find the key file related to \b name * in the \b /tmp directory. The key files are prefixed with \b * /tmp/spddskey_. * * \b os_posix_findKeyFile first opens the directory \b /tmp by calling * \b opendir. Then it reads all entries in serach for any entry * that starts with the name \b spddskey_ by reading the entry with * \b readdir. If the a matching entry is found, it calls os_posix_matchKeyFile * to check if the key file matches the identified \b name. If the * \b name matches the contents, the entry is found, and the path * is returned to the caller. The memory for the path is allocated * from heap and is expected to be freed by the caller. * * If no matching entry is found, NULL is returned to the caller. */ static char * os_posix_findKeyFile ( const char *name) { DIR *key_dir; struct dirent *entry; char key_file_name [sizeof(os_posix_key_file_prefix)+1]; char *kfn = NULL; key_dir = opendir ("/tmp"); if (key_dir) { entry = readdir (key_dir); while (entry != NULL) { if (strncmp (entry->d_name, "spddskey_", 9) == 0) { snprintf (key_file_name, sizeof(os_posix_key_file_prefix)+1, "/tmp/%s", entry->d_name); if (os_posix_matchKeyFile (key_file_name, name)) { kfn = os_malloc (strlen (key_file_name) + 1); if (kfn != NULL) { os_strcpy (kfn, key_file_name); } entry = NULL; } else { entry = readdir (key_dir); } } else { entry = readdir (key_dir); } } closedir (key_dir); } return kfn; }
/** \brief Return the file-path of the key file related * to the identified shared memory * * \b os_posix_findKeyFile tries to find the key file related to \b name * in the \b temporary directory. The key files are prefixed with \b * /<temporary directory>/spddskey_. * * \b os_posix_findKeyFile first opens the directory \b temporary directory by * calling \b opendir. Then it reads all entries in serach for any entry * that starts with the name \b spddskey_ by reading the entry with * \b readdir. If the a matching entry is found, it calls os_posix_matchKeyFile * to check if the key file matches the identified \b name. If the * \b name matches the contents, the entry is found, and the path * is returned to the caller. The memory for the path is allocated * from heap and is expected to be freed by the caller. * * If no matching entry is found, NULL is returned to the caller. */ static char * os_posix_findKeyFile( const char *name) { DIR *key_dir; struct dirent *entry; char *kfn = NULL; char * dir_name = NULL; char * key_file_name = NULL; int key_file_name_size; dir_name = os_getTempDir(); key_dir = opendir(dir_name); if (key_dir) { entry = readdir(key_dir); while (entry != NULL) { if (strncmp(entry->d_name, "spddskey_", 9) == 0) { key_file_name_size = strlen(dir_name) + strlen(os_posix_key_file_format) + 2; key_file_name = os_malloc (key_file_name_size); snprintf(key_file_name, key_file_name_size, "%s/%s", dir_name, entry->d_name); if (os_posix_matchKeyFile(key_file_name, name)) { kfn = os_malloc(strlen(key_file_name) + 1); if (kfn != NULL) { os_strcpy(kfn, key_file_name); } entry = NULL; } else { entry = readdir(key_dir); } os_free (key_file_name); } else { entry = readdir(key_dir); } } closedir(key_dir); } return kfn; }