美文网首页
系统数据文件和信息

系统数据文件和信息

作者: yuq329 | 来源:发表于2020-06-30 15:08 被阅读0次

    系统数据文件和信息

    #include <pwd.h>
    #include <stddef.h>
    #include <string.h>
    
    struct passwd *getpwnam(const char *name) {
        struct passwd *ptr;
        setpwent();
        while ((ptr = getpwent()) != NULL) {
            //printf("%s\n", ptr->pw_name);
            if (strcmp(name, ptr->pw_name) == 0)
                break;
        }
        endpwent();
        return ptr;
    }
    
    int main() {
        if (getpwnam("root"))
            printf("find root");
        else
            printf("Not find root");
    }
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main(void) {
        time_t t;
        struct tm *tmp;
        char buf1[16];
        char buf2[64];
    
        time(&t);
        tmp = localtime(&t);
        if (strftime(buf1, 16, "time and date: %r, %a %b %d, %Y", tmp) == 0)
            printf("buffer length 16 is too small\n");
        else
            printf("%s\n", buf1);
        if (strftime(buf2, 64, "time and date: %r, %a %b %d, %Y", tmp) == 0)
            printf("buffer length 64 is too small\n");
        else
            printf("%s\n", buf2);
        exit(0);
    }
    

    相关文章

      网友评论

          本文标题:系统数据文件和信息

          本文链接:https://www.haomeiwen.com/subject/dxjxqktx.html