コード例 #1
0
ファイル: photoid.c プロジェクト: tierney/lockbox-py
static const char *
get_default_photo_command(void)
{
#if defined(_WIN32)
  OSVERSIONINFO osvi;

  memset(&osvi,0,sizeof(osvi));
  osvi.dwOSVersionInfoSize=sizeof(osvi);
  GetVersionEx(&osvi);

  if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
    return "start /w %i";
  else
    return "cmd /c start /w %i";
#elif defined(__APPLE__)
  /* OS X.  This really needs more than just __APPLE__. */
  return "open %I";
#elif defined(__riscos__)
  return "Filer_Run %I";
#else
  if(path_access("xloadimage",X_OK)==0)
    return "xloadimage -fork -quiet -title 'KeyID 0x%k' stdin";
  else if(path_access("eog",X_OK)==0)
    return "eog %i";
  else if(path_access("display",X_OK)==0)
    return "display -title 'KeyID 0x%k' %i";
  else
    return "";
#endif
}
コード例 #2
0
bool
path_write_access(
    const std::string &	name)
{
    return path_access(name, W_OK);
}
コード例 #3
0
bool
path_read_access(
    const std::string &	name)
{
    return path_access(name, R_OK);
}
コード例 #4
0
bool
path_exists(
    const std::string &	name)
{
    return path_access(name, F_OK);
}
コード例 #5
0
ファイル: file.c プロジェクト: Caleb1994/stewieos
struct file* file_open(struct path* path, int flags)
{
	
	struct file* file = NULL;
	int access_mode = ((flags+1)&_FWRITE ? W_OK : 0) | \
				((flags+1)&_FREAD ? R_OK : 0);
	int result = 0;
	
	result = path_access(path, access_mode);
	if( result != 0 ){
		return ERR_PTR(result);
	}
	
	// Is this not a directory?
	if( !S_ISDIR(path->p_dentry->d_inode->i_mode) )
	{
		// We requested a directory, and this file isn't one.
		/*if( (flags & O_DIRECTORY) ){
			path_put(&file->f_path);
			kfree(file);
			return -ENOTDIR;
		}*/
	// This is a directory, and we want a writeable file
	} else if( (flags+1) & _FWRITE ){
		return ERR_PTR(-EISDIR);
	}
	
	// FIXME I need to add O_CLOEXEC (and some others) to sys/fcntl.h instead of just using _default_fcntl.h from newlib!
	//if( flags & O_CLOEXEC ) file->f_flags |= FD_CLOEXEC;
	
	// No follow was specified, and this is a symlink
/*	if( flags & O_NOFOLLOW ){
		if( S_ISLNK(file->f_path.p_dentry->d_inode->i_mode) )
		{
			path_put(&file->f_path);
			kfree(file);
			return -ELOOP;
		}
	}*/
	
	if( flags & O_TRUNC )
	{
		if( !(access_mode & W_OK) ){
			return ERR_PTR(-EACCES);
		} else {
			result = inode_trunc(path->p_dentry->d_inode);
			if( result != 0 ){
				return ERR_PTR(result);
			}
		}
	}
	
	file = (struct file*)kmalloc(sizeof(struct file));
	if(!file) {
		return ERR_PTR(-ENOMEM);
	}
	
	memset(file, 0, sizeof(struct file));
	
	path_copy(&file->f_path, path);
	
	if( S_ISBLK(path->p_dentry->d_inode->i_mode) )
	{
		file->f_ops = &block_device_fops;
	} else if( S_ISCHR(path->p_dentry->d_inode->i_mode) ){
		file->f_ops = get_chrdev_fops(major(path->p_dentry->d_inode->i_dev));
	} else if( S_ISFIFO(path->p_dentry->d_inode->i_mode) ){
		file->f_ops = &pipe_operations;
	} else {
		file->f_ops = path->p_dentry->d_inode->i_default_fops;
	}
	
	if( file->f_ops == NULL )
	{
		path_put(&file->f_path);
		kfree(file);
		return ERR_PTR(-ENXIO);
	}
	
	if( file->f_ops->open ){
		result = file->f_ops->open(file, file->f_path.p_dentry, flags);
		if( result != 0 ){
			path_put(&file->f_path);
			kfree(file);
			return ERR_PTR(result);
		}
	}
	
	file->f_status = flags;
	file->f_refs = 1;
	
	return file;
}