spice- application::main--init_globals--init_logger

void Platform::get_app_data_dir(std::string& path, const std::string& app_name)
{
    const char* home_dir = getenv("HOME");     //get the environment variable , return the pointer 

    if (!home_dir || strlen(home_dir) == 0) {   //dir is null 
        throw Exception("get home dir failed");  // throw  exception 
    }

    path = home_dir;
    std::string::iterator end = path.end();   // define the iterator of string 

    while (end != path.begin() && *(end - 1) == '/') {
        path.erase(--end);                               // delete the symbol  '/'
    }

    path += "/.";                                     // add  /.
    path += app_name;                                // add app_name 

    if (mkdir(path.c_str(), 0700) == -1 && errno != EEXIST) {  // dreate the appdata dir    
        throw Exception("create appdata dir failed");    // S_IRWXU  00700  stand for owner have the authorization of read write operate
    }                               //errno record the system last error code ,whose value is the type of int . 
}              //#define   EEXIST  17 /* File exists */



 

1. getenv()函数

 char *getenv(char *envvar);

函数说明:getenv()用来取得参数envvar 环境变量的内容。参数envvar为 环境变量的名称,如果该变量存在则会返回指向该内容的 指针环境变量的格式为envvar=value。getenv函数的返回值存储在一个全局二维数组里,当你再次使用getenv函数时不用担心会覆盖上次的调用结果。
返回值: 执行成功则返回指向该内容的 指针,找不到符合的 环境变量名称则返回NULL。如果 变量存在但无关联值,它将运行成功并返回一个 空字符串,即该字符的第一个字节是null。
 
2.fopen()函数
 FILE * f open(const char * path,const char * mode);

  参数说明

。。。。。。

http://baike.baidu.com/view/656681.htm

 a 以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)

。。。。。。

3.HOME

返回当前的用户路径

4.mkdir()函数

int mkdir(char * dir, int mode):目录创建函数
运用条件:只能在已存在的目录下建立一级子目录
返回值:
返回0表示成功,返回-1表述出错。
头文件:sys/stat.h

http://baike.baidu.com/view/1279338.htm
http://blog.csdn.net/rabbiteatpumpkin/article/details/6445321

errno parameter defintion

http://baike.baidu.com/view/3485007.htm

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值