Unix/Linux?е?read??write????
???????????? ???????[ 2016/12/19 10:22:39 ] ????????Linux ??????
	????1???????????
	??????????????????д???????????????????????á????????????????????????????????????????????????????????????????????????????????????д????????????open??create???????????????????????????????????????read??write??????
	????2??write????
	????write???????????£?
	????#include < unistd >
	????ssize_t write(int filedes?? void *buf?? size_t nbytes);
	????// ?????????????д???????????????????-1
	????// filedes???????????
	????// buf:??д???????????
	????// nbytes:?д????????
	????
	write?????????????
	#include <error.h>
	#include <fcntl.h>
	#include <string.h>
	#include <sys/types.h>
	int main()
	{
	    int fd = open("./write.txt"?? O_WRONLY  | O_CREAT?? 0666);
	    if (-1 == fd){
	        perror("open file error");
	        return;
	    }
	    char* buff = "write data to file!";
	    ssize_t writelen = write(fd?? buff?? strlen(buff));
	    printf("%d
"?? writelen);
	    close(fd);
	    return 0;
	}
	????3??read????
	????read???????????£?
	????#include < unistd >
	????ssize_t read(int filedes?? void *buf?? size_t nbytes);
	????// ??????????????????????????????????β????0???????????-1
	????// filedes???????????
	????// buf:????????????
	????// nbytes:???????????
	?????м???????????????????????????????????????
	????1?????????????????????????????????????????????磬???????????????????30????????????100????????read????30????????????read???????????0???????????
	????2??????????豸??????????ζ????С?
	????3???????????????????е??????????????????С?????????????????
	????4??????????FIFO??????????????????????????????????????read?????????????????????
	????5???????Щ?????????豸?????????????????ζ???????????
	????6???????????????ж????????????????????
	????
	read?????????????
	#include <error.h>
	#include <fcntl.h>
	#include <string.h>
	#include <sys/types.h>
	int main()
	{
	    int fd = open("./read.txt"?? O_RDONLY | O_CREAT?? 0666);
	    if (-1 == fd){
	        perror("open file error");
	        return;
	    }
	    char buff[1024];
	    memset(buff?? 0?? sizeof(buff));
	    ssize_t readlen = read(fd?? buff?? 1024);
	    printf("%s"?? buff);
	    printf("%d
"?? readlen);
	    close(fd);
	    return 0;
	}
??????
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44
					
			
								
								
								
								
								
								
								
								
								
								
				
sales@spasvo.com