您的位置:首页 > 其它

获取环境变量

2015-06-25 11:55 465 查看
#include <stdlib.h>

int main(int argc, char *argv[])
{
  const char *tmppath = "/tmp";
  const char *user = "";
  /**
   * in UNIX/Linux os, uses /tmp direcotry to store temp file, while in
   * Windows os, using `TMP' environment variable indicate the temp directory.
   *
   * and using `USER' environment variable in UNIX/Linux, but in Windows os,
   * it uses `USERNAME' to store logon user.
   */
#ifdef _WIN32
  tmppath = getenv("TMP");    /* without the last '\\' */
  user = getenv("USERNAME");
#else
  user = getenv("USER");
#endif /* _WIN32 */

  /* use the same `HOME' environment variable in Unix/Linux and Windows */
  const char *homedir = getenv("HOME");

  return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: