Annotation of rpl/rplsignal/chemin.c, revision 1.1

1.1     ! bertrand    1: unsigned char *
        !             2: recherche_chemin_fichiers_temporaires()
        !             3: {
        !             4:    FILE                *fichier;
        !             5: 
        !             6:    unsigned char       *candidat;
        !             7:    unsigned char       *chemin;
        !             8:    unsigned char       *chemins[] = { "$RPL_TMP_PATH",
        !             9:                                "/tmp", "/var/tmp", NULL };
        !            10:    unsigned char       fichier_test[] = "/RPL-SIGNAL-TEST";
        !            11:    unsigned char       *nom_candidat;
        !            12: 
        !            13:    unsigned long int   i;
        !            14: 
        !            15:    i = 0;
        !            16:    chemin = NULL;
        !            17: 
        !            18:    while(chemin == NULL)
        !            19:    {
        !            20:        if (chemins[i][0] == '$')
        !            21:        {
        !            22:            candidat = getenv(chemins[i] + 1);
        !            23: 
        !            24:            if (candidat != NULL)
        !            25:            {
        !            26:                if ((nom_candidat = malloc((strlen(candidat) +
        !            27:                        strlen(fichier_test) + 1) * sizeof(unsigned char)))
        !            28:                        == NULL)
        !            29:                {
        !            30:                    return(NULL);
        !            31:                }
        !            32: 
        !            33:                sprintf(nom_candidat, "%s%s", candidat, fichier_test);
        !            34: 
        !            35:                if ((fichier = fopen(nom_candidat, "w+")) != NULL)
        !            36:                {
        !            37:                    fclose(fichier);
        !            38:                    unlink(nom_candidat);
        !            39:                    free(nom_candidat);
        !            40: 
        !            41:                    if ((chemin = malloc((strlen(candidat) + 1)
        !            42:                            * sizeof(unsigned char))) != NULL)
        !            43:                    {
        !            44:                        strcpy(chemin, candidat);
        !            45:                    }
        !            46:                    else
        !            47:                    {
        !            48:                        return(NULL);
        !            49:                    }
        !            50:                }
        !            51:                else
        !            52:                {
        !            53:                    free(nom_candidat);
        !            54:                }
        !            55:            }
        !            56:        }
        !            57:        else
        !            58:        {
        !            59:            if ((nom_candidat = malloc((strlen(candidat) +
        !            60:                    strlen(fichier_test) + 1) * sizeof(unsigned char)))
        !            61:                    == NULL)
        !            62:            {
        !            63:                return(NULL);
        !            64:            }
        !            65: 
        !            66:            sprintf(nom_candidat, "%s%s", candidat, fichier_test);
        !            67: 
        !            68:            if ((fichier = fopen(nom_candidat, "w+")) != NULL)
        !            69:            {
        !            70:                fclose(fichier);
        !            71:                unlink(nom_candidat);
        !            72:                free(nom_candidat);
        !            73: 
        !            74:                if ((chemin = malloc((strlen(candidat) + 1)
        !            75:                        * sizeof(unsigned char))) != NULL)
        !            76:                {
        !            77:                    strcpy(chemin, candidat);
        !            78:                }
        !            79:                else
        !            80:                {
        !            81:                    return(NULL);
        !            82:                }
        !            83:            }
        !            84:            else
        !            85:            {
        !            86:                free(nom_candidat);
        !            87:            }
        !            88:        }
        !            89: 
        !            90:        i++
        !            91:    }
        !            92: 
        !            93:    return(chemin);
        !            94: }
        !            95: 
        !            96: // vim: ts=4
        !            97: 

CVSweb interface <joel.bertrand@systella.fr>