int add_sendFile(struct in_addr* sin_addr, char name[]){ struct stat buf; struct sendfile* newFile = NULL; struct sendfile* rear = send_filelist_head; static unsigned int file_num=0; stat(name,&buf); if ( (newFile = (struct sendfile*)malloc(sizeof(struct sendfile))) == NULL ) { printf("newFile failed!\n"); return 1; } newFile->sin_addr.s_addr = sin_addr->s_addr; strncpy(newFile->name, name, 20); newFile->num=file_num; newFile->pkgnum=time(NULL); newFile->size=buf.st_size; newFile->ltime=buf.st_mtime; while (rear->next != NULL) { rear = rear->next; } rear->next = newFile; newFile->next = NULL; return 0;}注释一下程序
时间: 2024-03-21 21:38:51 浏览: 97
好的,下面是对这段代码的注释:
```c
int add_sendFile(struct in_addr* sin_addr, char name[]){
// 定义变量和指针
struct stat buf;
struct sendfile* newFile = NULL;
struct sendfile* rear = send_filelist_head;
static unsigned int file_num=0;
// 获取文件信息
stat(name,&buf);
// 动态分配一个sendfile结构体
if ( (newFile = (struct sendfile*)malloc(sizeof(struct sendfile))) == NULL ) {
printf("newFile failed!\n");
return 1;
}
// 填充结构体信息
newFile->sin_addr.s_addr = sin_addr->s_addr;
strncpy(newFile->name, name, 20);
newFile->num=file_num;
newFile->pkgnum=time(NULL);
newFile->size=buf.st_size;
newFile->ltime=buf.st_mtime;
// 将结构体加入链表末尾
while (rear->next != NULL) {
rear = rear->next;
}
rear->next = newFile;
newFile->next = NULL;
// 返回操作结果
return 0;
}
```
阅读全文
相关推荐


















