当前位置: 首页 > news >正文

做gif表情包网站天津建设协会网站首页

做gif表情包网站,天津建设协会网站首页,wordpress音乐网站,wordpress 用途1.文件IO 最直观的系统调用 1.1打开文件 int open(const char *pathname, int flags, mode_t mode);功能#xff1a;打开/创建后打开一个文件 返回值#xff1a;成功返回文件描述符#xff0c;失败-10 —— 标准输入 1 —— 标准输出 2 —— 标准出错参数说明#xf…1.文件IO 最直观的系统调用 1.1打开文件 int open(const char *pathname, int flags, mode_t mode);功能打开/创建后打开一个文件 返回值成功返回文件描述符失败-10 —— 标准输入 1 —— 标准输出 2 —— 标准出错参数说明 pathname要打开的某个文件 flags打开文件的方式O_RDONLY只读O_WRONLY只写O_RDWR读写O_APPEND在文件末尾追加O_CREAT文件不存在则创建文件存在则不管O_EXCL和O_CREAT文件不存在则会创建文件存在则直接报错O_TRUNC文件存在就清空 mode创建文件时的权限只有写了O_CREAT的时候才生效如0666最后文件的权限会使用 mode和~umask相与#include fcntl.h #include stdio.hint main() {// 打开文件并以只写方式创建文件权限设置为0644int fileDescriptor open(example.txt, O_CREAT | O_WRONLY, 0644);if (fileDescriptor -1) {perror(open);return 1;}// 写入内容到文件write(fileDescriptor, Hello, this is a file example!\n, 30);// 关闭文件close(fileDescriptor);return 0; }1.2读文件 #include unistd.hssize_t read(int fd, void *buf, size_t count);功能从fd里读取内容存放到buf 返回值成功返回实际读到的字节数失败返回-1参数说明 fd已经打开的文件描述符 buf要存放的缓冲区 count预计要读的字节数不能超过buf的大小#include fcntl.h #include stdio.h #include unistd.hint main() {// 打开文件并以只读方式打开int fileDescriptor open(example.txt, O_RDONLY | O_CREAT , 0644);if (fileDescriptor -1) {perror(open);return 1;}// 读取文件内容到缓冲区char buffer[256];ssize_t bytesRead read(fileDescriptor, buffer, sizeof(buffer) - 1);if (bytesRead -1) {perror(read);return 1;}buffer[bytesRead] \0; // Null-terminate the bufferprintf(Read %ld bytes: %s\n, bytesRead, buffer);// 关闭文件close(fileDescriptor);return 0; }一种简单的图片加密方式 1.3写文件 ssize_t write(int fd, const void *buf, size_t count);功能往fd里写内容 返回值成功返回实际写入的字节数失败返回-1参数说明 fd已经打开的文件描述符 buf存放的要写入的内容的缓冲区 count预计要写的字节数不能超过buf的大小#include fcntl.h #include stdio.h #include unistd.h #include string.h int main() {int fd_src open(open.c, O_RDONLY);if(fd_src 0){ perror(open1);return -1; } int fd_dest open(xxx, O_WRONLY | O_CREAT | O_TRUNC, 0666);if(fd_dest 0){ perror(open2);return -1; } char buf[64];int ret;while(1){memset(buf, 0, sizeof(buf));ret read(fd_src, buf, sizeof(buf));if(ret 0){ perror(read);return -1; }write(fd_dest, buf, ret);} // 关闭文件close(fd_src);return 0; }2.时间函数 #include time.htime_t time(time_t *tloc);功能统计现在的系统时间从1970-1-1 00:00:00到现在所过的秒数 返回值成功就返回这个秒数失败返回-1参数说明 tloc用于存放这个秒数的变量地址time_t tm; tm time(NULL); time(tm);struct tm {int tm_sec; /* Seconds (0-60) */int tm_min; /* Minutes (0-59) */int tm_hour; /* Hours (0-23) */int tm_mday; /* Day of the month (1-31) */int tm_mon; /* Month (0-11) */int tm_year; /* Year - 1900 */int tm_wday; /* Day of the week (0-6, Sunday 0) */int tm_yday; /* Day in the year (0-365, 1 Jan 0) */int tm_isdst; /* Daylight saving time */ };struct tm *gmtime(const time_t *timep);功能将统计的秒数转换成时间结构体的形式 返回值成功返回时间结构体的地址失败返回NULL参数说明 timeptime()的返回值struct tm *localtime(const time_t *timep);功能将统计的秒数转换成时间结构体的形式 返回值成功返回时间结构体的地址失败返回NULL参数说明 timeptime()的返回值char *asctime(const struct tm *tm);功能把系统时间按照固定格式转换成字符串 返回值成功返回字符串的首地址失败返回NULL参数说明 tm转换秒数后的时间结构体char *ctime(const time_t *timep);功能把系统时间按照固定格式转换成字符串 返回值成功返回字符串的首地址失败返回NULL参数说明 timep直接转换秒数到固定字符串格式#include stdio.h #include time.hint main() {// 获取当前系统时间time_t currentTime;time(currentTime);// 转换为GMT时间struct tm *timeInfo gmtime(currentTime);// 打印GMT时间printf(GMT time: %s, asctime(timeInfo));// 转换为本地时间struct tm *localTimeInfo localtime(currentTime);// 打印本地时间printf(Local time: %s, asctime(localTimeInfo));// 直接打印当前系统时间printf(Current time: %s, ctime(currentTime));return 0; }3.文件属性 int stat(const char *pathname, struct stat *statbuf);功能获取文件的属性 返回值成功返回0失败返回-1 pathname要查看的文件 statbuf用于存放信息的结构体地址struct stat {dev_t st_dev; /* ID of device containing file */ino_t st_ino; /* Inode number */mode_t st_mode; /* File type and mode */nlink_t st_nlink; /* Number of hard links */uid_t st_uid; /* User ID of owner */gid_t st_gid; /* Group ID of owner */dev_t st_rdev; /* Device ID (if special file) */off_t st_size; /* Total size, in bytes */blksize_t st_blksize; /* Block size for filesystem I/O */blkcnt_t st_blocks; /* Number of 512B blocks allocated */struct timespec st_atim; /* Time of last access */struct timespec st_mtim; /* Time of last modification */struct timespec st_ctim; /* Time of last status change */#define st_atime st_atim.tv_sec /* Backward compatibility */ #define st_mtime st_mtim.tv_sec #define st_ctime st_ctim.tv_sec };#include stdio.h #include sys/stat.hint main() {// 获取文件属性struct stat fileStat;if (stat(example.txt, fileStat) -1) {perror(stat);return 1;}// 打印文件属性printf(File size: %ld bytes\n, fileStat.st_size);printf(Owner UID: %d\n, fileStat.st_uid);printf(Group GID: %d\n, fileStat.st_gid);printf(Permissions: %o\n, fileStat.st_mode 0777);return 0; }ls-a功能 #include stdio.h #include dirent.h int main(int argc, char *argv[]) { DIR *dirp opendir(.);if(dirp NULL){perror(opendir:);return -1;}struct dirent *dp NULL;while(1){dp readdir(dirp);if(dp NULL){break;}else if(dp-d_name[0] ! .){printf(%s\t,dp-d_name);}}printf(\n);return 0; } ls-l功能 #include stdio.h #include sys/types.h #include sys/stat.h #include dirent.h #include unistd.h #include pwd.h #include grp.h #include time.h #include string.h #include stdlib.h #include libgen.hint main(int argc, char *argv[]) { if(argc 2){printf(请输入路径%s src\n,argv[0]);return -1;}DIR* dirp opendir(argv[1]);if(dirp NULL){perror(opendir:);return -1;}struct dirent* dp NULL;struct stat st;char pathname[1024];while((dp readdir(dirp)) ! NULL){if (strcmp(dp-d_name, .) 0 || strcmp(dp-d_name, ..) 0) {continue;}sprintf(pathname, %s/%s, argv[1], dp-d_name);if (lstat(pathname, st) 0) {perror(lstat:);break;}switch(st.st_mode S_IFMT){case S_IFSOCK: printf(s);break;case S_IFLNK: printf(l);break;case S_IFREG: printf(-);break;case S_IFBLK: printf(b);break;case S_IFDIR: printf(d);break;case S_IFCHR: printf(c);break;case S_IFIFO: printf(p);break;}int n 8;while(n 0){if(st.st_mode 1 n){switch(n%3){case 2:printf(r);break;case 1:printf(w);break;case 0:printf(x);break;}}else{printf(-);}n--;}struct passwd *u_uid getpwuid(st.st_uid);printf( %s,u_uid-pw_name);struct group* g_uid getgrgid(st.st_gid);printf( %s,g_uid-gr_name);printf( %8ld,st.st_size);struct tm *time localtime(st.st_mtime);int month time-tm_mon1;switch(month){case 1: printf( 一月); break;case 2: printf( 二月); break;case 3: printf( 三月); break;case 4: printf( 四月); break;case 5: printf( 五月); break;case 6: printf( 六月); break;case 7: printf( 七月); break;case 8: printf( 八月); break;case 9: printf( 九月); break;case 10: printf( 十月); break;case 11: printf( 十一月); break;case 12: printf( 十二月); break;}printf( %2d %d:%02d %s,time-tm_mday,time-tm_hour,time-tm_min,dp-d_name);printf(\n);}closedir(dirp);return 0; } ls-l功能源文件 #include stdio.h #include sys/types.h #include sys/stat.h #include dirent.h #include unistd.h #include pwd.h #include grp.h #include time.h #include string.h #include stdlib.h #include libgen.hvoid printPermissions(mode_t mode) {printf((S_ISDIR(mode)) ? d : -);printf((mode S_IRUSR) ? r : -);printf((mode S_IWUSR) ? w : -);printf((mode S_IXUSR) ? x : -);printf((mode S_IRGRP) ? r : -);printf((mode S_IWGRP) ? w : -);printf((mode S_IXGRP) ? x : -);printf((mode S_IROTH) ? r : -);printf((mode S_IWOTH) ? w : -);printf((mode S_IXOTH) ? x : -); }void printFileInfo(const char *filename) {struct stat fileStat;if (stat(filename, fileStat) 0) {perror(stat);return;}// 打印文件权限printPermissions(fileStat.st_mode);printf( );// 打印硬链接数printf(%ld , fileStat.st_nlink);// 打印所有者用户名struct passwd *pw getpwuid(fileStat.st_uid);printf(%-2s , pw-pw_name);// 打印所有者所属组名struct group *gr getgrgid(fileStat.st_gid);printf(%-2s , gr-gr_name);// 打印文件大小printf(%5ld , fileStat.st_size);// 打印最后修改时间struct tm *timeinfo;char timeString[80];timeinfo localtime(fileStat.st_mtime);strftime(timeString, sizeof(timeString), %Y年%m月%d日 %H:%M, timeinfo);printf(%s , timeString);// 打印文件名printf(%s\n, basename((char*)filename)); }int main() {char cwd[1024];if (getcwd(cwd, sizeof(cwd)) NULL) {perror(getcwd);return 1;}DIR *dir opendir(cwd);if (!dir) {perror(opendir);return 1;}int blocksize 0;struct dirent *entry;while ((entry readdir(dir)) ! NULL) {// 忽略以.开头的文件隐藏文件if (entry-d_name[0] .)continue;char path[PATH_MAX];snprintf(path, sizeof(path), %s/%s, cwd, entry-d_name);struct stat fileStat;if (stat(path, fileStat) 0) {perror(stat);continue;}blocksize fileStat.st_blocks;}closedir(dir);// 打印总用量总块数printf(总用量%d\n, blocksize / 2);dir opendir(cwd);if (!dir) {perror(opendir);return 1;}while ((entry readdir(dir)) ! NULL) {if (entry-d_name[0] .)continue;char path[PATH_MAX];snprintf(path, sizeof(path), %s/%s, cwd, entry-d_name);printFileInfo(path);}closedir(dir);return 0; }4.库的制作 4.1静态库 ①.生成二进制文件 gcc -c linkstack.c -o linkstack.o②.制作静态库文件把.o文件转换成.a文件 ar crs libmykun.a hello.o //生成libmykun.a这个静态库文件③.编译时链接 gcc linkstack_main.c -L. -llinkstack //-L表示指定库路径-l表示指定具体的库4.2动态库 ①.生成地址无关二进制文件 gcc -fPIC -c linkstack.c②.制作动态库文件 gcc -shared -o liblinkstack.so linkstack.o③.编译时链接 gcc linkstack_main.c -L. -llinkstack //-L表示指定库路径-l表示指定具体的库注动态库程序运行时需要去默认路径加载库 1.把动态库文件拷贝到/lib或者/usr/lib目录下 或 2.配置动态库搜索文件 2.1、sudo vi /etc/ld.so.conf.d/my.conf新建一个my.conf将你的.so文件路径复制进去进行 2.2、把动态库路径存放进文件再次刷新 sudo ldconfig /etc/ld.so.conf.d/my.conf
http://www.pierceye.com/news/225901/

相关文章:

  • 共享虚拟主机做网站够用么抖音短剧推广怎么做
  • 个人网站备案内容写什么西部数码网站管理助手v3.1
  • 搜索引擎 网站模板wordpress 图片走cdn
  • 常见cms网站源码下载重庆微信网站开发公司
  • 网站开发用什么电脑天津室内设计公司排名
  • 云南网站建设招商建设公司网站计入哪个科目
  • 网站备案在哪里查询海外市场推广方案
  • 中诺建设集团有限公司网站微信商家小程序收费吗
  • 沙井品牌网站建设南宁网站提升排名
  • 网站空间备案要多久数商云是外包吗
  • 网站设计公司需要什么资质网站建设所需服务器
  • 织梦cms仿网站教程怎么做网站板块
  • 建设厅网站更改登陆密码wordpress主题 水墨
  • 彩云小梦ai写作网站机关网站建设情况汇报
  • 合肥专业网站优化手机界面设计素材
  • 台州网站建设惠店王烨烨
  • 工程建设比选公告固价方式网站wordpress html5的关系
  • 广州市网站建设 乾图信息科技潍坊市建设监理协会网站
  • 网站建优化网页脚本设计
  • 手机能访问电脑上自己做的网站吗网页设计作品到哪个网站
  • 网站推广成功案例城乡住房建设部官网查询
  • 养殖类网站模板那个网站的公众后推广做的好
  • 网站开发属于什么类型软件建站之星如何建网站
  • 微信做淘宝优惠券但网站是怎么建设但深圳市深圳市住房和建设局网站
  • 后端网站开发免费域名 网站
  • 综合信息网站建设方案网页浏览器排行榜前十名
  • 北京网站开发建设 58同城网站建设改版公司
  • 如何做网站预览网站设计线框图
  • 电子商务的网站的建设内容珠海自适应网站
  • 站酷海洛设计网站官网wordpress选了中文还是英文