The R Project SVN R

Rev

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

Rev 46843 Rev 47460
Line 296... Line 296...
296
#else
296
#else
297
extern char ** environ;
297
extern char ** environ;
298
#endif
298
#endif
299
 
299
 
300
#ifdef Win32
300
#ifdef Win32
301
# define WC_ENVIRON
-
 
302
#endif
-
 
303
 
-
 
304
#ifdef WC_ENVIRON
-
 
305
/* _wenviron is declared in stdlib.h */
301
/* _wenviron is declared in stdlib.h */
306
# define WIN32_LEAN_AND_MEAN 1
302
# define WIN32_LEAN_AND_MEAN 1
307
# include <windows.h> /* _wgetenv etc */
303
# include <windows.h> /* _wgetenv etc */
308
const wchar_t *wtransChar(SEXP x);
304
const wchar_t *wtransChar(SEXP x);
309
#endif
305
#endif
Line 321... Line 317...
321
    if (!isString(CADR(args)) || LENGTH(CADR(args)) != 1)
317
    if (!isString(CADR(args)) || LENGTH(CADR(args)) != 1)
322
	error(_("wrong type for argument"));
318
	error(_("wrong type for argument"));
323
 
319
 
324
    i = LENGTH(CAR(args));
320
    i = LENGTH(CAR(args));
325
    if (i == 0) {
321
    if (i == 0) {
326
#ifdef WC_ENVIRON
322
#ifdef Win32
327
	char *buf;
323
	char *buf;
328
	int n = 0, N;
324
	int n = 0, N;
329
	wchar_t **w;
325
	wchar_t **w;
330
	for (i = 0, w = _wenviron; *w != NULL; i++, w++)
326
	for (i = 0, w = _wenviron; *w != NULL; i++, w++)
331
	    n = max(n, wcslen(*w));
327
	    n = max(n, wcslen(*w));
Line 344... Line 340...
344
	    SET_STRING_ELT(ans, i, mkChar(*e));
340
	    SET_STRING_ELT(ans, i, mkChar(*e));
345
#endif
341
#endif
346
    } else {
342
    } else {
347
	PROTECT(ans = allocVector(STRSXP, i));
343
	PROTECT(ans = allocVector(STRSXP, i));
348
	for (j = 0; j < i; j++) {
344
	for (j = 0; j < i; j++) {
349
#ifdef WC_ENVIRON
345
#ifdef Win32
350
	    const wchar_t *wnm = wtransChar(STRING_ELT(CAR(args), j));
346
	    const wchar_t *wnm = wtransChar(STRING_ELT(CAR(args), j));
351
	    wchar_t *w = _wgetenv(wnm);
347
	    wchar_t *w = _wgetenv(wnm);
352
	    if (w == NULL)
348
	    if (w == NULL)
353
		SET_STRING_ELT(ans, j, STRING_ELT(CADR(args), 0));
349
		SET_STRING_ELT(ans, j, STRING_ELT(CADR(args), 0));
354
	    else {
350
	    else {
Line 374... Line 370...
374
    }
370
    }
375
    UNPROTECT(1);
371
    UNPROTECT(1);
376
    return (ans);
372
    return (ans);
377
}
373
}
378
 
374
 
379
#ifdef WC_ENVIRON
375
#ifdef Win32
380
static int Rwputenv(const wchar_t *nm, const wchar_t *val)
376
static int Rwputenv(const wchar_t *nm, const wchar_t *val)
381
{
377
{
382
    wchar_t *buf;
378
    wchar_t *buf;
383
    buf = (wchar_t *) malloc((wcslen(nm) + wcslen(val) + 2) * sizeof(wchar_t));
379
    buf = (wchar_t *) malloc((wcslen(nm) + wcslen(val) + 2) * sizeof(wchar_t));
384
    if(!buf) return 1;
380
    if(!buf) return 1;
Line 421... Line 417...
421
#ifdef HAVE_SETENV
417
#ifdef HAVE_SETENV
422
    for (i = 0; i < n; i++)
418
    for (i = 0; i < n; i++)
423
	LOGICAL(ans)[i] = setenv(translateChar(STRING_ELT(nm, i)),
419
	LOGICAL(ans)[i] = setenv(translateChar(STRING_ELT(nm, i)),
424
				 translateChar(STRING_ELT(vars, i)),
420
				 translateChar(STRING_ELT(vars, i)),
425
				 1) == 0;
421
				 1) == 0;
426
#elif defined(WC_ENVIRON)
422
#elif defined(Win32)
427
    for (i = 0; i < n; i++)
423
    for (i = 0; i < n; i++)
428
	LOGICAL(ans)[i] = Rwputenv(wtransChar(STRING_ELT(nm, i)),
424
	LOGICAL(ans)[i] = Rwputenv(wtransChar(STRING_ELT(nm, i)),
429
				   wtransChar(STRING_ELT(vars, i))) == 0;
425
				   wtransChar(STRING_ELT(vars, i))) == 0;
430
#else
426
#else
431
    for (i = 0; i < n; i++)
427
    for (i = 0; i < n; i++)
Line 459... Line 455...
459
	char buf[1000];
455
	char buf[1000];
460
	snprintf(buf, 1000, "%s",  translateChar(STRING_ELT(vars, i)));
456
	snprintf(buf, 1000, "%s",  translateChar(STRING_ELT(vars, i)));
461
	putenv(buf);
457
	putenv(buf);
462
    }
458
    }
463
#elif defined(HAVE_PUTENV_UNSET2)
459
#elif defined(HAVE_PUTENV_UNSET2)
464
# ifdef WC_ENVIRON
460
# ifdef Win32
465
    for (i = 0; i < n; i++) {
461
    for (i = 0; i < n; i++) {
466
	const wchar_t *w = wtransChar(STRING_ELT(vars, i));
462
	const wchar_t *w = wtransChar(STRING_ELT(vars, i));
467
	wchar_t *buf = (wchar_t *) alloca(2*wcslen(w));
463
	wchar_t *buf = (wchar_t *) alloca(2*wcslen(w));
468
	R_CheckStack();
464
	R_CheckStack();
469
	wcscpy(buf, w);
465
	wcscpy(buf, w);