unsigned char * recherche_chemin_fichiers_temporaires() { FILE *fichier; unsigned char *candidat; unsigned char *chemin; unsigned char *chemins[] = { "$RPL_TMP_PATH", "/tmp", "/var/tmp", NULL }; unsigned char fichier_test[] = "/RPL-SIGNAL-TEST"; unsigned char *nom_candidat; unsigned long int i; i = 0; chemin = NULL; while(chemin == NULL) { if (chemins[i][0] == '$') { candidat = getenv(chemins[i] + 1); if (candidat != NULL) { if ((nom_candidat = malloc((strlen(candidat) + strlen(fichier_test) + 1) * sizeof(unsigned char))) == NULL) { return(NULL); } sprintf(nom_candidat, "%s%s", candidat, fichier_test); if ((fichier = fopen(nom_candidat, "w+")) != NULL) { fclose(fichier); unlink(nom_candidat); free(nom_candidat); if ((chemin = malloc((strlen(candidat) + 1) * sizeof(unsigned char))) != NULL) { strcpy(chemin, candidat); } else { return(NULL); } } else { free(nom_candidat); } } } else { if ((nom_candidat = malloc((strlen(candidat) + strlen(fichier_test) + 1) * sizeof(unsigned char))) == NULL) { return(NULL); } sprintf(nom_candidat, "%s%s", candidat, fichier_test); if ((fichier = fopen(nom_candidat, "w+")) != NULL) { fclose(fichier); unlink(nom_candidat); free(nom_candidat); if ((chemin = malloc((strlen(candidat) + 1) * sizeof(unsigned char))) != NULL) { strcpy(chemin, candidat); } else { return(NULL); } } else { free(nom_candidat); } } i++ } return(chemin); } // vim: ts=4