first commit

This commit is contained in:
2021-08-29 00:02:47 +08:00
commit 01e8b33396
52 changed files with 4404 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
SRC := #
SRC += main.c
#OBJ := $(subst .c,.o,$(SRC))
OBJ = $(SRC:%.c=%.o)
CC = gcc
FLAG = -Wall
OPTION = -lpthread -ldl
EXEC_NAME = demo
EXEC_PATH = .
.PHONY:clean demo
demo:$(OBJ)
@echo make ...
$(CC) $^ -o $(EXEC_PATH)/$(EXEC_NAME) $(FLAG) $(OPTION)
@echo make over
@echo Execute target is $(EXEC_PATH)/$(EXEC_NAME)
$(OBJ):%.o:%.c
$(CC) -c -o $@ $< $(FLAG)
clean:
@echo clean ...
rm $(EXEC_PATH)/$(EXEC_NAME) *.o -rf
@echo clean over

Binary file not shown.

View File

@@ -0,0 +1,54 @@
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
// 时间结构体
struct tm *local_time; // time to show or modify
void settime(int tm_hour, int tm_min, int tm_sec)
{
struct tm *time_set = NULL;
struct timeval tv;
struct timezone tz;
/* 获取当前时间 */
gettimeofday(&tv, &tz);
/* 获取当前时间 */
time_set = gmtime(&tv.tv_sec);
/* 设置当前时间结构体 */
time_set->tm_hour = tm_hour;
time_set->tm_min = tm_min;
time_set->tm_sec = tm_sec;
/* 获取用秒表示的时间 */
tv.tv_sec = mktime(time_set);
/* 设置当前时间 */
settimeofday(&tv, &tz);
}
void refresh_clock(void)
{
time_t timep;
time(&timep);
local_time = localtime(&timep); // 读取系统时间
// 时分秒
int hour = local_time->tm_hour;
int minute = local_time->tm_min;
int second = local_time->tm_sec;
printf("h = %d, m = %d, s = %d\n", hour, minute, second);
}
int main(int argc, char *argv[])
{
printf("修改前的时间:\n");
refresh_clock();
settime(11, 34, 50);
printf("修改后的时间:\n");
refresh_clock();
return 0;
}

Binary file not shown.

View File

@@ -0,0 +1 @@
<EFBFBD>޸<EFBFBD>ϵͳʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪrootȨ<EFBFBD>ޣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sudo<EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><EFBFBD><EFBFBD>