diff --git a/6/etc/group.c b/6/etc/group.c new file mode 100644 index 0000000..15167bb --- /dev/null +++ b/6/etc/group.c @@ -0,0 +1,25 @@ +#include +#include + +int main(void){ + + struct group *p_gp = getgrnam("sudo"); + + if(p_gp == NULL) { + printf("getgrgid error\n"); + return -1; + } + + printf("%d %s", p_gp->gr_gid, p_gp->gr_name); + + char **p_men = p_gp->gr_mem; + + while(*p_men != NULL){ + printf(" %s", *p_men); + p_men++; + } + + printf("\n"); + + return 0; +} diff --git a/6/etc/pwd.c b/6/etc/pwd.c new file mode 100644 index 0000000..a20d87f --- /dev/null +++ b/6/etc/pwd.c @@ -0,0 +1,19 @@ +#include +#include + + +int main(void) { + + struct passwd *p_pwd = getpwnam("eric"); + + printf("%d %d %s %s %s\n", p_pwd->pw_uid, p_pwd->pw_gid, p_pwd->pw_name, p_pwd->pw_shell, p_pwd->pw_passwd); + + + while((p_pwd = getpwent()) != NULL) { + printf("%d %d %s %s\n", p_pwd->pw_uid, p_pwd->pw_gid, p_pwd->pw_name, p_pwd->pw_shell); + } + + endpwent(); + + return 0; +} diff --git a/6/etc/spwd.c b/6/etc/spwd.c new file mode 100644 index 0000000..9fdb1e6 --- /dev/null +++ b/6/etc/spwd.c @@ -0,0 +1,14 @@ +#include +#include + +int main(void) { + struct spwd *p_spwd = getspnam("eric"); + + printf("%s %s %ld %lu\n", p_spwd->sp_namp, p_spwd->sp_pwdp, p_spwd->sp_flag, p_spwd->sp_max); + + printf("%ld %ld %ld\n", p_spwd->sp_min, p_spwd->sp_inact, p_spwd->sp_warn); + + endspent(); + + return 0; +} diff --git a/6/etc/uname.c b/6/etc/uname.c new file mode 100644 index 0000000..dc678c2 --- /dev/null +++ b/6/etc/uname.c @@ -0,0 +1,15 @@ +#include +#include + +int main(void) { + struct utsname utsn; + + if(uname(&utsn) < 0) { + printf("uname error\n"); + return -1; + } + + printf("%s %s %s %s\n", utsn.sysname, utsn.nodename, utsn.machine, utsn.release); + printf("%s\n", utsn.version); + return 0; +} diff --git a/6/time/clock.c b/6/time/clock.c new file mode 100644 index 0000000..2925c4f --- /dev/null +++ b/6/time/clock.c @@ -0,0 +1,36 @@ +#include +#include +#include + +int main(void) { + struct timespec tsp; + if(clock_gettime(CLOCK_REALTIME, &tsp) < 0) { + printf("clock_gettime error\n"); + return -1; + } + + printf("real time: %lu %lu\n", tsp.tv_sec, tsp.tv_nsec);; + + if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tsp) < 0) { + printf("clock_gettime error\n"); + return -1; + } + + printf("cpu time: %lu %lu\n", tsp.tv_sec, tsp.tv_nsec);; + + if(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tsp) < 0) { + printf("clock_gettime error\n"); + return -1; + } + + printf("thread time: %lu %lu\n", tsp.tv_sec, tsp.tv_nsec);; + + if(clock_getres(CLOCK_REALTIME, &tsp) < 0) { + printf("clock_getres error\n"); + return -1; + } + + printf("real time res: %lu %lu\n", tsp.tv_sec, tsp.tv_nsec);; + + return 0; +} diff --git a/6/time/format.c b/6/time/format.c new file mode 100644 index 0000000..7ab59b1 --- /dev/null +++ b/6/time/format.c @@ -0,0 +1,50 @@ +#include +#include + + +void printTm(struct tm *ptm) { + printf("%d-%d-%d\n", 1900 + ptm->tm_year, 1 + ptm->tm_mon, ptm->tm_mday); + printf("%d:%d:%d\n", ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + printf("\n"); +} + +int main(void) { + time_t t = time(NULL); + struct tm * ptm = gmtime(&t); + + printTm(ptm); + + ptm = localtime(&t); + + printTm(ptm); + + t = mktime(ptm); + + printf("time: %lu\n", t); + + char buf[1024]; + + size_t wbit = strftime(buf , sizeof(buf), "%D %T %r %Z", ptm); + + if(wbit == 0) { + printf("strftime error\n"); + return -1; + } + + printf("format: %s\n", buf); + + sprintf(buf, "09/04/00 1:00:00"); + + strptime((const char *)buf, "%x %X", ptm); + + wbit = strftime(buf , sizeof(buf), "%D %T %r %Z", ptm); + + if(wbit == 0) { + printf("strftime error\n"); + return -1; + } + + printf("check format: %s\n", buf); + + return 0; +} diff --git a/6/time/time.c b/6/time/time.c new file mode 100644 index 0000000..3ec2e70 --- /dev/null +++ b/6/time/time.c @@ -0,0 +1,8 @@ +#include +#include + +int main(void) { + time_t t = time(NULL); + printf("%lu\n", t); + return 0; +}