我编写函数来防止运行具有相同配置(fifo 文件)的两个应用程序实例:
if( !filename_specified ) {
char *fifofile = get_fifo_filename( config_get_uid( ct ) );
int fifofd;
if( !fifofile ) {
lfprintf( stderr, _("%s: Cannot allocate memory.\n"), argv[ 0 ] );
return 0;
}
/* negative_return_fn: Function "open(fifofile, 2049)" returns a negative number */
fifofd = open( fifofile, O_WRONLY | O_NONBLOCK );
if( fifofd >= 0 ) {
lfprintf( stderr, _("Cannot run two instances of application with the same configuration.\n") );
close( fifofd );
return 0;
}
/* negative_returns: "fifofd" is passed to a parameter that cannot be negative */
close( fifofd );
}
我的代码收到此警告:
负值用作期望正值的函数的参数。