The R Project SVN R

Rev

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

Rev 78183 Rev 79342
Line 49... Line 49...
49
#endif
49
#endif
50
#ifdef HAVE_SYS_STAT_H
50
#ifdef HAVE_SYS_STAT_H
51
# include <sys/stat.h>
51
# include <sys/stat.h>
52
#endif
52
#endif
53
 
53
 
54
static int isDir(char *path);
54
int attribute_hidden R_isWriteableDir(char *path);
55
 
55
 
56
#ifdef HAVE_AQUA
56
#ifdef HAVE_AQUA
57
int (*ptr_CocoaSystem)(const char*);
57
int (*ptr_CocoaSystem)(const char*);
58
#endif
58
#endif
59
 
59
 
Line 236... Line 236...
236
 
236
 
237
SEXP attribute_hidden do_tempdir(SEXP call, SEXP op, SEXP args, SEXP env)
237
SEXP attribute_hidden do_tempdir(SEXP call, SEXP op, SEXP args, SEXP env)
238
{
238
{
239
    checkArity(op, args);
239
    checkArity(op, args);
240
    Rboolean check = asLogical(CAR(args));
240
    Rboolean check = asLogical(CAR(args));
241
    if(check && !isDir(R_TempDir)) {
241
    if(check && !R_isWriteableDir(R_TempDir)) {
242
	R_TempDir = NULL;
242
	R_TempDir = NULL;
243
	R_reInitTempDir(/* die_on_fail = */ FALSE);
243
	R_reInitTempDir(/* die_on_fail = */ FALSE);
244
    }
244
    }
245
    return mkString(R_TempDir);
245
    return mkString(R_TempDir);
246
}
246
}
Line 1737... Line 1737...
1737
 
1737
 
1738
#if !defined(S_IFDIR) && defined(__S_IFDIR)
1738
#if !defined(S_IFDIR) && defined(__S_IFDIR)
1739
# define S_IFDIR __S_IFDIR
1739
# define S_IFDIR __S_IFDIR
1740
#endif
1740
#endif
1741
 
1741
 
1742
static int isDir(char *path)
1742
int attribute_hidden R_isWriteableDir(char *path)
1743
{
1743
{
1744
#ifdef Win32
1744
#ifdef Win32
1745
    struct _stati64 sb;
1745
    struct _stati64 sb;
1746
#else
1746
#else
1747
    struct stat sb;
1747
    struct stat sb;
Line 1761... Line 1761...
1761
#endif
1761
#endif
1762
    }
1762
    }
1763
    return isdir;
1763
    return isdir;
1764
}
1764
}
1765
#else
1765
#else
1766
static int isDir(char *path)
1766
int attribute_hidden R_isWriteableDir(char *path)
1767
{
1767
{
1768
    return 1;
1768
    return 1;
1769
}
1769
}
1770
#endif /* HAVE_STAT */
1770
#endif /* HAVE_STAT */
1771
 
1771
 
Line 1793... Line 1793...
1793
 
1793
 
1794
    if(R_TempDir) return; /* someone else set it */
1794
    if(R_TempDir) return; /* someone else set it */
1795
    tmp = NULL; /* getenv("R_SESSION_TMPDIR");   no longer set in R.sh */
1795
    tmp = NULL; /* getenv("R_SESSION_TMPDIR");   no longer set in R.sh */
1796
    if (!tmp) {
1796
    if (!tmp) {
1797
	tm = getenv("TMPDIR");
1797
	tm = getenv("TMPDIR");
1798
	if (!isDir(tm)) {
1798
	if (!R_isWriteableDir(tm)) {
1799
	    tm = getenv("TMP");
1799
	    tm = getenv("TMP");
1800
	    if (!isDir(tm)) {
1800
	    if (!R_isWriteableDir(tm)) {
1801
		tm = getenv("TEMP");
1801
		tm = getenv("TEMP");
1802
		if (!isDir(tm))
1802
		if (!R_isWriteableDir(tm))
1803
#ifdef Win32
1803
#ifdef Win32
1804
		    tm = getenv("R_USER"); /* this one will succeed */
1804
		    tm = getenv("R_USER"); /* this one will succeed */
1805
#else
1805
#else
1806
		    tm = "/tmp";
1806
		    tm = "/tmp";
1807
#endif
1807
#endif