November 09, 2002
I just wrote this function
char[] tostring(char* cstring)
{
    int n = strlen(cstring);
    char[] ret = cstring[0 .. n];
    return ret;
}

I just wonder why not add a constructor like this one to string ....


November 11, 2002
Is it really missing?

First, it's declaration may be missing from stdlib.d, but that doesn't mean it's not in the stdlib.lib (which is included by default), you just need to make the declaration yourself.

example that works:

import c.stdio;

//declaration
extern (C) char* getenv(char*);

//app
void main(){

char * s = getenv("PATH");

printf("PATH env var: %s", s);
}


Second, I would like to propose that as phobos is an object oriented evironment, and that room has been make in the language to address environments (ie, linux, windows, POSIX, etc...), that there should be some abstract object that makes available such things as environment variables, shell information, terminal abstraction etc...

Karim Sharif

P.S. as getenv returns a char pointer, it's safe to use the c.stdio.printf function without the wierd syntax for strings ie; printf("%.*s", s), just use printf("%s", s); This is because you have a C string returned. Don't try to free this or manipulate it in any way, make a copy then do what you want with it.

In article <aqhvpr$31je$1@digitaldaemon.com>, Lloyd Dupont says...
>
>I just wrote this function
>char[] tostring(char* cstring)
>{
>    int n = strlen(cstring);
>    char[] ret = cstring[0 .. n];
>    return ret;
>}
>
>I just wonder why not add a constructor like this one to string ....
>
>