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

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

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

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);
相关文章
相关标签/搜索