2024年网络安全最全嵌入式学习DAY17 --- IO进程的学习_嵌入式 io进程,附答案解析

给大家的福利

零基础入门

对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。

同时每个成长路线对应的板块都有配套的视频提供:

在这里插入图片描述

因篇幅有限,仅展示部分资料

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以点击这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

		 The argument mode points to a string beginning with one of the  follow‐
	       ing sequences (Additional characters may follow these sequences.):

	       r      Open  text  file  for  reading.  The stream is positioned at the
	              beginning of the file.(以读方式打开文本文件,流指针定位在文件开头)

	       r+     Open for reading and writing.  The stream is positioned  at  the
	              beginning of the file.(以读写方式打开文件,流指针定位在文件开头)

	       w      Truncate  file  to  zero length or create text file for writing.
	              The stream is positioned at the beginning of the file.(以擦除方式打开文件或创建文件,该文件只能被写入,流指针定位在文件开头)

	       w+     Open for reading and writing.  The file is created  if  it  does
	              not  exist, otherwise it is truncated.  The stream is positioned
	              at the beginning of the file.(以读写方式打开或创建文件,该文件会被擦除,流指针定位在文件开头)

	       a      Open for appending (writing at end of file).  The file  is  cre‐
	              ated  if it does not exist.  The stream is positioned at the end
	              of the file.(以追加的方式在文件末尾写数据,如果文件不存在,则创建,流指针定位在文件末尾)
				  
		   a+     Open for reading and appending (writing at end  of  file).   The
	              file is created if it does not exist.  The initial file position
	              for reading is at the beginning  of  the  file,  but  output  is
	              always appended to the end of the file.(以读写追加的方式打开,文件不存在就创建,读指针在文件头,写指针在文件末尾)
		   
		   The  mode string can also include the letter 'b' either as a last char‐
	       acter or as a character between the characters in any of the  two-char‐
	       acter strings described above.  This is strictly for compatibility with
	       C89 and has no effect; the 'b' is ignored on all POSIX conforming  sys‐
	       tems,  including Linux.  (Other systems may treat text files and binary
	       files differently, and adding the 'b' may be a good idea if you do  I/O
	       to a binary file and expect that your program may be ported to non-UNIX
	       environments.)针对于非unix类操作系统,想要读取二进制文件,可以加字母b
创建文件
读取文件
	fread
	/*
	 *函数名:fread
	 *函数功能:从文件流中读出内容
	 *函数参数:
	 *		void *ptr:想要存储读出数据的内存首地址
	 *		size_t size:想要读取块所占的大小
	 *		size_t nmemb:想要读取的块的个数
	 *		FILE *stream:被读的文件流指针
	 *函数返回值:int:成功返回读成功块的个数,否则返回EOF或者0或者其他值。
	 */
	size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
往文件中写入数据
	fwrite
	/*
	 *函数名:fwrite
	 *函数功能:往文件流中写入内容
	 *函数参数:
	 *		void *ptr:存储想要写的数据的内存首地址
	 *		size_t size:想要写的块所占的大小
	 *		size_t nmemb:想要写的块的个数
	 *		FILE *stream:被写的文件流指针
	 *函数返回值:int:成功返回写成功块的个数,否则返回EOF或者0或者其他值。
	 */
	size_t fwrite(const void *ptr, size_t size, size_t nmemb,
                 FILE *stream);
关闭文件
	fclose
	/*需要添加的头文件*/
	#include <stdio.h>
	/*
	 *函数名:fclose
	 *函数功能:关闭一个文件流
	 *函数参数:
	 *			FILE *:想要关闭的流指针
	 *函数返回值:int:成功返回0,失败返回错误码
	 */
	int fclose(FILE *fp);
文件重定位:
	fseek
	/*
	 *函数名:fseek
	 *函数功能:
	 *函数参数:
	 *		FILE *stream:被重定位的文件流指针
	 *		long offset:是相对于基准的偏移量
	 *		int whence:基准
	 *函数返回值:key_t:成功返回0,否则返回-1或者错误码。
	 */
	int fseek(FILE *stream, long offset, int whence);
		基准值的取值:
			SEEK_SET:文件头
			SEEK_CUR:当前流指针的位置
			SEEK_END:文件末尾

		offset > 0:往文件末尾的方向移动
		offset < 0:往文件头的方向移动


	ftell
		/*
		 *函数名:ftell
		 *函数功能:
		 *函数参数:
		 *		FILE *stream:想要获取位置的文件流指针
		 *函数返回值:long:返回文件流指针的位置
		 */
		
		long ftell(FILE *stream);

注意:打开文件和关闭文件配对存在,使用完就得关闭

如何判断是否到文件末尾:
	feof()

时间处理:
linux下C获取系统时间的方法:
asctime(将时间和时间以字符串格式表示)
相关函数:
time
ctime
gmtime
localtime

/*需要包含的头文件*/
#include <time.h>
/*
 *函数名:time
 *函数功能:返回从 1970-01-01 00:00:00 +0000 (UTC).到现在的秒数。
 *		   如果参数t非空,返回值也会存入t中。
 *函数参数:
 *		time_t *t:t是一个time_t类型的指针,指向的内存空间用于存储秒数。
 *函数返回值:成功返回从1970年到现在的秒数,失败返回-1/错误码
 */
time_t time(time_t *t);

/*需要包含的头文件*/
#include <time.h>
/*
 *函数名:ctime
 *函数功能:将日期和时间转换为Broken-down时间或ASCII
 *函数参数:
 *		time_t *timep:从time函数获取到的时间
 *函数返回值:char *成功返回时间的描述,失败返回NULL
 */
char *ctime(const time_t *timep);

Broken-down  time  is  stored  in  the structure tm which is defined in
<time.h> as follows:
       struct tm {
           int tm_sec;         /* seconds */
           int tm_min;         /* minutes */
           int tm_hour;        /* hours */
           int tm_mday;        /* day of the month */
           int tm_mon;         /* month */
           int tm_year;        /* year */
           int tm_wday;        /* day of the week */
           int tm_yday;        /* day in the year */
           int tm_isdst;       /* daylight saving time */
       };

The members of the tm structure are:

   tm_sec    The number of seconds after the minute, normally in the range
             0 to 59, but can be up to 60 to allow for leap seconds.

   tm_min    The number of minutes after the hour, in the range 0 to 59.

   tm_hour   The number of hours past midnight, in the range 0 to 23.

   tm_mday   The day of the month, in the range 1 to 31.

   tm_mon    The number of months since January, in the range 0 to 11.

   tm_year   The number of years since 1900.

   tm_wday   The number of days since Sunday, in the range 0 to 6.

   tm_yday   The number of days since January 1, in the range 0 to 365.

   tm_isdst  A  flag  that  indicates  whether  daylight saving time is in
             effect at the time described.  The value is positive if  day‐
             light  saving time is in effect, zero if it is not, and nega‐
             tive if the information is not available.

例子:(打印当前时间)

	#include <stdio.h>
		#include <time.h>

		int main()
		{
		        time_t t;
		        time(&t);
		        char \*p = NULL;
		        printf("%s",ctime(&t));
		        return 0;
		}


/*需要包含的头文件*/
#include <time.h>
/*
 *函数名:gmtime
 *函数功能:将time_t转换为struct tm类型
 *函数参数:
 *		const time_t *timep:time函数获取到的
 *函数返回值:
 *		struct tm *:成功返回结构体指针,失败返回NULL
 */
struct tm *gmtime(const time_t *timep);

/*需要包含的头文件*/
#include <time.h>
/*
 *函数名:localtime
 *函数功能:将time_t转换为struct tm类型
 *函数参数:
 *			const time_t *timep:time函数获取到的
 *函数返回值:
 *			struct tm *:成功返回结构体指针,失败返回NULL
 */
struct tm *localtime(const time_t *timep);

/*需要包含的头文件*/
#include <time.h>
/*
 *函数名:asctime
 *函数功能:将struct tm转换为char *类型
 *函数参数:
 *			struct tm *:gmtime获取到的结构体指针
 *函数返回值:
 *			char *:成功返回字符串形式的时间指针,失败返回NULL
 */
char *asctime(const struct tm *tm);

例子:

#include <stdio.h>
		#include <time.h>

		int main()
		{
		        time_t t;
		        time(&t);
		        printf("%s",asctime(gmtime(&t)));
		        return 0;
		}

建议使用ctime:获取的是当前时区时间/(时区由系统决定)
不建议使用asctime:获取的是格林尼治时间

文件夹操作:
增:mkdir
删:rmdir
查:readdir
打开:opendir/fdopendir
关闭:closedir

1.创建一个文件夹:
/需要添加的头文件/
#include <sys/stat.h>
#include <sys/types.h>
/*函数声明
*函数名:mkdir
*函数功能:创建一个文件夹
*函数参数:

  •   const char *pathname:被创建的文件夹的名字(带路径)
    
    
* ```
 	mode_t mode:(被创建的文件夹的权限)(mode & ~umask & 0777).

*函数返回值:成功返回0,失败返回-1或者错误码
*/
int mkdir(const char *pathname, mode_t mode);

umask:文件权限掩码,002(八进制)
775 & mode

例子:
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(int argc, char *argv[])
{
if(argc != 2)
{
puts(“Usage:./a.out dirname.”);
return -1;
}
mkdir(argv[1], 0777);
return 0;
}

2.删除一个空文件夹:
/需要添加的头文件/
#include <unistd.h>
/*
*函数名:rmdir
*函数功能:删除一个空的文件夹
*函数参数:

  •   const char *pathname:想要删除的文件夹的名字(带路径)
    
    


\*函数返回值:成功返回0,失败返回-1或者错误码  
 \*/  
 int rmdir(const char \*pathname);


例子:


3.打开一个文件夹  
 /*需要添加的头文件*/  
 #include <sys/types.h>  
 #include <dirent.h>


/\*  
 \*函数名:opendir  
 \*函数功能:打开一个文件夹  
 \*函数参数:const char \*name:文件夹名  
 *函数返回值:DIR*:成功返回一个存储文件夹基本信息的结构体指针(即文件夹流指针),失败返回NULL或错误码  
 \*/  
 DIR \*opendir(const char *name);  
 /*  
 \*函数名:fdopendir  
 \*函数功能:打开一个文件夹  
 \*函数参数:int fd:文件夹的文件描述符  
 *函数返回值:DIR*:成功返回一个存储文件夹基本信息的结构体指针,失败返回NULL或错误码  
 \*/  
 DIR \*fdopendir(int fd);


/\* Directory stream type.该格式用于守护进程维护的目录  
 The Hurd directory format is the same as `struct dirent', so`readdir’  
 returns a pointer into the buffer we read directory data into. \*/  
 struct \_\_dirstream  
 {  
 void *\_\_fd; /* `struct hurd_fd' pointer for descriptor. */ char *__data; /* Directory block. */ int __entry_data; /* Entry number`\_\_data’ corresponds to. \*/  
 char *\_\_ptr; /* Current pointer into the block. */  
 int \_\_entry\_ptr; /* Entry number `\_\_ptr’ corresponds to. */  
 size\_t \_\_allocation; /* Space allocated for the block. */  
 size\_t \_\_size; /* Total valid data in the block. */  
 \_\_libc\_lock\_define (, \_\_lock) /* Mutex lock for this structure. \*/  
 };


/\* Directory stream type.


The miscellaneous Unix `readdir' implementations read directory data into a buffer and return`struct dirent \*’ pointers into it. \*/


struct \_\_dirstream  
 {  
 int fd; /\* File descriptor. */  
 \_\_libc\_lock\_define (, lock) /* Mutex lock for this structure. */  
 size\_t allocation; /* Space allocated for the block. */  
 size\_t size; /* Total valid data in the block. */  
 size\_t offset; /* Current offset into the block. */  
 off\_t filepos; /* Position of next entry to read. */  
 int errcode; /* Delayed error code. */  
 /* Directory block. We must make sure that this block starts  
 at an address that is aligned adequately enough to store  
 dirent entries. Using the alignment of “void \*” is not  
 sufficient because dirents on 32-bit platforms can require  
 64-bit alignment. We use “long double” here to be consistent  
 with what malloc uses. \*/  
 char data[0] **attribute** ((aligned (**alignof** (long double))));  
 };


4.关闭文件夹  
 /*需要添加的头文件*/  
 #include <sys/types.h>  
 #include <dirent.h>  
 /\*函数声明  
 \*函数名:closedir  
 \*函数功能:关闭一个文件夹  
 \*函数返参数:DIR \*dirp:想要关闭的文件夹的流指针  
 \*函数返回值:int:成功返回0,失败返回-1或者错误码  
 \*/  
 int closedir(DIR \*dirp);


5.读取文件夹的内容  
 /*需要添加的头文件*/  
 #include <dirent.h>  
 /\*函数声明  
 \*函数名:readdir  
 \*函数功能:读取文件夹的信息  
 \*函数参数:DIR \*dirp:打开后的文件夹的流指针  
 \*函数返回值:struct dirent \*:成功返回文件夹信息的指针,失败返回NULL或错误码  
 \*/  
 struct dirent \*readdir(DIR \*dirp);


struct dirent  
 {  
 #ifdef \_\_USE\_FILE\_OFFSET64  
 \_\_ino64\_t d\_ino;  
 #else  
 \_\_ino\_t d\_ino;  
 int \_\_pad;  
 #endif  
 \_\_off\_t d\_off;  
 unsigned short int d\_reclen;  
 unsigned char d\_type;  
 char d\_name[256]; /\* We must not include limits.h! \*/  
 };


struct dirent  
 {  
 ino\_t d\_ino; /\* inode number */  
 off\_t d\_off; /* offset to the next dirent */  
 unsigned short d\_reclen; /* length of this record */  
 unsigned char d\_type; /* type of file; not supported by all file system types */  
 char d\_name[256]; /* filename \*/  
 };


d\_type:


DT\_BLK This is a block device.  
 DT\_CHR This is a character device.  
 DT\_DIR This is a directory.  
 DT\_FIFO This is a named pipe (FIFO).  
 DT\_LNK This is a symbolic link.  
 DT\_REG This is a regular file.  
 DT\_SOCK This is a UNIX domain socket.  
 DT\_UNKNOWN The file type is unknown.


例子:



#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以点击这里获取

学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
[外链图片转存中…(img-VjNxQzQT-1715442664205)]
[外链图片转存中…(img-WJVveBdb-1715442664206)]
[外链图片转存中…(img-FDX5TVsd-1715442664207)]
[外链图片转存中…(img-81xvKpnd-1715442664207)]
[外链图片转存中…(img-vnJ9X9tE-1715442664207)]
[外链图片转存中…(img-7fOMHaEC-1715442664208)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以点击这里获取

  • 24
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值