Ejemplo n.º 1
0
static void save_folders_r(struct folder *root, char* dst, size_t maxlen)
{
    int i = 0;

    while (i < root->children_count)
    {
        struct child *this = &root->children[i];
        if (this->state == SELECTED)
        {
            if (this->folder)
                snprintf(buffer_front, buffer_end - buffer_front,
                        "%s:", get_full_path(this->folder));
            else
            {
                char *p = get_full_path(root);
                snprintf(buffer_front, buffer_end - buffer_front,
                        "%s/%s:", strcmp(p, "/") ? p : "",
                                  strcmp(this->name, "/") ? this->name : "");
            }
            strlcat(dst, buffer_front, maxlen);
        }
        else if (this->state == EXPANDED)
            save_folders_r(this->folder, dst, maxlen);
        i++;
    }
}
Ejemplo n.º 2
0
static int rootfctrl_path_rename(struct path *old_dir, struct dentry *old_dentry,
                    struct path *new_dir, struct dentry *new_dentry)
{
	pid_t pid;
	char tcomm[sizeof(current->comm)];
	char old_name_buf[MAX_NAME_BUF_LEN], new_name_buf[MAX_NAME_BUF_LEN];
	char *old_full_path = get_full_path(old_dir, old_dentry, old_name_buf);
	char *new_full_path = get_full_path(new_dir, new_dentry, new_name_buf);

#if (RTFCTL_RUN_MODE == RTFCTL_TEST_MODE)
	if (is_felica_file(old_full_path) || is_nfc_file(old_full_path))
#else
	if (is_felica_file(old_full_path) || is_felica_file(new_full_path) ||
		is_nfc_file(old_full_path) || is_nfc_file(new_full_path))
#endif
	{
		pid = task_tgid_vnr(current);
		get_task_comm(tcomm, current);

		RTFCTL_MSG("########## %s ##########\n", __FUNCTION__);
		RTFCTL_MSG("pid: %d (%s)\n", pid, tcomm);

#if (RTFCTL_RUN_MODE != RTFCTL_TRACKING_MODE)
		
		printk("[RTFCTL] RType-5 <%s (%d)>\n", tcomm, pid);
		if (old_full_path)
			printk("[RTFCTL] RType-5 <old %s>\n", old_full_path);
		if (new_full_path)
			printk("[RTFCTL] RType-5 <new %s>\n", new_full_path);
		return -EACCES;
#endif
	}
	return 0;
}
Ejemplo n.º 3
0
static int rootfctrl_path_truncate(struct path *path)
{
	char name_buf[MAX_NAME_BUF_LEN];
	if (is_felica_file(get_full_path(path, NULL, name_buf))) {
		RTFCTL_MSG("*****>>>>> %s <<<<<*****\n", __FUNCTION__);
		RTFCTL_MSG("path: %s\n", get_full_path(path, NULL, name_buf));
	}
	return 0;
}
Ejemplo n.º 4
0
/* Program */
int main(int argc, char **argv) {
	int err = 0;
	int i;
	int len;

	/* Set default applications to open bookmarks */

	g_cmd_name = argv[0];
	g_dir_name = getenv("HOME");
	g_browser_name = "firefox";
	g_filer_name = "rox";
	g_icon_dir = "/usr/share/icons/hicolor/32x32/apps";

	/* If applications is specified. */
	for (i = 1; i < argc; i++) {
		len = strlen(argv[i]);
		if (len > 2 && argv[i][0] == '-') {
			switch (argv[i][1]) {
				case 'd': g_dir_name = get_full_path(argv[i] + 2); break;
				case 'b': g_browser_name = argv[i] + 2; break;
				case 'f': g_filer_name = argv[i] + 2; break;
				case 'i': g_icon_dir = get_full_path(argv[i] + 2); break;
				default:
				    exit(1);
			}
		}
	}

	printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
	printf("<openbox_pipe_menu>\n");
	err = print_dir_entries(g_dir_name);
	if (err) {
		printf(ERR_MSG_DIR);
	}

	printf(
		"<separator label=\"編集\" />\n"
		"<item label=\"Open the location with %s\" icon=\"%s/%s.png\">\n"
		"  <action name=\"Execute\"><execute>%s &quot;%s&quot;</execute></action>\n"
		"</item>\n",
		g_filer_name, g_icon_dir, g_filer_name, g_filer_name, g_dir_name
	);

	printf("</openbox_pipe_menu>\n");

	if (g_dir_name != NULL) {
		free(g_dir_name);
	}

	if (g_icon_dir != NULL) {
		free(g_icon_dir);
	}
	return 0;
}
Ejemplo n.º 5
0
static int rootfctrl_path_rmdir(struct path *dir, struct dentry *dentry)
{
	char name_buf[MAX_NAME_BUF_LEN];
	if (is_felica_file(get_full_path(dir, dentry, name_buf))) {
		RTFCTL_MSG("*****>>>>> %s <<<<<*****\n", __FUNCTION__);
		RTFCTL_MSG("parent: %s\n", get_full_path(dir, NULL, name_buf));
		RTFCTL_MSG("dentry: %s\n", dentry->d_name.name);
		if (current_uid() == 0) {
			RTFCTL_MSG("Rejected...\n");
			
		}
	}
	return 0;
}
Ejemplo n.º 6
0
/*
 * display the file open dialog
 */
void gtkui_load_filter(void)
{
   GtkWidget *dialog;
   gchar *filename;
   int response = 0;
   char *path = get_full_path("share", "");

   DEBUG_MSG("gtk_load_filter");

   dialog = gtk_file_chooser_dialog_new("Select a precompiled filter file...",
            GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN,
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
            GTK_STOCK_OPEN, GTK_RESPONSE_OK,
            NULL);
   gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);

   SAFE_FREE(path);

   response = gtk_dialog_run (GTK_DIALOG (dialog));

   if (response == GTK_RESPONSE_OK) {
      gtk_widget_hide(dialog);
      filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));

      /* 
       * load the filters chain.
       * errors are spawned by the function itself
       */
      filter_load_file(filename, GBL_FILTERS, 1);

      g_free(filename);
   }
   gtk_widget_destroy (dialog);
}
Ejemplo n.º 7
0
static int rootfctrl_path_link(struct dentry *old_dentry, struct path *new_dir, struct dentry *new_dentry)
{
	pid_t pid;
	char tcomm[sizeof(current->comm)], name_buf[MAX_NAME_BUF_LEN];
	char *full_path;
	struct path path;

	path.mnt = new_dir->mnt;
	path.dentry = old_dentry;
	full_path = get_full_path(&path, NULL, name_buf);

	if (is_felica_file(full_path) || is_nfc_file(full_path)) {
		pid = task_tgid_vnr(current);
		get_task_comm(tcomm, current);

		RTFCTL_MSG("########## %s ##########\n", __FUNCTION__);
		RTFCTL_MSG("pid: %d (%s)\n", pid, tcomm);
		
		RTFCTL_MSG("new_dentry: %s -> old_dentry: %s\n", new_dentry->d_name.name, old_dentry->d_name.name);

#if (RTFCTL_RUN_MODE != RTFCTL_TRACKING_MODE)
		
		printk("[RTFCTL] RType-4 <%s-%s (%d)>\n", full_path, tcomm, pid);
		return -EACCES;
#endif
	}
	return 0;
}
Ejemplo n.º 8
0
int run() {
    // store cooccurrence in Eigen sparse matrix object
    REDSVD::SMatrixXf A;
    const int ncontext = read_cooccurrence(c_cooc_file_name, A, verbose);

    // read U matrix from file
    Eigen::MatrixXf V;
    read_eigen_truncated_matrix(c_input_file_V_name, V, dim);
    // read S matrix from file
    Eigen::VectorXf S;
    read_eigen_vector(c_input_file_S_name, S, dim, 1.0-eig);

    // checking the dimensions
    if (V.rows() != ncontext){
        throw std::runtime_error("size mismatch between projection V matrix and the number of context words!!");
    }

    // starting projection
    if (verbose) fprintf(stderr, "Running the projection...");
    const double start = REDSVD::Util::getSec();
    Eigen::MatrixXf embeddings = A * V * S.asDiagonal().inverse();
    if (norm) embeddings.rowwise().normalize();
    if (verbose) fprintf(stderr, "done in %.2f.\n",REDSVD::Util::getSec() - start);

    // write out embeddings
    const char *c_output_name = get_full_path(c_cooc_dir_name, c_output_file_name);
    if (verbose) fprintf(stderr, "writing infered word embeddings in %s\n", c_output_name);
    write_eigen_matrix(c_output_name, embeddings);
    free((char*)c_output_name);

    return 0;
}
Ejemplo n.º 9
0
void delete_cmd(int argc, char **args, int call_type) {
    char *path;

    switch (call_type) {
        case CALL_TYPE_HELP:
            puts("DELETE ITEMS\n");
            return;
        case CALL_TYPE_DESC:
            puts("[PATH] [PATH] [PATH] . . .\n");
            puts("\tPATH\tTHE PATH OF THE TARGET TO DELETE\n");
            return;
    }

    while (argc--) {
        path = get_full_path(*args);
        if (is_path(path, strlen(path), TYPE_UNDEFINED, 0)) {
            delete(path, strlen(path));
        } else {
            puts(*args);
            puts(" not found!\n");
        }
        args++;
        free(path);
    }

}
Ejemplo n.º 10
0
	void ImplNodeEx::update() const
	{
		auto hndl = CheckHandleErr(::CreateFileW(get_full_path().c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ, nullptr, OPEN_EXISTING,
		                                         FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,
		                                         nullptr));
		::GetFileInformationByHandle(hndl, &data_);
	}
Ejemplo n.º 11
0
/*
 * The BFileFullPathFunc() SQL function  returns full path of a BFile
 */
static void BFileFullPathFunc(
    sqlite3_context *context,
    int argc,
    sqlite3_value **argv)
{
    int rc;
    sqlite3 *db;
    int loc_size;
    char *pLoc, *full_path;

    assert(context != NULL && argc == 1 && argv != NULL);

    loc_size = sqlite3_value_bytes(argv[0]);
    if (loc_size == 0) {
        sqlite3_result_null(context);
        return;
    }

    pLoc = (char *)sqlite3_value_text(argv[0]);
    db = (sqlite3 *)sqlite3_user_data(context);

    rc = get_full_path(db, pLoc, loc_size, &full_path);
    if (rc) {
        if (rc == SQLITE_NOMEM)
            sqlite3_result_error_nomem(context);
        else
            sqlite3_result_error(context, "internal error", -1);

        return;
    }

    sqlite3_result_text(context, full_path, strlen(full_path), sqlite3_free);
}
Ejemplo n.º 12
0
int GIGAreadlink(const char *path, char *link, size_t size)
{
    logMessage(LOG_TRACE, __func__,
               " ==> readlink(path=[%s],link=[%s],size[%d])", path, link, size);
    
    int ret = 0;
    char fpath[MAX_LEN] = {0};

    switch (giga_options_t.backend_type) {
        case BACKEND_LOCAL_FS:
            get_full_path(fpath, path);
            ret = local_readlink(fpath, link, size);
            ret = FUSE_ERROR(ret);
            break;
        case BACKEND_RPC_LEVELDB:
            break;
        default:
            break;
    }
    
    logMessage(LOG_TRACE, __func__,
               "ret_readlink(link=[%s], size[%d])", path, link, strlen(link));
    
    return ret;
}
Ejemplo n.º 13
0
static WERROR cmd_ck(struct regshell_context *ctx, int argc, char **argv)
{
	struct registry_key *nkey = NULL;
	char *full_path;
	WERROR error;

	if(argc == 2) {
		if (!W_ERROR_IS_OK(get_full_path(ctx, argv[1], &full_path))) {
			fprintf(stderr, "Unable to parse the supplied path\n");
			return WERR_INVALID_PARAM;
		}
		error = reg_open_key(ctx->registry, ctx->root, full_path,
				     &nkey);
		if(!W_ERROR_IS_OK(error)) {
			DEBUG(0, ("Error opening specified key: %s\n",
				win_errstr(error)));
			return error;
		}

		talloc_free(ctx->path);
		ctx->path = full_path;

		ctx->current = nkey;
	}
	printf("New path is: %s\\%s\n", ctx->predef?ctx->predef:"", ctx->path);

	return WERR_OK;
}
Ejemplo n.º 14
0
int GIGAmkdir(const char *path, mode_t mode)
{
    logMessage(LOG_TRACE, __func__, 
               " ==> mkdir(path=[%s], mode=[0%3o])", path, mode);

    int ret = 0;
    char fpath[MAX_LEN] = {0};
    char dir[MAX_LEN] = {0};
    char file[MAX_LEN] = {0};
    int dir_id = 0;

    switch (giga_options_t.backend_type) {
        case BACKEND_LOCAL_FS:
            get_full_path(fpath, path);
            ret = local_mkdir(fpath, mode);
            ret = FUSE_ERROR(ret);
            break;
        case BACKEND_RPC_LEVELDB:
            parse_path_components(path, dir, file);
            ret = rpc_mkdir(dir_id, path, mode);
            ret = FUSE_ERROR(ret);
            break;
        default:
            break;
    }

    return ret;
}
Ejemplo n.º 15
0
/*
 * display the file open dialog
 */
void gtkui_load_filter(void)
{
   GtkWidget *dialog;
   char *filename;
   int response = 0;
   char *path = get_full_path("share", "");

   DEBUG_MSG("gtk_load_filter");

   dialog = gtk_file_selection_new ("Select a precompiled filter file...");
   gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), path);

   SAFE_FREE(path);

   response = gtk_dialog_run (GTK_DIALOG (dialog));

   if (response == GTK_RESPONSE_OK) {
      gtk_widget_hide(dialog);
      filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (dialog));

      /* 
       * load the filters chain.
       * errors are spawned by the function itself
       */
      filter_load_file(filename, GBL_FILTERS);
   }
   gtk_widget_destroy (dialog);
}
Ejemplo n.º 16
0
int GIGAgetattr(const char *path, struct stat *statbuf)
{
    logMessage(LOG_TRACE, __func__,
               " ==> getattr(path=[%s], statbuf=0x%08x) ", path, statbuf);

    int ret = 0;
    char fpath[MAX_LEN] = {0};
    char dir[MAX_LEN] = {0};
    char file[MAX_LEN] = {0};
    int dir_id = 0;
   
    switch (giga_options_t.backend_type) {
        case BACKEND_LOCAL_FS: 
            get_full_path(fpath, path);
            ret = local_getattr(fpath, statbuf);
            ret = FUSE_ERROR(ret);
            break;
        case BACKEND_RPC_LEVELDB:
            parse_path_components(path, dir, file);
            //TODO: convert "dir" to "dir_id"
            ret = rpc_getattr(dir_id, file, statbuf);
            ret = FUSE_ERROR(ret);
            break;
        default:
            break;
    }

    return ret;
}
sodiumpp::locked_string filestorage::load_string_mlocked(t_filestore file_type,
														 const std::string &filename) {
	FILE * f_ptr;
	fs::path file_with_path = get_full_path(file_type, filename);

	f_ptr = std::fopen(file_with_path.c_str(), "r");

	if (f_ptr == NULL){
		throw std::invalid_argument("Fail to open mlocked file for read: " + filename);
	}

	std::fseek(f_ptr, 0L, SEEK_END);
	size_t content_size = static_cast<size_t>(ftell(f_ptr));

	std::rewind(f_ptr);

	sodiumpp::locked_string content(content_size);

	size_t byte_read = std::fread(content.buffer_writable(), 1, content_size, f_ptr);
	if (byte_read != content_size) {
		std::string err_msg = "Fail to read all content of file: " + filename;
		err_msg += " read: [" + std::to_string(byte_read);
		err_msg += "] bytes of [" + std::to_string(content_size) + "]";
		throw std::invalid_argument(err_msg);
	}
	std::fclose(f_ptr);

	_dbg2("Successfully loaded mlocked string from:" << file_with_path.native());
	return content;
}
Ejemplo n.º 18
0
int ConfirmOverwrite(const CTar32CmdInfo &cmdinfo,EXTRACTINGINFOEX64 &ExtractingInfoEx64)
{
	extern HINSTANCE dll_instance;
	extern HWND g_hwndOwnerWindow;
	std::string path=ExtractingInfoEx64.szDestFileName;
	convert_slash_to_backslash(path);

	//存在確認
	if(PathFileExists(path.c_str()) && !PathIsDirectory(path.c_str())){
		HWND hWnd=NULL;
		if(cmdinfo.hTar32StatusDialog){
			hWnd=cmdinfo.hTar32StatusDialog;
		}else if(g_hwndOwnerWindow){
			hWnd=g_hwndOwnerWindow;
		}

		get_full_path(path.c_str(),path);

		std::stringstream msg;
		msg << "File " << path << " already exists.\r\n"
			<< "Do you want to overwrite?";
		int ret=::DialogBoxParam(dll_instance,MAKEINTRESOURCE(IDD_CONFIRM_OVERWRITE),hWnd,Tar32ConfirmOverwriteDialogProc,(LPARAM)(const char*)(msg.str().c_str()));
		switch(ret){
		case IDCANCEL:
			return -1;
		case IDC_BUTTON_OVERWRITE:
			return 0;
		case IDC_BUTTON_OVERWRITE_ALL:
			return 1;
		default:
			return 0;
		}
	}
	return 0;
}
Ejemplo n.º 19
0
/*
 * display the file open dialog
 */
void gtkui_plugin_load(void)
{
   GtkWidget *dialog;
   char *filename;
   int response = 0;
#ifdef OS_WINDOWS
   char *path = get_full_path("/lib/", "");
#else
   char *path = INSTALL_LIBDIR "/" EC_PROGRAM "/";
#endif
   
   DEBUG_MSG("gtk_plugin_load");
   
   dialog = gtk_file_selection_new ("Select a plugin...");
   gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), path);   

#ifdef OS_WINDOWS
   SAFE_FREE(path);
#endif
   
   response = gtk_dialog_run (GTK_DIALOG (dialog));
   
   if (response == GTK_RESPONSE_OK) {
      gtk_widget_hide(dialog);
      filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (dialog));
      
      gtkui_load_plugin(filename);

      /* update the list */
      gtkui_create_plug_array();
   }
   gtk_widget_destroy (dialog);
}
Ejemplo n.º 20
0
/*--------------------------------------------------------------------------*/
BOOL IsAlreadyOpenedInScilab(char *filename)
{
    if (ScilabFileList)
    {
        char fullpath[PATH_MAX*4];
        int i = 0;

        if ((strcmp(filename, "") == 0) || (filename == NULL))
        {
            return FALSE;
        }

        if( get_full_path( fullpath, filename, PATH_MAX*4 ) == NULL )
        {
            /* if we are a problem */
            strcpy(fullpath,filename);
        }

        for (i=0;i<CurrentMaxFiles;i++)
        {
            if ( (ScilabFileList[i].ftformat) && ScilabFileList[i].ftname)
            {
                if (strcmp(ScilabFileList[i].ftname,fullpath) == 0) return TRUE;
            }
        }
    }
    return FALSE;
}
Ejemplo n.º 21
0
/* check if (arg) is a valid wordlist file */
void parser_wordlist(char *arg)
{
	struct stat wrd_stat;
#ifdef HAVE_LIBMAGIC
	const char *target_mime = "text/plain;";
#endif

	if(arg == NULL)
		fatal("called with NULL argument.");
	else if(globals.options.dict == false)
		fatal("dictionary features OFF. unable to parse wordlist.");
	else if( stat(arg,&wrd_stat) ) // if can't get file stats
		pfatal(arg);
	else if( S_ISREG(wrd_stat.st_mode) == 0 ) // if isn't a regular file
		fatal_long("\"%s\" is not a regular file.",arg);
	else if( access(arg,R_OK))
		pfatal(arg);
	else
	{
#ifdef HAVE_LIBMAGIC
		if(strncmp(get_mime(arg),target_mime,strlen(target_mime)+1) != 0)
			report(warning,"\"%s\" is not a \"%s\" file.",arg,target_mime);
#endif
		if((globals.wordlist = (const char *) get_full_path(arg)) == NULL)
			fatal("unable to resolve full path for wordlist.");
	}
	return;
}
Ejemplo n.º 22
0
Errcode set_flipath(char *fliname, Fli_id *flid, Flipath *fp)

/* note this sets size to sizeof(Flipath) not length of string! it
 * returns adjusted size of length for actual path string length if
 * successful */
{
Errcode err;
char pbuf[PATH_SIZE];

	clear_struct(&fp->fid);
	if(fliname && flid)
	{
		if((err = get_full_path(fliname,pbuf)) < 0)
			return(err);
		fp->fid = *flid;
	}
	else
		sprintf(pbuf,"%s.flc", unnamed_str );

	fp->id.type = FP_FLIPATH;
	fp->id.size = sizeof(Flipath);
	fp->id.version = FLIPATH_VERSION;

	return((OFFSET(Flipath,path)+1) + sprintf(fp->path,"%s", pbuf));
}
Ejemplo n.º 23
0
/// 这里应该做 错误检查 , 检查相对应模式下的错误情况 比如在copy 文件时  , source 不能是目录 , copy 目录时 , source 不能是文件等 必须做特殊处理
int copy_file (struct mode *oper_mode , int argc , char* argv[]) {

	// 保存 argv 中的 dest
	char 	path_buf[PATH_MAX_LEN] ;
	char 	source_path[PATH_MAX_LEN] ;
// 这里 对于递归 , 接口写好! , directory , directory 参数 , 这样的话, 就可以调, target的话,
	bzero (path_buf , PATH_MAX_LEN) ;
	strcpy(source_path , argv[argc-2]) ;
	if( 1 == oper_mode->directory ) {
		printf ("copy directory!\n ") ;  	// source是目录
		get_full_path (argv[argc-1] , path_buf) ;	
		// 判断用户输入的是否符合自己规定
		if ( '/' != path_buf[strlen(path_buf)-1] ){
			strcat (path_buf , "/") ;
		}
		if ( '/' != source_path[strlen(source_path)-1] ) {
			strcat (source_path , "/" ) ;
		}
		cat_source_to_dest (source_path , path_buf) ;
		copy_dir (source_path,path_buf) ;
		return TRUE ;	
	} else {
		// 全都处理成绝对路径 
		get_full_path (argv[argc-1] ,path_buf ) ;		
		if (ISDIR == is_directory(path_buf )) {
			printf ("target is a direcroty !\n") ;
			// 首先处理名字
			// 我需要st_mode 值 和 st_uid , st_gid值 然后去调函数设置	
			// 生成最终的文件名
			if ( '/' != path_buf[strlen(path_buf)-1] ){
				strcat (path_buf , "/") ;
			}
			cat_source_to_dest (argv[argc-2] , path_buf) ;
			path_buf[strlen(path_buf)-1] = 0 ;
			copy (argv[argc-2] , path_buf ) ;
		}else {
			// 判断文件是否存在
			if (!access (path_buf , F_OK)) {
			// 存在
				printf ("file now is exist ! overwrite it now !\n") ;
			}
			copy (argv[argc-2] , path_buf ) ;
			return TRUE ;
		}	
	}	
	return TRUE ;
}
Ejemplo n.º 24
0
//---------------------------------------------------------------------------------------
string DocLocator::get_locator_as_string()
{
    string loc = get_protocol_string() + get_full_path();
    if (m_innerProtocol == k_zip)
        return loc + "#zip:" + get_inner_fullpath();
    else
        return loc;
}
fs::path filestorage::create_path_for(t_filestore file_type,
									  const std::string &filename) {

	// connect parent path with filename
	fs::path full_path = get_full_path(file_type, filename);
	std::cout << "full_path: " << full_path.native() << std::endl;
	create_parent_dir(full_path);
	return full_path;
}
Ejemplo n.º 26
0
/*
 * Access BFILE element of the current row in the row set
 */
SQLITE_API int sqlite3_column_bfile(
    sqlite3_stmt *pStmt,
    int iCol,
    sqlite3_bfile **ppBfile
)
{
    BfileHdl *pHdl;
    char * pLoc;
    int loc_size, rc;
    sqlite3 *db;
#define IS_ERROR(rc) \
	((rc)!= SQLITE_OK && (rc) != SQLITE_ROW && (rc) != SQLITE_DONE)

    if (pStmt == NULL || iCol < 0 || iCol >= sqlite3_column_count(pStmt)
            || ppBfile == NULL)
        return SQLITE_ERROR;

    db = sqlite3_db_handle(pStmt);

    /*
     * If a memory allocation error occurs during the evaluation of any of
     * these routines, a default value is returned. The default value is
     * either the integer 0, the floating point number 0.0, or a NULL
     * pointer. Subsequent calls to sqlite3_errcode() will return
     * SQLITE_NOMEM.
     */
    pLoc = (char *)sqlite3_column_blob(pStmt, iCol);
    if (pLoc == NULL) {
        *ppBfile = NULL;
        rc = sqlite3_errcode(db);
        return (IS_ERROR(rc) ? SQLITE_ERROR : SQLITE_OK);
    }

    pHdl = sqlite3_malloc(sizeof(BfileHdl));
    if (pHdl == NULL) {
        *ppBfile = NULL;
        return SQLITE_ERROR;
    }

    pHdl->fd = -1;

    loc_size = sqlite3_column_bytes(pStmt, iCol);

    rc = get_full_path(db, pLoc, loc_size,&(pHdl->full_path));

    if (rc) {
        if (pHdl != NULL)
            sqlite3_free(pHdl);
        *ppBfile = NULL;
        return SQLITE_ERROR;
    }

    *ppBfile = (sqlite3_bfile *)pHdl;

    return SQLITE_OK;
}
Ejemplo n.º 27
0
/* check if (arg) is a vlid output file */
void parser_outfile(char *arg)
{
	struct stat out_stat;
	struct statvfs disk_stat;
	char *path=NULL;
	FILE *fout;

	if(arg == NULL)
		fatal("called with NULL argument.");
	else if(stat(arg,&out_stat) == 0)
	{
		if(S_ISREG(out_stat.st_mode))
		{
			if((path = get_full_path(arg)) != NULL)
			{
				if(access(path,W_OK) == 0)
				{
					if(statvfs(path,&disk_stat) == 0)
					{
						if((disk_stat.f_bsize * disk_stat.f_bavail) > MIN_FREE_SPACE )
						{
							argcpy(&(globals.outfile),path,strlen(path)+1);
						}
						else
							fatal_long("we need at least %lu free bytes for writing some output.",MIN_FREE_SPACE);
					}
					else
						pfatal(path);
				}
				else
					pfatal(path);
			}
			else
				fatal("unable to find full path for outfile.");
		}
		else
			fatal_long("file \"%s\" isn't a regular file.",arg);
	}
	else if(errno == ENOENT)
	{
		if((fout = fopen(arg,"w+")) != NULL)
		{
			fclose(fout);
			parser_outfile(arg); // restart
		}
		else
			pfatal(arg);
	}
	else
		pfatal(arg);

	if(path!=NULL)
		free((void *) path);

	return;
}
Ejemplo n.º 28
0
static void po_chainto(Popot ppath)
/*****************************************************************************
 * void PocoChainTo(char *program_path)
 ****************************************************************************/
{
	if (ppath.pt == NULL)
		po_chainto_program_path[0] = '\0';
	else
		get_full_path(ppath.pt, po_chainto_program_path);
}
Ejemplo n.º 29
0
t_file		*get_glob(char *str, t_env *env)
{
  t_file	*glob;
  char		*dir;

  glob = NULL;
  if (!(dir = get_full_path(str, env)))
    return (NULL);
  return (glob);
}
Ejemplo n.º 30
0
void
kfs_close(struct file *file)
{
	// if this file was allocated with alloc_file it will not have
	// an inode
	if ( file->inode ) {
		char __attribute__((unused)) buff[MAX_PATHLEN];
        	dbg("name=`%s`\n", get_full_path( file->inode, buff) );
		atomic_dec(&file->inode->i_count);
	}