The R Project SVN R

Rev

Rev 37084 | Rev 38957 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37084 Rev 37091
Line 575... Line 575...
575
	    if (isspace(*p)) { hasspace = 1; break; }
575
	    if (isspace(*p)) { hasspace = 1; break; }
576
	if (hasspace) {
576
	if (hasspace) {
577
	    GetShortPathName(tm, tmp2, MAX_PATH);
577
	    GetShortPathName(tm, tmp2, MAX_PATH);
578
	    tm = tmp2;
578
	    tm = tmp2;
579
	}
579
	}
-
 
580
	sprintf(tmp1, "%s\\RtmpXXXXXX", tm);
580
#endif
581
#else
581
	sprintf(tmp1, "%s/RtmpXXXXXX", tm);
582
	sprintf(tmp1, "%s/RtmpXXXXXX", tm);
-
 
583
#endif
582
	tmp = mkdtemp(tmp1);
584
	tmp = mkdtemp(tmp1);
583
	if(!tmp) R_Suicide(_("cannot mkdir R_TempDir"));
585
	if(!tmp) R_Suicide(_("cannot mkdir R_TempDir"));
584
#if defined(HAVE_PUTENV) && !defined(Win32)
586
#if defined(HAVE_PUTENV) && !defined(Win32)
585
	{
587
	{
586
	    char * buf = (char *) malloc((strlen(tmp) + 20) * sizeof(char));
588
	    char * buf = (char *) malloc((strlen(tmp) + 20) * sizeof(char));
Line 605... Line 607...
605
 
607
 
606
char * R_tmpnam(const char * prefix, const char * tempdir)
608
char * R_tmpnam(const char * prefix, const char * tempdir)
607
{
609
{
608
    char tm[PATH_MAX], tmp1[PATH_MAX], *res;
610
    char tm[PATH_MAX], tmp1[PATH_MAX], *res;
609
    unsigned int n, done = 0;
611
    unsigned int n, done = 0;
-
 
612
#ifdef Win32
-
 
613
    char filesep[] = "\\";
-
 
614
#else
-
 
615
    char filesep[] = "/";
-
 
616
#endif
610
 
617
 
611
    if(!prefix) prefix = "";	/* NULL */
618
    if(!prefix) prefix = "";	/* NULL */
612
    if(strlen(tempdir) >= PATH_MAX) error(_("invalid 'tempdir' in R_tmpnam"));
619
    if(strlen(tempdir) >= PATH_MAX) error(_("invalid 'tempdir' in R_tmpnam"));
613
    strcpy(tmp1, tempdir);
620
    strcpy(tmp1, tempdir);
614
    for (n = 0; n < 100; n++) {
621
    for (n = 0; n < 100; n++) {
615
	/* try a random number at the end.  Need at least 6 hex digits */
622
	/* try a random number at the end.  Need at least 6 hex digits */
616
#if RAND_MAX > 16777215
623
#if RAND_MAX > 16777215
617
	sprintf(tm, "%s/%s%x", tmp1, prefix, rand());
624
	sprintf(tm, "%s%s%s%x", tmp1, filesep, prefix, rand());
618
#else
625
#else
619
	sprintf(tm, "%s/%s%x%x", tmp1, prefix, rand(), rand());
626
	sprintf(tm, "%s%s%s%x%x", tmp1, filesep, prefix, rand(), rand());
620
#endif
627
#endif
621
        if(!R_FileExists(tm)) { 
628
        if(!R_FileExists(tm)) { 
622
	    done = 1; 
629
	    done = 1; 
623
	    break; 
630
	    break; 
624
	}
631
	}