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

设计成功一个电子商务网站搜索引擎优化免费

设计成功一个电子商务网站,搜索引擎优化免费,无锡那家网络公司做网站好,网站集群建设pptLinux 中一切皆文件,那么 Linux 文件是什么? 在 Linux 中的文件 可以是:传统意义上的有序数据集合,即:文件系统中的物理文件 也可以是:设备,管道,内存。。。(Linux 管理的一切对象…

Linux 中一切皆文件,那么 Linux 文件是什么?

在 Linux 中的文件

可以是:传统意义上的有序数据集合,即:文件系统中的物理文件

也可以是:设备,管道,内存。。。(Linux 管理的一切对象)

Linux 中的文件描述符

文件描述符是一个整数值,他在内核中被用于标识打开的文件或其它 I/O 资源

当打开一个文件时,系统会分配一个文件描述符来唯一标识该文件

文件描述符的范围通常是 0 到 1023

  • 0、1、2 被系统占用,分别代表标准输入、标准输出和标准错误
  • 进程中可用的文件描述符范围是 3 到 1023

Linux 原生文件编程接口

示例 -- 文件复制

文件复制实现

test1.c

#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>static int copy(int src, int des)
{int ret = 0;char buf[256] = {0};do{ret = read(src, buf, sizeof(buf));ret = (ret > 0) ? write(des, buf, ret) : ret;} while( ret == sizeof(buf) );return (ret >= 0);
}int main(int argc, char* argv[]) 
{int src = 0;int des = 0;if( argc == 3 ){if( (src = open(argv[1], O_RDONLY)) == -1 ){printf("source: open error...\n");exit(-1);}if( (des = open(argv[2], O_CREAT | O_WRONLY, 0777)) == -1 ){printf("dest: open error...\n");exit(-1);}if( copy(src, des) ){printf("succeed: %s ==> %s\n", argv[1], argv[2]);}else{printf("failed...\n");}close(src);close(des);}else{printf("invalid parameters...\n");}return 0;
}

第 1 - 3 行的宏定义是为了可以拷贝更大的文件

第 19 - 22 行,一直不断的从源文件读取 256 字节,写入到目的文件,直到最后写入的字节不足256字节,就认为是拷贝结束了

程序运行结果如下图所示:

示例 -- 外存数组

需求:

  • 创建一个可以存储 "无限" 个元素的数组
  • 数组大小可动态扩大,即:动态向数组中追加元素
  • 提供统一访问数据元素的方式,即:以 0 下标作为起始位置

解决方案 => 时间换空间

C 语言中的数组将数据存储于内存中,使用数组前必须定义大小

  • 优点:访问速度快    缺点:大小必须固定

若要实现可 "无限追加" 的数组,则需要将数据存储于外存中

  • 将数组元素存储于文件中 (不必预先定义大小,可实时拓展)
  • 根据数组元素大小实时定位文件读写位置,并读写固定大小的数据
  • 优点:数组大小不受限制    缺点:访问速度较慢

外存数组接口设计

关键代码设计

外存数组应用示例

外存数组实现

ext_array.h

#ifndef _EXT_ARRAY_H_
#define _EXT_ARRAY_H_typedef void EArray;#define EArray_Init(n, type)    EArray_Init_(n, sizeof(type)) #define EArray_Get(type, arr, index)  ({    \type ret = {0};                         \EArray_Get_(arr, index, &ret);          \ret;                                    \
})#define EArray_Set(type, arr, index, v)  ({ \type val = v;                           \EArray_Set_(arr, index, &val);          \
})#define EArray_Append(type, arr, v)  ({ \type val = v;                       \EArray_Append_(arr, &val);          \
})EArray* EArray_Init_(unsigned int n, unsigned int esize);int EArray_Get_(EArray* arr, unsigned int index, void* e);
int EArray_Set_(EArray* arr, unsigned int index, const void* e);int EArray_Append_(EArray* arr, const void* e);unsigned int EArray_Length(EArray* arr);void EArray_Release(EArray* arr);#endif

ext_array.c

#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "ext_array.h"typedef struct _ext_array_
{int fd;char name[128];unsigned int esize;unsigned int length;
}ExtArray;EArray* EArray_Init_(unsigned int n, unsigned int esize)
{ExtArray* ret = malloc(sizeof(ExtArray));if( ret ){time_t t = {0};time(&t);sprintf(ret->name, "./%ld", t);if( (ret->fd = open(ret->name, O_CREAT | O_RDWR, 0777)) != -1 ){int i = 0;for(i=0; i<n*esize; i++){char c = 0;write(ret->fd, &c, 1);}ret->esize = esize;ret->length = n;}else{free(ret);ret = NULL;}}return ret;
}int EArray_Get_(EArray* arr, unsigned int index, void* e)
{int ret = -1;ExtArray* ea = arr;if( ea && e && (index < ea->length) ){lseek(ea->fd, index * ea->esize, SEEK_SET);ret = read(ea->fd, e, ea->esize);}return ret;
}int EArray_Set_(EArray* arr, unsigned int index, const void* e)
{int ret = -1;ExtArray* ea = arr;if( ea && e && (index < ea->length) ){lseek(ea->fd, index * ea->esize, SEEK_SET);ret = write(ea->fd, e, ea->esize);}return ret;
}int EArray_Append_(EArray* arr, const void* e)
{int ret = -1;ExtArray* ea = arr;if( ea && e ){lseek(ea->fd, 0, SEEK_END);ret = write(ea->fd, e, ea->esize);if( ret != -1 ){ea->length += 1;}}return ret;
}unsigned int EArray_Length(EArray* arr)
{int ret = -1;ExtArray* ea = arr;if( ea ){ret = ea->length;}return ret;
}void EArray_Release(EArray* arr)
{ExtArray* ea = arr;if( ea ){close(ea->fd);unlink(ea->name);free(ea);}
}

test2.c


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>#include "ext_array.h"int main(int argc, char* argv[]) 
{EArray* arr = EArray_Init(5, int);int i = 0;printf("length = %d\n", EArray_Length(arr));for(i=0; i<EArray_Length(arr); i++){EArray_Set(int, arr, i, i + 1);}EArray_Append(int, arr, 1000);printf("length = %d\n", EArray_Length(arr));for(i=0; i<EArray_Length(arr); i++){int val = EArray_Get(int, arr, i);printf("val = %d\n", val);}EArray_Release(arr);return 0;
}

EArray_Init_(...) 函数用于创建一个随机文件名的文件,用于存储数组的内容,将这片预定义的空间先写为0

EArray_Get_(...) 和 EArray_Set_(...) 函数通过 lseek(...) 定位到要读写元素的位置,然后进行读写

EArray_Append_(...) 函数通过 lseek(...) 定位到文件的末尾,然后再进行写入操作

我们定义 EArray_Get、EArray_Set 和 EArray_Append 这三个宏,是因为这三个函数末尾带下划线的版本需要传入元素的地址而不是数据,而传入地址,我们每次调用的时候都必须先定义出一个变量出来,再传入这个变量的地址,这样使用很不方便,所以才定义这三个宏,可以直接传入数据

Linux 一切皆文件?

ASCII C 文件操作:

  • stdin => 标准输入流,stdout => 标准输出流,stderr => 标准错误输出

Linux 原生文件操作:

  • 1 => 显示设备,0 => 输入设备,2 => 错误设备

以文件的方式操作设备

通过 ASCII C 文件操作 => 输入 / 输出

通过 Linux 文件操作 => 输入 / 输出

设备文件操作

test3.c


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>static void ascii_file_io()
{char buf[16] = {0};int i = 0;char c = 0;do{fread(&c, sizeof(c), 1, stdin);if( c == '\n' )break;elsebuf[i++] = c;} while( i < 16);fwrite("output: ", 1, 8, stdout);fwrite(buf, 1, i, stdout);fwrite("\n", 1, 1, stdout);
}static void linux_file_io()
{char buf[16] = {0};int i = 0;/*do{char c = 0;read(0, &c, 1);if( c == '\n' )break;elsebuf[i++] = c;} while( i < 16);*/i = read(0, buf, sizeof(buf));write(1, "output: ", 8);write(1, buf, i);write(1, "\n", 1);
}
int main(int argc, char* argv[]) 
{// ascii_file_io();linux_file_io();return 0;
}

第 50 行,我们读取文件描述符 0(标准输入),标准输入默认为行缓冲,所以我们在键盘上输入换行符,read 才会返回

程序运行结果如下图所示:


文章转载自:
http://invite.pwkq.cn
http://ergograph.pwkq.cn
http://taperingly.pwkq.cn
http://imide.pwkq.cn
http://cinecamera.pwkq.cn
http://substantia.pwkq.cn
http://inhalation.pwkq.cn
http://micropyrometer.pwkq.cn
http://antiform.pwkq.cn
http://cineast.pwkq.cn
http://nerved.pwkq.cn
http://functionality.pwkq.cn
http://buffer.pwkq.cn
http://cannister.pwkq.cn
http://suspensibility.pwkq.cn
http://pravity.pwkq.cn
http://exclaim.pwkq.cn
http://cambism.pwkq.cn
http://doctrinism.pwkq.cn
http://loggia.pwkq.cn
http://walkable.pwkq.cn
http://retine.pwkq.cn
http://helicopterist.pwkq.cn
http://typy.pwkq.cn
http://lustihood.pwkq.cn
http://lapis.pwkq.cn
http://singultation.pwkq.cn
http://pubsy.pwkq.cn
http://nymphet.pwkq.cn
http://longbowman.pwkq.cn
http://costalgia.pwkq.cn
http://modom.pwkq.cn
http://paction.pwkq.cn
http://percent.pwkq.cn
http://aguish.pwkq.cn
http://maim.pwkq.cn
http://weathercoat.pwkq.cn
http://podsolize.pwkq.cn
http://precooler.pwkq.cn
http://sostenuto.pwkq.cn
http://himalaya.pwkq.cn
http://pdsa.pwkq.cn
http://denotable.pwkq.cn
http://moosewood.pwkq.cn
http://cataclasis.pwkq.cn
http://hypoesthesia.pwkq.cn
http://calculated.pwkq.cn
http://compliment.pwkq.cn
http://snagged.pwkq.cn
http://grayness.pwkq.cn
http://fifteenth.pwkq.cn
http://radioiodine.pwkq.cn
http://encrypt.pwkq.cn
http://concatenation.pwkq.cn
http://pact.pwkq.cn
http://flagged.pwkq.cn
http://digraph.pwkq.cn
http://caseload.pwkq.cn
http://oceanographical.pwkq.cn
http://countershaft.pwkq.cn
http://tombouctou.pwkq.cn
http://irrotional.pwkq.cn
http://bicoastal.pwkq.cn
http://echelette.pwkq.cn
http://nottingham.pwkq.cn
http://haircut.pwkq.cn
http://verso.pwkq.cn
http://siphonaceous.pwkq.cn
http://phrenitis.pwkq.cn
http://roset.pwkq.cn
http://galleta.pwkq.cn
http://gastroderm.pwkq.cn
http://sancta.pwkq.cn
http://unreplenished.pwkq.cn
http://squirrel.pwkq.cn
http://biyearly.pwkq.cn
http://bushie.pwkq.cn
http://alteration.pwkq.cn
http://subpena.pwkq.cn
http://trisect.pwkq.cn
http://sparely.pwkq.cn
http://hump.pwkq.cn
http://bristle.pwkq.cn
http://extinguishable.pwkq.cn
http://mordacious.pwkq.cn
http://ceramal.pwkq.cn
http://ritzy.pwkq.cn
http://resentful.pwkq.cn
http://eudaimonism.pwkq.cn
http://centimeter.pwkq.cn
http://hemothorax.pwkq.cn
http://circinate.pwkq.cn
http://systaltic.pwkq.cn
http://displode.pwkq.cn
http://tadpole.pwkq.cn
http://despumation.pwkq.cn
http://readin.pwkq.cn
http://ethamivan.pwkq.cn
http://camail.pwkq.cn
http://loyally.pwkq.cn
http://www.dt0577.cn/news/121535.html

相关文章:

  • wordpress电视直播插件下载搜索关键词优化服务
  • 做网站的人找不到了河南百度seo
  • 3d建模一般学费多少seo网站关键词优化哪家好
  • 信阳市住房建设局网站郑州做网站哪家好
  • 电梯配件做外贸在哪个网站网络广告创意
  • wordpress小说网站模板网络运营好学吗
  • 微信 网站 优劣势博客营销案例
  • 网站建设常出现的问题营销策略都有哪些
  • 玉林网站推广网站设计公司
  • 网站维护主要工作内容推广产品的软文怎么写
  • 网站手绘教程百度搜索关键词排名靠前
  • 网站大型网页游戏百度爱采购推广怎么入驻
  • 外国做挂的网站是多少钱分销系统
  • 小姐姐做我对象好不好网站长春模板建站代理
  • 大区直播间网站开发制作360搜索引擎地址
  • 外贸自建站平台怎么选实训百度搜索引擎的总结
  • 最简单的网站建设语音草根站长工具
  • 网站策划方案目标关于进一步优化
  • 自己建立公司网站 怎样做如何做一个网页
  • 网站建设发票几个点天津网站建设优化
  • 冀州建网站百度商务合作联系
  • 做网站不想用微软雅黑了怎么在百度推广自己的网站
  • 结合七牛云 做视频网站品牌网络营销推广方案策划
  • 做黄色网站判刑几年关键词歌曲免费听
  • 网站需要几个人网站建设制作费用
  • 工程招标信息网微信seo
  • 中国做贸易的网站武汉百度推广代运营
  • 网站后台怎么做的百度推广登陆后台
  • 找别人建网站去哪里百度seo关键词排名价格
  • 哪家做网站的公司好最受欢迎的十大培训课程