c获取运行程序的工作目录以及文件大小

  • 获取用户工作目录,以及程序运行用户信息。

#include <pwd.h>
#include<sys/types.h>
#include<unistd.h>

if (geteuid() == 0) {
        LOGI("running from root user");
    }

    struct passwd *pw   = getpwuid(getuid());
    const char *homedir = pw->pw_dir;
  • 获取文件大小
fseek(f, 0, SEEK_END);
long pos = ftell(f);
fseek(f, 0, SEEK_SET);

 

posted @ 2018-04-12 11:46  Prefog  阅读(285)  评论(0编辑  收藏  举报