当前位置: 技术问答>linux和unix
为什么freebsd下的lockf我编译通不过呢.请大家指教
来源: 互联网 发布时间:2016-02-02
本文导语: 我在freebsd环境下写了个测试锁文件的程序.可是编译的时候通不过去.说 arpu_do_test.c:95: `F_TLOCK' undeclared (first use in this function) arpu_do_test.c:95: (Each undeclared identifier is reported only once arpu_do_test.c:95: for each function...
我在freebsd环境下写了个测试锁文件的程序.可是编译的时候通不过去.说
arpu_do_test.c:95: `F_TLOCK' undeclared (first use in this function)
arpu_do_test.c:95: (Each undeclared identifier is reported only once
arpu_do_test.c:95: for each function it appears in.)
arpu_do_test.c:107: `F_ULOCK' undeclared (first use in this function)
int mywritefile(const char *file_name,const char *write_msg,const char *create_flag,const char * write_flag)
{
FILE *fp=NULL;
int lock_flag=0;
int lock_count=0;
if((fp=fopen(file_name,"r"))==NULL)
{
if(!strcmp(create_flag,"true"))
{
if((fp=fopen(file_name,write_flag))==NULL)
return -1;
fprintf(fp,"%s",write_msg);
fclose(fp);
return 1;
}
}
fclose(fp);
L1: if((fp=fopen(file_name,write_flag))==NULL)
return -1;
lock_flag=lockf(fileno(fp),F_TLOCK,0L);
if(lock_flag3);
return -2;
sleep(1);
fp=NULL;
goto L1;
}
fprintf(fp,"%s",write_msg);
lockf(fileno(fp),F_ULOCK,0L);
fclose(fp);
return 0;
}
是怎么回事呢.请大家指教.谢谢
arpu_do_test.c:95: `F_TLOCK' undeclared (first use in this function)
arpu_do_test.c:95: (Each undeclared identifier is reported only once
arpu_do_test.c:95: for each function it appears in.)
arpu_do_test.c:107: `F_ULOCK' undeclared (first use in this function)
int mywritefile(const char *file_name,const char *write_msg,const char *create_flag,const char * write_flag)
{
FILE *fp=NULL;
int lock_flag=0;
int lock_count=0;
if((fp=fopen(file_name,"r"))==NULL)
{
if(!strcmp(create_flag,"true"))
{
if((fp=fopen(file_name,write_flag))==NULL)
return -1;
fprintf(fp,"%s",write_msg);
fclose(fp);
return 1;
}
}
fclose(fp);
L1: if((fp=fopen(file_name,write_flag))==NULL)
return -1;
lock_flag=lockf(fileno(fp),F_TLOCK,0L);
if(lock_flag3);
return -2;
sleep(1);
fp=NULL;
goto L1;
}
fprintf(fp,"%s",write_msg);
lockf(fileno(fp),F_ULOCK,0L);
fclose(fp);
return 0;
}
是怎么回事呢.请大家指教.谢谢
|
不好意思,有一个地方写错了
lockf是 SYSV的界面 flock是BSD的界面,标准的可移植的调用是fcntl,
详情参见:
http://docs.sun.com/app/docs/doc/819-7052/6n91ag9rv?l=zh&a=view
lockf是 SYSV的界面 flock是BSD的界面,标准的可移植的调用是fcntl,
详情参见:
http://docs.sun.com/app/docs/doc/819-7052/6n91ag9rv?l=zh&a=view