我编写函数来创建目录并强制它归用户所有。
int mkdir_and_force_owner( const char *path, uid_t uid, gid_t gid )
{
/* deref_ptr_in_call: Dereferencing pointer "path" */
if( mkdir( path, S_IRWXU ) < 0 ) {
if( errno != EEXIST ) {
lfprintf( stderr, _("Cannot create %s: %s\n"), path, strerror( errno ) );
} else {
DIR *temp_dir = opendir( path );
/* check_after_deref: Null-checking "path" suggests that it may be null, but it has already been dereferenced on all paths leading to the check */
if( !path ) {
lfprintf( stderr, _("Cannot open %s: %s\n"), path, strerror( errno ) );
} else {
closedir( temp_dir );
return 1;
}
closedir( temp_dir );
}
} else {
if( chown( path, uid, gid ) < 0 ) {
lfprintf( stderr, _("Cannot change owner of %s: %s.\n"), path, strerror( errno ) );
} else {
return 1;
}
}
return 0;
}
但是这段代码得到了这个警告:
空值检查“路径”表明它可能为空,但它已经在导致检查的所有路径上取消引用。我需要同样的帮助来解决这个问题谢谢