本文整理汇总了C++中checkname函数的典型用法代码示例。如果您正苦于以下问题:C++ checkname函数的具体用法?C++ checkname怎么用?C++ checkname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了checkname函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: InitStack
//.........这里部分代码省略.........
p--;
while(p>=S.base)
{
printf("%d ", *p);
p--;
}
}
printf("\n");
return OK;
}
void search(struct total&ex)//查询线路
{
char x[10];
int i,j,index;
printf("请输入您要查询的线路\n");
scanf("%s",x);
for(i=0; i<ex.totalline; i++)
{
if(strcmp(ex.line[i].linenumber,x)==0)
{
index=i;
break;
}
}
for(j=0; j<ex.line[index].stopcount; j++)
{
printf("%s ",ex.line[index].station[j].stopname);
}
printf("\n");
printf("按任意键返回主菜单\n");
system("pause");
}
int checkname(char *s,Mgraph C)//判断是否存在该站点
{
int i;
for(i=0;i<C.vexnum;i++)
if(strcmp(s,C.vex[i].name)==0)
return 1;
return 0;
}
void searchname(struct total&ex,Mgraph C)//按站点名称查询线路
{
char x[20];
int i,j;
int count=0;//存储找到的线路的个数
while(1)
{
printf("请输入您要查询的站点名称\n");
scanf("%s",x);
if(checkname(x,C)==0)
printf("该站点不存在,请重新输入");
else break;
}
for(i=0; i<ex.totalline; i++)
{
for(j=0; j<ex.line[i].stopcount; j++)
{
if(strcmp(ex.line[i].station[j].stopname,x)==0)
{
printf("%s\n",ex.line[i].linenumber);
count++;
}
}
if(j<ex.line[i].stopcount)
break;
开发者ID:zz0807,项目名称:learngit,代码行数:67,代码来源:main.cpp
示例2: recfield
static void recfield (LexState *ls, struct ConsControl *cc)
{
/* recfield -> (NAME | `['exp1`]') = exp1 */
FuncState *fs = GetCurrentFuncState( ls );
int reg = fs->freereg;
expdesc key, val;
if (ls->t.token == TK_NAME)
{
luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
checkname(ls, &key);
}
else /* ls->t.token == '[' */
{
yindex(ls, &key);
}
cc->nh++;
checknext(ls, '=');
int rkkey = luaK_exp2RK(fs, &key);
expr(ls, &val);
luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));
fs->freereg = reg; /* free registers */
}
开发者ID:qaisjp,项目名称:green-candy,代码行数:26,代码来源:lparser.c
示例3: primaryexp
static void primaryexp (LexState *ls, expdesc *v) {
/* primaryexp ->
prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
FuncState *fs = ls->fs;
prefixexp(ls, v);
for (;;) {
switch (ls->t.token) {
case '.': { /* field */
field(ls, v);
break;
}
case '[': { /* `[' exp1 `]' */
expdesc key;
luaK_exp2anyreg(fs, v);
yindex(ls, &key);
luaK_indexed(fs, v, &key);
break;
}
case ':': { /* `:' NAME funcargs */
expdesc key;
luaX_next(ls);
checkname(ls, &key);
luaK_self(fs, v, &key);
funcargs(ls, v);
break;
}
case '(': case TK_STRING: case '{': { /* funcargs */
luaK_exp2nextreg(fs, v);
funcargs(ls, v);
break;
}
default: return;
}
}
}
开发者ID:xiaofeng,项目名称:Arcemu,代码行数:35,代码来源:lparser.c
示例4: searchname
void searchname(struct total&ex,Mgraph C)//按站点名称查询线路
{
char x[20];
int i,j;
int count=0;//存储找到的线路的个数
while(1)
{
printf("请输入您要查询的站点名称\n");
scanf("%s",x);
if(checkname(x,C)==0)
printf("该站点不存在,请重新输入");
else break;
}
for(i=0; i<ex.totalline; i++)
{
for(j=0; j<ex.line[i].stopcount; j++)
{
if(strcmp(ex.line[i].station[j].stopname,x)==0)
{
printf("%s\n",ex.line[i].linenumber);
count++;
}
}
if(j<ex.line[i].stopcount)
break;
}
if(count==0)
printf("没有找到您输入的站点\n");
}
开发者ID:zz0807,项目名称:learngit,代码行数:31,代码来源:main.cpp
示例5: field
static void field (LexState *ls, expdesc *v) {
/* field -> ['.' | ':'] NAME */
FuncState *fs = ls->fs;
expdesc key;
luaK_exp2anyreg(fs, v);
luaX_next(ls); /* skip the dot or colon */
checkname(ls, &key);
luaK_indexed(fs, v, &key);
}
开发者ID:xiaofeng,项目名称:Arcemu,代码行数:9,代码来源:lparser.c
示例6: openin
/*
* open input file
* Input : char* p
* Output : int error code
*
* Try to open the file whose filename is p, return YES if opened, else NO
* Updates fname with the actual opened name
* input is the handle of the opened file
*
*/
int openin (char *p)
{
strcpy(fname, p);
strcpy(fname_copy, fname);
fixname (fname);
if (!checkname (fname))
return (NO);
if ((input = fopen (fname, "r")) == NULL) {
pl ("Open failure\n");
return (NO);
}
kill_line ();
return (YES);
}
开发者ID:BouKiCHi,项目名称:husic_git,代码行数:25,代码来源:io.c
示例7: remove_file
int remove_file(struct inode *dir, const char *name){
/*判断目录是否有效*/
if(dir->ext2_inode.i_block[0] != UINT_MAX){
perror("inode_operations.c: remove_file error! current dir is a file!\n");
return -1;
}
/*判断名字是否有效*/
if(checkname(name) == -1){
perror("inode_operations.c: remove_file error! filename is illegal!\n");
return -1;
}
char buf[BLOCK_SIZE];
struct ext2_dir_entry_2 *pentry;
int dir_datablocks = dir->ext2_inode.i_blocks;/*数据块个数*/
int i = 1;
int j = 0;
int num = BLOCK_SIZE/sizeof(struct ext2_dir_entry_2);
while(i <= dir_datablocks){
/*取出目录节点中第i块逻辑块所在的物理块的数据,放入buf*/
get_block_data(dir->ext2_inode.i_block[i],buf);
pentry = (struct ext2_dir_entry_2 *)buf;
//printf("inode_operations.c: check : dir_datablocks: %d\n",i);
/*比较每一项*/
while(j<num){
//printf("inode_operations.c: check : entry: %d\n",j);
/*比较pentry->inode不为0的每一项*/
if(pentry->inode && !strcmp(pentry->name,name)){
if(free_inode(pentry->inode) == -1){
perror("节点释放失败!\n");
return -1;
};
/*清空该目录项*/
memset(pentry,'\0',sizeof(struct ext2_dir_entry_2));
/*写回磁盘,更新数据*/
write_block_data(dir->ext2_inode.i_block[i],buf);
return 1;
}
j++;
pentry++;
}
i++;
}
printf("no such file,please check your filename!\n");
return -1;
}
开发者ID:Naturing,项目名称:ext2_emulation,代码行数:45,代码来源:inode_operations.c
示例8: checkbase
void checkbase(Student *stu) //根据条件查询
{
int type;
do
{
printf("\n请输入序号选择相应功能\n");
printf("******** 1.按学号查询 ********\n");
printf("******** 2.按姓名查询 ********\n");
printf("******** 3.按名次查询 ********\n");
printf("******** 0.退出 ********\n");
scanf("%d",&type);
switch(type)
{
case 0:printf("");break;
case 1:checknum(stu);break;
case 2:checkname(stu);break;
case 3:checkrank(stu);break;
default:printf("没有该选项,请重输");break;
}
}while(type!=0);
}
开发者ID:zhangsheng377,项目名称:studentmanage,代码行数:21,代码来源:Cpp1.cpp
示例9: expression
int expression()
{
//printf("begin to do expression\n");
kope=0;
knum=0;
typ=2;
char exp[80]="";
int expj=0;
ifexpression=0;
gets(exp);
/*ÐèҪɾ³ý*/integer=1;
do{
printf("now string=%s\n",string);
printf("now number=%d\n",integer);
printf("now type=%d\n",typ);
//len=strlen(string);
if (typ==2)
{
knum++;
num[knum]=integer;
}
if (typ==1)
{
//printf("find a operater\n");
if ((string[0]==')'))
{
doexpression();
}
else
{
kope++;
operater[kope]=string[0];
}
}
if (exp[expj]==0) break;
if ((exp[expj]=='+')||(exp[expj]=='-')||(exp[expj]=='*')||(exp[expj]=='/')||(exp[expj]='(')||(exp[expj]=')'))
{
//printf("findstring\n");
string[0]=exp[expj];
string[1]='\0';
//printf("finish\n");
do{
expj++;
}while (exp[expj]==' ');
typ=1;
}
else
if (exp[expj]=':')
{
//printf("find :\n");
memset(string,0,80);
int i=0;
while ((exp[expj]!=' ')&&(exp[expj]!=0))
{
string[i]=exp[expj];
expj++;
}
int ctf=checkname(1,string);
if (ctf==0)
{
return 0;
}
int x=findidentifier(string);
if (x==0)
{
printf("error:this word is not defined!\n");
return 0;
}
if (identifier.type[x]==1)
{
printf("string can't be calculated in a expression!\n");
return 0;
}
integer=identifier.intvalue[x];
while (exp[expj]==' ')
{
expj++;
}
}else
{
printf("find digit\n");
integer=0;
while ((exp[expj]>='0')&&(exp[expj]<='9'))
{
integer=integer*10+exp[expj]-'0';
expj++;
}
typ=2;
while (exp[expj]==' ')
{
expj++;
}
}
printf("finish\n");
}while (1);
ifre=1;
doexpression();
return 2;
}
开发者ID:denil1111,项目名称:Logo,代码行数:99,代码来源:备份.c
示例10: primaryexp
static void primaryexp (LexState *ls, expdesc *v) {
/* primaryexp ->
prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
FuncState *fs = ls->fs;
prefixexp(ls, v);
for (;;) {
switch (ls->t.token) {
case '.': { /* field */
field(ls, v);
break;
}
case '[': { /* `[' exp1 `]' */
expdesc key;
luaK_exp2anyreg(fs, v);
yindex(ls, &key);
luaK_indexed(fs, v, &key);
break;
}
case ':': { /* `:' NAME funcargs */
expdesc key;
luaX_next(ls);
checkname(ls, &key);
luaK_self(fs, v, &key);
funcargs(ls, v);
break;
}
#if LUA_WIDESTRING
case '(': case TK_STRING: case TK_WSTRING: case '{': { /* funcargs */
#else
case '(': case TK_STRING: case '{': { /* funcargs */
#endif /* LUA_WIDESTRING */
luaK_exp2nextreg(fs, v);
funcargs(ls, v);
break;
}
default: return;
}
}
}
static void simpleexp (LexState *ls, expdesc *v) {
#if LUA_WIDESTRING
/* simpleexp -> NUMBER | STRING | WSTRING | NIL | true | false | ... |
constructor | FUNCTION body | primaryexp */
#else
/* simpleexp -> NUMBER | STRING | NIL | true | false | ... |
constructor | FUNCTION body | primaryexp */
#endif /* LUA_WIDESTRING */
switch (ls->t.token) {
case TK_NUMBER: {
init_exp(v, VKNUM, 0);
v->u.nval = ls->t.seminfo.r;
break;
}
case TK_STRING: {
codestring(ls, v, ls->t.seminfo.ts);
break;
}
#if LUA_WIDESTRING
case TK_WSTRING: {
codewstring(ls, v, ls->t.seminfo.ts);
break;
}
#endif /* LUA_WIDESTRING */
case TK_NIL: {
init_exp(v, VNIL, 0);
break;
}
case TK_TRUE: {
init_exp(v, VTRUE, 0);
break;
}
case TK_FALSE: {
init_exp(v, VFALSE, 0);
break;
}
case TK_DOTS: { /* vararg */
FuncState *fs = ls->fs;
check_condition(ls, fs->f->is_vararg,
"cannot use " LUA_QL("...") " outside a vararg function");
fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */
init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
break;
}
case '{': { /* constructor */
constructor(ls, v);
return;
}
case TK_FUNCTION: {
luaX_next(ls);
body(ls, v, 0, ls->linenumber);
return;
}
default: {
primaryexp(ls, v);
return;
}
}
luaX_next(ls);
//.........这里部分代码省略.........
开发者ID:henryfung01,项目名称:GameCode4,代码行数:101,代码来源:lparser.c
示例11: create
int create(struct inode *dir, const char *name, int len, int mode, struct inode ** res_inode){
/*判断目录是否有效*/
if(dir->ext2_inode.i_block[0] != UINT_MAX){
perror("inode_operations.c: create error! dir is a file!\n");
return -1;
}
/*判断名字是否有效*/
if(checkname(name) == -1){
perror("inode_operations.c: create error! filename is illegal!\n");
return -1;
}
/*判断是否已存在*/
if(is_exist(dir,name) == 1){
perror("inode_operations.c: create error! file is alreay exists!\n");
return -1;
}
char buf[BLOCK_SIZE];
struct ext2_dir_entry_2 *pentry;
int dir_datablocks = dir->ext2_inode.i_blocks;/*数据块个数*/
int i = 1;
int num = BLOCK_SIZE/sizeof(struct ext2_dir_entry_2);
while(i <= dir_datablocks){
/*取出目录节点中第i块逻辑块所在的物理块的数据,放入buf*/
get_block_data(dir->ext2_inode.i_block[i],buf);
pentry = (struct ext2_dir_entry_2 *)buf;
/*寻找pentry->inode为0的每一项,表示未使用,填写目录项*/
//printf("inode_operations.c: create : dir_datablocks: %d\n",i);
int j = 0;
while(j<num){
//printf("inode_operations.c: create : entry: %d\n",j);
if(!pentry->inode){
pentry->name_len = len;
strcpy(pentry->name,name);
pentry->file_type = mode;
pentry->rec_len = 8 + len;
pentry->inode = new_inode();
write_block_data(dir->ext2_inode.i_block[i],buf);//更新该数据块
*res_inode=(struct inode *)malloc(sizeof(struct inode));
if(*res_inode != NULL){
get_inode_data(pentry->inode,*res_inode);
return 1;
}
}
j++;
pentry++;
}
i++;
}
/*数据块表项已满,则需申请新的数据块来存放新的目录项*/
if(dir_datablocks>=14){
perror("inode_operations.c create error! dir_entry is full,no more sub_dir!\n");
return -1;
}
dir_datablocks = ++(dir->ext2_inode.i_blocks);
dir->ext2_inode.i_block[dir_datablocks] = new_block();
write_inode_data(dir->i_number,dir);//因为申请了新块,inode节点及时更新
get_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);
pentry = (struct ext2_dir_entry_2 *)buf;
pentry->name_len = len;
strcpy(pentry->name,name);
pentry->file_type = mode;
pentry->rec_len = 8 + len;
pentry->inode = new_inode();
write_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);//更新该数据块
if((*res_inode=(struct inode *)malloc(sizeof(struct inode))) != NULL){
get_inode_data(pentry->inode,*res_inode);
return 1;
}
return -1;
}
开发者ID:Naturing,项目名称:ext2_emulation,代码行数:71,代码来源:inode_operations.c
示例12: main
//.........这里部分代码省略.........
case 'F':
setfstab(optarg);
break;
case 'f':
fflag |= MNT_FORCE;
break;
case 'h': /* -h implies -A. */
all = 2;
nfshost = optarg;
break;
case 'N':
nfsforce = 1;
break;
case 'n':
fflag |= MNT_NONBUSY;
break;
case 't':
if (typelist != NULL)
err(1, "only one -t option may be specified");
typelist = makevfslist(optarg);
break;
case 'v':
vflag = 1;
break;
default:
usage();
/* NOTREACHED */
}
argc -= optind;
argv += optind;
if ((fflag & MNT_FORCE) != 0 && (fflag & MNT_NONBUSY) != 0)
err(1, "-f and -n are mutually exclusive");
/* Start disks transferring immediately. */
if ((fflag & (MNT_FORCE | MNT_NONBUSY)) == 0 && nfsforce == 0)
sync();
if ((argc == 0 && !all) || (argc != 0 && all))
usage();
if (nfsforce != 0 && (argc == 0 || nfshost != NULL || typelist != NULL))
usage();
/* -h implies "-t nfs" if no -t flag. */
if ((nfshost != NULL) && (typelist == NULL))
typelist = makevfslist("nfs");
if (nfshost != NULL) {
memset(&hints, 0, sizeof hints);
error = getaddrinfo(nfshost, NULL, &hints, &nfshost_ai);
if (error)
errx(1, "%s: %s", nfshost, gai_strerror(error));
}
switch (all) {
case 2:
if ((mntsize = mntinfo(&mntbuf)) <= 0)
break;
/*
* We unmount the nfs-mounts in the reverse order
* that they were mounted.
*/
for (errs = 0, mntsize--; mntsize > 0; mntsize--) {
sfs = &mntbuf[mntsize];
if (checkvfsname(sfs->f_fstypename, typelist))
continue;
if (strcmp(sfs->f_mntonname, "/dev") == 0)
continue;
if (umountfs(sfs) != 0)
errs = 1;
}
free(mntbuf);
break;
case 1:
if (setfsent() == 0)
err(1, "%s", getfstab());
errs = umountall(typelist);
break;
case 0:
for (errs = 0; *argv != NULL; ++argv)
if (nfsforce != 0) {
/*
* First do the nfssvc() syscall to shut down
* the mount point and then do the forced
* dismount.
*/
ret = nfssvc(NFSSVC_FORCEDISM, *argv);
if (ret >= 0)
ret = unmount(*argv, MNT_FORCE);
if (ret < 0) {
warn("%s", *argv);
errs = 1;
}
} else if (checkname(*argv, typelist) != 0)
errs = 1;
break;
}
exit(errs);
}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:101,代码来源:umount.c
示例13: f_create
void
f_create(Chan *cp, Oldfcall *in, Oldfcall *ou)
{
Iobuf *p, *p1;
Dentry *d, *d1;
File *f;
int slot, slot1, fmod;
int32_t addr, addr1, path;
Qid qid;
Tlock *t;
Wpath *w;
if(CHAT(cp)) {
print("c_create %d\n", cp->chan);
print(" fid = %d\n", in->fid);
print(" name = %s\n", in->name);
print(" perm = %lx+%lo\n", (in->perm>>28)&0xf,
in->perm&0777);
print(" mode = %d\n", in->mode);
}
p = 0;
f = filep(cp, in->fid, 0);
if(!f) {
ou->err = Efid;
goto out;
}
if(isro(f->fs->dev) || (cp != cons.chan && writegroup && !ingroup(f->uid, writegroup))) {
ou->err = Eronly;
goto out;
}
p = getbuf(f->fs->dev, f->addr, Bread);
d = getdir(p, f->slot);
if(!d || checktag(p, Tdir, QPNONE) || !(d->mode & DALLOC)) {
ou->err = Ealloc;
goto out;
}
if(ou->err = mkqidcmp(&f->qid, d))
goto out;
if(!(d->mode & DDIR)) {
ou->err = Edir2;
goto out;
}
if(cp != cons.chan && iaccess(f, d, DWRITE) && !writeallow) {
ou->err = Eaccess;
goto out;
}
accessdir(p, d, FREAD);
if(!strncmp(in->name, ".", sizeof(in->name)) ||
!strncmp(in->name, "..", sizeof(in->name))) {
ou->err = Edot;
goto out;
}
if(checkname(in->name)) {
ou->err = Ename;
goto out;
}
addr1 = 0;
slot1 = 0; /* set */
for(addr=0;; addr++) {
p1 = dnodebuf(p, d, addr, 0);
if(!p1) {
if(addr1)
break;
p1 = dnodebuf(p, d, addr, Tdir);
}
if(p1 == 0) {
ou->err = Efull;
goto out;
}
if(checktag(p1, Tdir, d->qid.path)) {
putbuf(p1);
goto phase;
}
for(slot=0; slot<DIRPERBUF; slot++) {
d1 = getdir(p1, slot);
if(!(d1->mode & DALLOC)) {
if(!addr1) {
addr1 = p1->addr;
slot1 = slot + addr*DIRPERBUF;
}
continue;
}
if(!strncmp(in->name, d1->name, sizeof(in->name))) {
putbuf(p1);
ou->err = Eexist;
goto out;
}
}
putbuf(p1);
}
switch(in->mode & 7) {
case MEXEC:
case MREAD: /* seems only useful to make directories */
fmod = FREAD;
break;
case MWRITE:
fmod = FWRITE;
//.........这里部分代码省略.........
开发者ID:dancrossnyc,项目名称:harvey,代码行数:101,代码来源:9p1.c
示例14: f_wstat
void
f_wstat(Chan *cp, Oldfcall *in, Oldfcall *ou)
{
Iobuf *p, *p1;
Dentry *d, *d1, xd;
File *f;
int slot;
int32_t addr;
if(CHAT(cp)) {
print("c_wstat %d\n", cp->chan);
print(" fid = %d\n", in->fid);
}
p = 0;
p1 = 0;
d1 = 0;
f = filep(cp, in->fid, 0);
if(!f) {
ou->err = Efid;
goto out;
}
if(isro(f->fs->dev) || (cp != cons.chan && writegroup && !ingroup(f->uid, writegroup))) {
ou->err = Eronly;
goto out;
}
/*
* first get parent
*/
if(f->wpath) {
p1 = getbuf(f->fs->dev, f->wpath->addr, Bread);
d1 = getdir(p1, f->wpath->slot);
if(!d1 || checktag(p1, Tdir, QPNONE) || !(d1->mode & DALLOC)) {
ou->err = Ephase;
goto out;
}
}
p = getbuf(f->fs->dev, f->addr, Bread);
d = getdir(p, f->slot);
if(!d || checktag(p, Tdir, QPNONE) || !(d->mode & DALLOC)) {
ou->err = Ealloc;
goto out;
}
if(ou->err = mkqidcmp(&f->qid, d))
goto out;
convM2D9p1(in->stat, &xd);
if(CHAT(cp)) {
print(" d.name = %s\n", xd.name);
print(" d.uid = %d\n", xd.uid);
print(" d.gid = %d\n", xd.gid);
print(" d.mode = %.4x\n", xd.mode);
}
/*
* if chown,
* must be god
*/
while(xd.uid != d->uid) {
if(wstatallow) /* set to allow chown during boot */
break;
ou->err = Enotu;
goto out;
}
/*
* if chgroup,
* must be either
* a) owner and in new group
* b) leader of both groups
*/
while(xd.gid != d->gid) {
if(wstatallow || writeallow) /* set to allow chgrp during boot */
break;
if(d->uid == f->uid && ingroup(f->uid, xd.gid))
break;
if(leadgroup(f->uid, xd.gid))
if(leadgroup(f->uid, d->gid))
break;
ou->err = Enotg;
goto out;
}
/*
* if rename,
* must have write permission in parent
*/
if(xd.name[0] == 0)
strncpy(xd.name, d->name, sizeof(xd.name));
while(strncmp(d->name, xd.name, sizeof(d->name)) != 0) {
if(checkname(xd.name)) {
ou->err = Ename;
goto out;
}
if(strcmp(xd.name, ".") == 0 || strcmp(xd.name, "..") == 0) {
ou->err = Ename;
goto out;
//.........这里部分代码省略.........
开发者ID:dancrossnyc,项目名称:harvey,代码行数:101,代码来源:9p1.c
示例15: mkdir
int mkdir(struct inode *dir, const char *name, int len, int mode){
/*判断目录是否有效*/
if(dir->ext2_inode.i_block[0] != UINT_MAX){
perror("inode_operations.c: mkdir error! dir is a file!\n");
return -1;
}
/*判断名字是否有效*/
if(checkname(name) == -1){
perror("inode_operations.c: mkdir error! dirname is illegal!\n");
return -1;
}
/*判断是否已存在*/
if(is_exist(dir,name) == 1){
perror("inode_operations.c: mkdir error! dirname is alreay exists!\n");
return -1;
}
char buf[BLOCK_SIZE];
struct inode *m_inode;
struct ext2_dir_entry_2 *pentry;
int dir_datablocks = dir->ext2_inode.i_blocks;/*数据块个数*/
int i = 1;
int num = BLOCK_SIZE/sizeof(struct ext2_dir_entry_2);
while(i <= dir_datablocks){
/*取出目录节点中第i块逻辑块所在的物理块的数据,放入buf*/
get_block_data(dir->ext2_inode.i_block[i],buf);
pentry = (struct ext2_dir_entry_2 *)buf;
/*寻找pentry->inode为0的每一项,表示未使用*/
int j = 0;
while(j<num){
if(!pentry->inode){
pentry->name_len = len;
strcpy(pentry->name,name);
pentry->file_type = mode;
pentry->rec_len = 8 + len;
pentry->inode = new_inode();
write_block_data(dir->ext2_inode.i_block[i],buf);//更新该数据块
/*下面更新为目录项(文件夹)申请的inode节点信息,并为其预分配一块数据块,用于存放子目录或文件*/
if((m_inode=(struct inode*)malloc(sizeof(struct inode))) != NULL){
get_inode_data(pentry->inode,m_inode);
m_inode->ext2_inode.i_block[0] = UINT_MAX;//表示该节点是目录节点
m_inode->ext2_inode.i_block[1] = new_block();//为每个目录节点预分配一块数据块,存放目录项
m_inode->ext2_inode.i_blocks = 1;
write_inode_data(pentry->inode,m_inode);
free(m_inode);
return 1;
}
}
j++;
pentry++;
}
i++;
}
/*数据块表项已满,则需申请新的数据块来存放新的目录项*/
if(dir_datablocks>=14){
perror("inode_operations.c mkdir error! dir_entry is full,no more sub_dir!\n");
return -1;
}
dir_datablocks = ++dir->ext2_inode.i_blocks;
dir->ext2_inode.i_block[dir_datablocks] = new_block();
write_inode_data(dir->i_number,dir);//因为申请了新块,inode节点及时更新
get_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);
pentry = (struct ext2_dir_entry_2 *)buf;
pentry->name_len = len;
strcpy(pentry->name,name);
pentry->file_type = mode;
pentry->rec_len = 8 + len;
pentry->inode = new_inode();
write_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);//更新该数据块
if((m_inode=(struct inode*)malloc(sizeof(struct inode))) != NULL){
get_inode_data(pentry->inode,m_inode);
m_inode->ext2_inode.i_block[0] = UINT_MAX;//表示该节点是目录节点
m_inode->ext2_inode.i_block[1] = new_block();//为每个目录节点预分配一块数据块,存放目录项
m_inode->ext2_inode.i_blocks = 1;
write_inode_data(pentry->inode,m_inode);
free(m_inode);
return 1;
}
return -1;
}
开发者ID:Naturing,项目名称:ext2_emulation,代码行数:83,代码来源:inode_operations.c
示例16: decode
/*
* decode decodes one line of the type structure named str into the
* a parseinfo block called pi. depth is the current depth which may be 0.
*
* newName is set in case of ARRAY (to the empty string) or CONTAINER. In this
* case is set to the LIKE parameter or to the empty string.
*
* Leading and trailing spaces are ignored completely, "INDIRECTFLOAT32" is
* acceptable. Differences in case are ignored.
*
* THE GENERATED TYPE MAY HAVE AN ILLEGAL BIT SIZE. IT ISN'T CHECKED ALWAYS!
*
* Return values:
* GCI_OK: Line understood, *pi filled.
* GCI_UnsupportedType: Wrong type of input, e.g. FLOAT31 or the empty string.
* GCI_NoBaseType: The type won't fit the requirements for basic types.
*/
static GCI_result decode( void *hidden,
const GCI_str *str,
GCI_parseinfo *pi,
int depth,
GCI_str *newName )
{
const char *ptr = GCI_ccontent( str );
int size = GCI_strlen( str );
/*
* Chop off leading and trailing spaces. We really need it.
*/
while ( ( size > 0 ) && GCI_isspace( *ptr ) )
{
ptr++;
size--;
}
while ( ( size > 0 ) && GCI_isspace( ptr[size - 1] ) )
size--;
memset( pi, 0, sizeof( GCI_parseinfo ) );
if ( ( pi->type = checkname( &ptr, &size ) ) == GCI_unknown )
return GCI_UnsupportedType;
if ( pi->type == GCI_indirect )
{
while ( ( size > 0 ) && GCI_isspace( *ptr ) )
{
ptr++;
size--;
}
pi->type = checkname( &ptr, &size );
if ( ( pi->type == GCI_unknown ) || ( pi->type == GCI_indirect ) )
return GCI_UnsupportedType;
pi->indirect = 1;
}
else
pi->indirect = 0;
/*
* Check for a size operand.
*/
while ( ( size > 0 ) && GCI_isspace( *ptr ) )
{
ptr++;
size--;
}
/*
* We may have a size operand only if not an array or container is
* processed!
* This implementation shall support plain types like "INTEGER" without
* any bit size.
*/
switch ( pi->type )
{
case GCI_container:
if ( size > 0 )
{
GCI_str tmp;
if ( checkname( &ptr, &size ) != GCI_like )
return GCI_UnsupportedType;
while ( ( size > 0 ) && GCI_isspace( *ptr ) )
{
ptr++;
size--;
}
if ( size == 0 )
{
/*
* Single "like" after "container".
*/
return GCI_UnsupportedType;
}
while ( GCI_isspace( ptr[size - 1] ) )
size--;
/*
* Cut off a final dot, we append one later.
*/
if ( ptr[size - 1] == '.' )
{
/*
//.........这里部分代码省略.........
开发者ID:jlfaucher,项目名称:builder,代码行数:101,代码来源:gci_tree.c
注:本文中的checkname函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论