Fixed problem with temp files on OS with no /tmp
authorEdouard Tisserant
Sun, 11 Oct 2015 15:28:20 +0200
changeset 37367a975761b69
parent 372 3fb0f63d566e
child 374 a26015b998e8
child 375 66e48c55cd7a
Fixed problem with temp files on OS with no /tmp
src/mime.c
     1.1 --- a/src/mime.c	Sat Oct 10 17:40:33 2015 +0200
     1.2 +++ b/src/mime.c	Sun Oct 11 15:28:20 2015 +0200
     1.3 @@ -33,6 +33,13 @@
     1.4      return strncmp(text, "-----BEGIN PGP MESSAGE-----", 27) == 0;
     1.5  }
     1.6  
     1.7 +#define TMP_TEMPLATE "pEp.XXXXXXXXXXXXXXXXXXXX"
     1.8 +#ifdef _WIN32
     1.9 +#define PATH_SEP '\\'
    1.10 +#else
    1.11 +#define PATH_SEP '/'
    1.12 +#endif
    1.13 +
    1.14  static PEP_STATUS render_mime(struct mailmime *mime, char **mimetext)
    1.15  {
    1.16      PEP_STATUS status = PEP_STATUS_OK;
    1.17 @@ -42,10 +49,30 @@
    1.18      char *buf = NULL;
    1.19      int col;
    1.20      int r;
    1.21 -    char *template = strdup("/tmp/pEp.XXXXXXXXXXXXXXXXXXXX");
    1.22 +
    1.23 +    char *template;
    1.24 +    char *envTmp = getenv("TEMP");
    1.25 +
    1.26 +    if(envTmp){
    1.27 +        int tmpL = strlen(envTmp);
    1.28 +        int needSep = envTmp[tmpL-1] == PATH_SEP;
    1.29 +        template = calloc(1, tmpL + 
    1.30 +                             (needSep ? 1 : 0) +
    1.31 +                             sizeof(TMP_TEMPLATE));
    1.32 +        if (template == NULL)
    1.33 +            goto enomem;
    1.34 +
    1.35 +        memcpy(template, envTmp, tmpL);
    1.36 +        if(needSep)
    1.37 +            template[tmpL] = PATH_SEP;
    1.38 +        memcpy(template + tmpL + (needSep ? 1 : 0), TMP_TEMPLATE, sizeof(TMP_TEMPLATE));
    1.39 +
    1.40 +    }else{
    1.41 +        template = strdup("/tmp/" TMP_TEMPLATE);
    1.42 +        if (template == NULL)
    1.43 +            goto enomem;
    1.44 +    }
    1.45      assert(template);
    1.46 -    if (template == NULL)
    1.47 -        goto enomem;
    1.48  
    1.49      *mimetext = NULL;
    1.50