Beispiel #1
0
void test_find_index(void)
{
	FILENODE *node[5];
	FILENODE *current_node;
	GtkTreeIter iter;
	int index[11] = {4, 3, 2, 1, 0, 3, 2, 4, 0, 1, 1};
	int i = 0;
	init_file_list();

	node[0] = append_file("file1", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[0]);
	node[1] = append_file("file2", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[1]);
	node[2] = append_file("file3", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[2]);
	node[3] = append_file("file4", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[3]);
	node[4] = append_file("file5", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[4]);

	for (i = 0; i < 11; i++)
	{
		current_node = find_file_by_index(index[i]);
		CU_ASSERT_PTR_EQUAL(node[index[i]], current_node);
	}

	destroy_file_list();

}
Beispiel #2
0
int append_ramdisk(int ofd, off_t pos) {
	if(access("ramdisk-mtk", R_OK) == 0) {
		char buf[512];
		off_t size = file_size("ramdisk.gz");
		memcpy(buf, "\x88\x16\x88\x58", 4);
		uint32_t v = size;
		memcpy(buf+4, &v, sizeof(v)); //Should convert to LE

		//TODO: RECOVERY OR ROOTFS?
		char str[32];
		memset(str, 0, sizeof(str));
		if(access("ramdisk-mtk-boot", R_OK)==0) {
			strcpy(str, "ROOTFS");
		} else if(access("ramdisk-mtk-recovery", R_OK)==0) {
			strcpy(str, "RECOVERY");
		} else {
			exit(1);
		}
		memcpy(buf+8, str, sizeof(str));

		memset(buf+8+sizeof(str), 0xff, 512-8-sizeof(str));

		pwrite(ofd, buf, sizeof(buf), pos);

		return append_file(ofd, "ramdisk.gz", pos + 512) + 512;
	} else if(access("ramdisk.gz", R_OK) == 0) {
		return append_file(ofd, "ramdisk.gz", pos);
	} else {
		return append_file(ofd, "ramdisk", pos);
	}
}
Beispiel #3
0
static int process_individual_events(const char *path, struct event_iter *iter)
{
	struct stat st;
	const char *system = iter->system_dent->d_name;
	char *file;
	char *enable = NULL;
	char *str;
	int ret = 0;

	file = append_file(path, system);

	stat(file, &st);
	if (!S_ISDIR(st.st_mode))
		goto out;

	enable = append_file(file, "enable");
	str = get_file_content(enable);
	if (!str)
		goto out;

	if (*str != '1' && *str != '0')
		ret = 1;
	free(str);

 out:
	free(enable);
	free(file);

	return ret;
}
Beispiel #4
0
void test_traversal(void)
{
	FILENODE *node[5];
	FILENODE *current_node;
	GtkTreeIter iter;
	int i = 0;
	init_file_list();

	node[0] = append_file("file1", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[0]);
	node[1] = append_file("file2", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[1]);
	node[2] = append_file("file3", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[2]);
	node[3] = append_file("file4", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[3]);
	node[4] = append_file("file5", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[4]);

	current_node = get_next_node(NULL);
	CU_ASSERT_PTR_NOT_NULL(current_node);
	while (current_node != NULL)
	{
		CU_ASSERT_NOT_EQUAL(i, 5);
		CU_ASSERT_PTR_EQUAL(current_node, node[i]);
		current_node = get_next_node(current_node);
		i++;
	}
}
Beispiel #5
0
static int load_events(struct pevent *pevent, const char *system,
			const char *sys_dir)
{
	struct dirent *dent;
	struct stat st;
	DIR *dir;
	int len = 0;
	int ret = 0, failure = 0;

	ret = stat(sys_dir, &st);
	if (ret < 0 || !S_ISDIR(st.st_mode))
		return EINVAL;

	dir = opendir(sys_dir);
	if (!dir)
		return errno;

	while ((dent = readdir(dir))) {
		const char *name = dent->d_name;
		char *event;
		char *format;
		char *buf;

		if (strcmp(name, ".") == 0 ||
		    strcmp(name, "..") == 0)
			continue;

		event = append_file(sys_dir, name);
		ret = stat(event, &st);
		if (ret < 0 || !S_ISDIR(st.st_mode))
			goto free_event;

		format = append_file(event, "format");
		ret = stat(format, &st);
		if (ret < 0)
			goto free_format;

		len = read_file(format, &buf);
		if (len < 0)
			goto free_format;

		ret = pevent_parse_event(pevent, buf, len, system);
		free(buf);
 free_format:
		free(format);
 free_event:
		free(event);
		if (ret)
			failure = ret;
	}

	closedir(dir);
	return failure;
}
Beispiel #6
0
int append_ramdisk(int ofd, off_t pos) {
	//TODO:
	// - MTK ramdisk
	if(access("ramdisk-mtk", R_OK) == 0) {
		fprintf(stderr, "Repacking mtk-style ramdisk is not supported yet\n");
		exit(1);
	} else if(access("ramdisk.gz", R_OK) == 0) {
		return append_file(ofd, "ramdisk.gz", pos);
	} else {
		return append_file(ofd, "ramdisk", pos);
	}
}
Beispiel #7
0
void test_append_file(void)
{
	FILENODE *node;
	GtkTreeIter iter;
	init_file_list();

	node = append_file("file1", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);

	node = append_file("file2", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);

	destroy_file_list();
}
Beispiel #8
0
void test_find_file(void)
{
	FILENODE *node;
	FILENODE *keeper_node;
	GtkTreeIter iter;
	GtkTreeIter keeper_iter;
	init_file_list();

	node = append_file("file1", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);

	node = append_file("file2", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);
	node = append_file("file3", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);

	node = append_file("file4", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);
	keeper_node = append_file("file5", "schema", "table", "geom_column", "-1", 'c', &keeper_iter);
	CU_ASSERT_PTR_NOT_NULL(node);

	node = append_file("file6", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);
	node = append_file("file7", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);

	node = append_file("file8", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node);

	node = find_file_by_iter(&keeper_iter);
	CU_ASSERT_PTR_NOT_NULL(node);
	CU_ASSERT_PTR_EQUAL(node, keeper_node);

	destroy_file_list();
}
Beispiel #9
0
static void
process_event_enable(char *path, const char *system, const char *name,
		     enum event_process *processed)
{
	struct stat st;
	char *enable = NULL;
	char *file;
	char *str;

	if (system)
		path = append_file(path, system);

	file = append_file(path, name);

	if (system)
		free(path);

	stat(file, &st);
	if (!S_ISDIR(st.st_mode))
		goto out;

	enable = append_file(file, "enable");
	str = get_file_content(enable);
	if (!str)
		goto out;

	if (*str == '1') {
		if (!system) {
			if (!*processed)
				printf(" Individual systems:\n");
			printf( "   %s\n", name);
			*processed = PROCESSED_SYSTEM;
		} else {
			if (!*processed) {
				printf(" Individual events:\n");
				*processed = PROCESSED_SYSTEM;
			}
			if (*processed == PROCESSED_SYSTEM) {
				printf("    %s\n", system);
				*processed = PROCESSED_EVENT;
			}
			printf( "        %s\n", name);
		}
	}
	free(str);

 out:
	free(enable);
	free(file);
}
Beispiel #10
0
int pass_user_ident(const char *userid, const char *ident_mailheader,
		    const char *stamp)
{
	FILE *fps;
	char buf[PATHLEN], srcfile[PATHLEN], destfile[PATHLEN];
	char title[STRLEN];

	sethomefile(destfile, userid, UFNAME_IDENT);
	if (append_file(destfile, ident_mailheader) == -1)
		return -1;

	if (set_passwd_ident_ok(userid, 7) == -1)
		return -1;

	sprintf(srcfile, "%s/%s", BBSPATH_IDENT, stamp);
	get_realuser_path(destfile, userid);
	sprintf(title, "身份確認: %s", userid);
	do_article(srcfile, destfile, userid, title);

	sprintf(buf, "tmp/%sPGP", userid);
	a_encode(srcfile, buf, destfile);

	del_ident_article(userid);

	sprintf(buf, "tmp/%s.idented", userid);
	if ((fps = fopen(buf, "w")) != NULL)
	{
		sprintf(title, "[通知] %s 您已通過本站身份認證!", userid);

		write_article_header(fps, "SYSOP", "系統管理者", NULL, NULL, title, NULL);
		fclose(fps);

		append_file(buf, IDENTED);

		/* mail to user to infor that he has been idented in our bbs */
		if (SendMail(-1, buf, "SYSOP", userid, title, 7) < 0)
		{
/*
			bbslog("ERROR", "idcheck: SendMail fail for idented notify!\n");
*/
		}

		unlink(buf);
	}

	return 0;

}
Beispiel #11
0
static int read_header(struct pevent *pevent, const char *events_dir)
{
	struct stat st;
	char *header;
	char *buf;
	int len;
	int ret = -1;

	header = append_file(events_dir, "header_page");

	ret = stat(header, &st);
	if (ret < 0)
		goto out;

	len = read_file(header, &buf);
	if (len < 0)
		goto out;

	pevent_parse_header_page(pevent, buf, len, sizeof(long));

	free(buf);

	ret = 0;
 out:
	free(header);
	return ret;
}
static void     receiving(t_server *serv, t_user *user, \
			  t_user *tosend, char *filename)
{
  char		ret[512];
  int		port;

  sprintf(ret, "%s_%s_%s", user->nick, tosend->nick, filename);
  if (!file_exists(serv->files, ret))
    {
      port = init_passive(user);
      serv->fd_type[user->sf] = FD_SFILE_READ;
      serv->fct_read[user->sf] = file_read;
      serv->fct_write[user->sf] = NULL;

      serv->files = append_file(serv->files, ret, user->sf);

      sprintf(ret, "SEND_FILE :%s: Send Command (127,0,0,1,%d,%d)\r\n", \
	      filename, port / 256, port % 256);
      swrite(user->fd, ret);

      sprintf(ret, ":%s SEND_FILE :%s\r\n", user->nick, filename);
      swrite(tosend->fd, ret);
    }
  else
    swrite(user->fd, "424 ERR_FILERROR :File already exists\r\n");
}
Beispiel #13
0
static int APPEND(test_input_t *t)
{
	int i;
	int total_written_bytes = 0;

	//show_test_input(t);

	t->append_count = 0;
	for (i = 0; i < t->max_append_count; i++) {
		int id = t->test_order[i];
		int ret = append_file(t, &(t->test_files[id-1]));
		total_written_bytes += t->test_files[id-1].written_bytes;
		if (ret == FAIL) {
			error("%d'th append_file(id[%d]) failed.", i, id);
			error("total written bytes[%d]", total_written_bytes);
			return FAIL;
		}

		t->append_count++;

		if ( ret == SEGMENT_FULL ) break;
	}
	info("total written bytes[%d]", total_written_bytes);

	return SUCCESS;
}
Beispiel #14
0
void Ipdb::EncMsg(GT M, string Msg, string fname)
{
	Big aes_key_big = pfc->hash_to_aes_key(M);
	char aes_key_char[AES_SECURITY/8];
	aes_key_char << aes_key_big;

	// Crypt using openssl cbc
	/* init vector */
	unsigned char iv_enc[AES_BLOCK_SIZE];
	for(int i=0;i<AES_BLOCK_SIZE;i++)
		iv_enc[i]=0;

	// Create sha256 for Msg and add first 128 bit at the end of it
	string sha = stdsha256(Msg);
	sha = sha.substr(0,16);
	Msg = Msg+sha;

	// buffers for encryption
	size_t inputslength = Msg.size();
	const size_t encslength = ((inputslength + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
	unsigned char enc_out[encslength];
	memset(enc_out, 0, sizeof(enc_out));

	// so i can do with this aes-cbc-128 aes-cbc-192 aes-cbc-256
	AES_KEY enc_key;
	AES_set_encrypt_key((const unsigned char *)aes_key_char, AES_SECURITY, &enc_key);
	AES_cbc_encrypt((const unsigned char *)Msg.c_str(), enc_out, inputslength, &enc_key, iv_enc, AES_ENCRYPT);

	append_file(fname,enc_out, encslength, NULL);
}
Beispiel #15
0
Datei: files.c Projekt: h3rb/gc
void OUTPUT(char *fmt, ...)
{
  char buf[2048];
  va_list args;
  va_start(args, fmt);
  vsprintf(buf, fmt, args);
  append_file( "gc.log", buf );
  va_end(args);
  return;
}
Beispiel #16
0
void create_file_from_file(int dir_inum, const char *name)
{
    FILE *infile = fopen(name, "rb");
    inode *in = new_inode(file_size(name), FILE_INODE);
    write_inode_to_disk(in);
    create_dir_entry(name, dir_inum, in->num);
    append_file(in->num, infile, file_size(name));
    free(in);
    fclose(infile);
} 
Beispiel #17
0
static void
process_event_trigger(char *path, struct event_iter *iter, enum event_process *processed)
{
	const char *system = iter->system_dent->d_name;
	const char *event = iter->event_dent->d_name;
	struct stat st;
	char *trigger = NULL;
	char *file;
	char *str;
	char *cont;

	path = append_file(path, system);
	file = append_file(path, event);
	free(path);

	stat(file, &st);
	if (!S_ISDIR(st.st_mode))
		goto out;

	trigger = append_file(file, "trigger");
	str = get_file_content(trigger);
	if (!str)
		goto out;

	cont = strstrip(str);

	if (cont[0] == '#') {
		free(str);
		goto out;
	}

	if (!*processed)
		printf("\nTriggers:\n");
	printf( "  %s:%s \"%s\"\n", system, event, cont);
	*processed = PROCESSED_SYSTEM;
	free(str);

 out:
	free(trigger);
	free(file);
}
Beispiel #18
0
enum event_iter_type
trace_event_iter_next(struct event_iter *iter, const char *path, const char *system)
{
	struct dirent *dent;

	if (system && !iter->event_dir) {
		char *event;
		struct stat st;

		event = append_file(path, system);

		stat(event, &st);
		if (!S_ISDIR(st.st_mode)) {
			free(event);
			goto do_system;
		}

		iter->event_dir = opendir(event);
		if (!iter->event_dir)
			die("opendir %s", event);
		free(event);
	}

	if (iter->event_dir) {
		while ((dent = readdir(iter->event_dir))) {
			const char *name = dent->d_name;

			if (strcmp(name, ".") == 0 ||
			    strcmp(name, "..") == 0)
				continue;

			iter->event_dent = dent;
			return EVENT_ITER_EVENT;
		}
		closedir(iter->event_dir);
		iter->event_dir = NULL;
	}

 do_system:
	while ((dent = readdir(iter->system_dir))) {
		const char *name = dent->d_name;

		if (strcmp(name, ".") == 0 ||
		    strcmp(name, "..") == 0)
			continue;

		iter->system_dent = dent;

		return EVENT_ITER_SYSTEM;
	}

	return EVENT_ITER_NONE;
}
Beispiel #19
0
void tracecmd_free_recorder(struct tracecmd_recorder *recorder)
{
	if (!recorder)
		return;

	if (recorder->max) {
		/* Need to put everything into fd1 */
		if (recorder->fd == recorder->fd1) {
			int ret;
			/*
			 * Crap, the older data is in fd2, and we need
			 * to append fd1 onto it, and then copy over to fd1
			 */
			ret = append_file(recorder->page_size,
					  recorder->fd2, recorder->fd1);
			/* Error on copying, then just keep fd1 */
			if (ret) {
				lseek64(recorder->fd1, 0, SEEK_END);
				goto close;
			}
			lseek64(recorder->fd1, 0, SEEK_SET);
			ftruncate(recorder->fd1, 0);
		}
		append_file(recorder->page_size, recorder->fd1, recorder->fd2);
	}
 close:
	if (recorder->trace_fd >= 0)
		close(recorder->trace_fd);

	if (recorder->fd1 >= 0)
		close(recorder->fd1);

	if (recorder->fd2 >= 0)
		close(recorder->fd2);

	free(recorder);
}
Beispiel #20
0
	unsigned long pack(const char* path,MPQPackage* pPkg,FILE* fp_log)
	{
		int count = 0;
		string sFileKey = "";
		string sFindKey = path;
		sFindKey.append("/*.*");

		WIN32_FIND_DATA fileData;
		HANDLE hNextFile=::FindFirstFile(sFindKey.c_str(),&fileData);
		if(INVALID_HANDLE_VALUE == hNextFile)
		{
			return 0;
		}

		do{
			if(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if(fileData.cFileName[0] != '.')
				{
					sFindKey = path;
					sFindKey.append("/");
					sFindKey.append(fileData.cFileName);
					count += pack(sFindKey.c_str(),pPkg,fp_log);
				}
			}
			else
			{      //deal with FindFileData.cFileName	
				sFileKey = path;
				sFileKey += "/";
				sFileKey += fileData.cFileName;

				if (std::string::npos != sFileKey.find(".svn"))
				{
					continue;
				}

				if ( append_file("",sFileKey.c_str(),pPkg,fp_log) )
				{
					++count;
				}

				m_pOwner->setPos(m_pOwner->getPos()+1);
			}
		}while(FindNextFile(hNextFile,&fileData));

		FindClose(hNextFile);

		return count;
	}
static file_info *
sc_profile_instantiate_file(sc_profile_t *profile, file_info *ft,
		file_info *parent, unsigned int skew)
{
	struct file_info *fi;
	sc_card_t	*card = profile->card;

	fi = (file_info *) calloc(1, sizeof(*fi));
	if (fi == NULL)
		return NULL;
	fi->instance = fi;
	fi->parent = parent;
	fi->ident = strdup(ft->ident);
	if (fi->ident == NULL) {
		free(fi);
		return NULL;
	}
	sc_file_dup(&fi->file, ft->file);
	if (fi->file == NULL) {
		free(fi->ident);
		free(fi);
		return NULL;
	}
	fi->file->path = parent->file->path;
	fi->file->id += skew;
	sc_append_file_id(&fi->file->path, fi->file->id);

	append_file(profile, fi);

	ft->instance = fi;

	if (card->ctx->debug >= 2) {
		char pbuf[SC_MAX_PATH_STRING_SIZE];

		int r = sc_path_print(pbuf, sizeof(pbuf), &fi->file->path);
		if (r != SC_SUCCESS)
			pbuf[0] = '\0';

		sc_debug(card->ctx, "Instantiated %s at %s", ft->ident, pbuf);

		r = sc_path_print(pbuf, sizeof(pbuf), &parent->file->path);
		if (r != SC_SUCCESS)
			pbuf[0] = '\0';

		sc_debug(card->ctx, "  parent=%s@%s", parent->ident, pbuf);
	}

	return fi;
}
Beispiel #22
0
void combine_star_creation_log(){
  char filename_screst[256];
  char filename_local[256];
  int proc;
  FILE *fp;

  sprintf(filename_screst,"%s/restart_star_creation.log",output_directory);
  for ( proc = 0; proc < num_procs; proc++ ) {
    sprintf(filename_local,"%s/star_temp."ART_PROC_FORMAT".log",output_directory,proc);
    fp = fopen(filename_local,"r");
    if( fp != NULL ) {fclose(fp); 
      cart_debug("combine_star_creation_log %s to %s",filename_local,filename_screst);
      append_file( filename_local, filename_screst);
    }
  }
}
Beispiel #23
0
void	ft_not_fd_right_append(char **path, char **arg, char ***env, t_ast *ast)
{
	int		status;
	int		i;
	int		fildes;
	char	**cmd;

	if ((i = fork()) > 0)
		waitpid(-1, &status, WNOHANG & WUNTRACED);
	else if (i == 0)
	{
		cmd = ft_strsplit(ast->right, ' ');
		if ((fildes = append_file(cmd[0])) == -1)
			return ;
		dup2(fildes, 1);
		ft_execute(path, arg, env);
	}
}
/*
 * Add a new file to the profile.
 * This function is called by sc_profile_add_file.
 */
static file_info *
add_file(sc_profile_t *profile, const char *name,
		sc_file_t *file, file_info *parent)
{
	file_info	*info;

	info = (struct file_info *) calloc(1, sizeof(*info));
	if (info == NULL)
		return NULL;
	info->instance = info;
	info->ident = strdup(name);

	info->parent = parent;
	info->file = file;

	append_file(profile, info);
	return info;
}
int main(int argc, char *argv[]) {
    oss_media_init(AOS_LOG_INFO);
    
    if (argc < 2) {
        usage();
        return -1;
    }
    
    // example of oss media file functions
    if (strcmp("write", argv[1]) == 0) {
        write_file();
    } else if (strcmp("append", argv[1]) == 0) {
        append_file();
    } else if (strcmp("read", argv[1]) == 0) {
        read_file();
    } else if (strcmp("seek", argv[1]) == 0) {
        seek_file();
    } else if (strcmp("error_code", argv[1]) ==0) {
        error_code();
    } else if (strcmp("idr", argv[1]) == 0) {
        if (argc < 3) {
            usage();
            return -1;
        }

        idr(argv[2]);
    } else if (strcmp("perf", argv[1]) == 0) {
        int loop = (argc == 3) ? atoi(argv[2]) : 1000;
        perf(loop);
    } else if (strcmp("app", argv[1]) == 0) {
        if (argc < 3) {
            usage();
            return -1;
        }

        camera_app(argv[2]);
    } else {
        printf("Unsupport operation:%s\n", argv[1]);
        usage();
    }

    oss_media_destroy();
    return 0;
}
Beispiel #26
0
error_t read_file(char* path, void* state)
{
  FILE* f;
  bwt_state_t* s = (bwt_state_t*) state;
  prepared_text_t* p = &s->p;
  error_t err;

  // First thing, open the file
  f = fopen(path, "r");
  if( ! f ) return ERR_IO_STR("Could not open file");

  printf("%s\n", path);

  // now append the file.
  err = append_file(p, f, 0, NULL, NULL, strlen(path), (unsigned char*) path);
  fclose(f);
  if( err ) return err;

  return ERR_NOERR;
}
Beispiel #27
0
int process(const char *files_dir, const char *prefix, int file_number)
{
	struct fi_data_t f_data;
	int  f_handle;
	char cur_file[0x100];
	char cwd[0x100];
	char tag_names[MAX_FILES][0x100];
	int  no;

	_getcwd(cwd, sizeof(cwd));
	printf("cwd=%s\n", cwd);
	for (no = 0; no < MAX_FILES; no++)
	{
		sprintf(tag_names[no], "%s\\%s-%03d.txt", cwd, prefix, no);
		_unlink(tag_names[no]);
	}

	f_handle = fi_first(files_dir, &f_data);
	printf("0\n");
	if (!f_handle)
	{
		last_err = ERR_FILE_OPEN;
		return 0;
	}

	printf("0\n");
	do
	{
		sprintf(cur_file, "%s\\%s", f_data.dir, f_data.name);
		no = rand() % file_number;
//		printf("no:%d, src:%s, tag:%s\n", no, cur_file, tag_names[no]);
		if (!append_file(tag_names[no], cur_file))
		{
			fi_close(f_handle);
			return 0;
		}
	}while(-1 != fi_next(f_handle, &f_data));

	fi_close(f_handle);
	return 1;
}
Beispiel #28
0
/*
**  insert_comment ()
*/
STATUS
insert_comment ()
{
    STATUS                 ret_val ;
    OFFSET_TYPE            size ;

    if ((ret_val = bld_cmtName(msg)) != OK)
    {
        disp_line(msg, 0, 0);
    }
    else if (SEP_LOexists(cmtLoc))
    {
        LOsize(cmtLoc, &size);
        if (size > 0)
        {
            append_line(OPEN_COMMENT, 1);
            append_file(cmtName);
            append_line(CLOSE_COMMENT, 1);
        }
        del_floc(cmtLoc);
    }

    return (ret_val);
} /* end of insert_comment */
Beispiel #29
0
/**
 * tracecmd_fill_local_events - Fill a pevent with the events on system
 * @tracing_dir: The directory that contains the events.
 * @pevent: Allocated pevent which will be filled
 *
 * Returns whether the operation succeeded
 */
int tracecmd_fill_local_events(const char *tracing_dir, struct pevent *pevent)
{
	struct dirent *dent;
	char *events_dir;
	struct stat st;
	DIR *dir;
	int ret, failure = 0;

	if (!tracing_dir)
		return -1;

	events_dir = append_file(tracing_dir, "events");
	if (!events_dir)
		return -1;

	ret = stat(events_dir, &st);
	if (ret < 0 || !S_ISDIR(st.st_mode)) {
		ret = -1;
		goto out_free;
	}

	dir = opendir(events_dir);
	if (!dir) {
		ret = -1;
		goto out_free;
	}

	ret = read_header(pevent, events_dir);
	if (ret < 0) {
		ret = -1;
		goto out_free;
	}

	while ((dent = readdir(dir))) {
		const char *name = dent->d_name;
		char *sys;

		if (strcmp(name, ".") == 0 ||
		    strcmp(name, "..") == 0)
			continue;

		sys = append_file(events_dir, name);
		ret = stat(sys, &st);
		if (ret < 0 || !S_ISDIR(st.st_mode)) {
			free(sys);
			continue;
		}

		ret = load_events(pevent, name, sys);

		free(sys);

		if (ret)
			failure = 1;
	}

	closedir(dir);
	/* always succeed because parsing failures are not critical */
	ret = 0;

 out_free:
	free(events_dir);

	pevent->parsing_failures = failure;

	return ret;
}
Beispiel #30
0
RF_class *RF_construct(BYTE *filename, WORD compacting) {
	RF_class *RF;
	WORD i;
	OD_block *tmp;
	OD_link *link;
	OD_link **prev;
	ULONG next;

	RF = (RF_class*) mem_alloc(sizeof(RF_class));

	RF->filename = str_alloc(filename);

	while ((RF->file = open(filename, O_RDWR)) == -1) {
		if (compacting)
			report(E_NOTICE, NULL, MSG_CMR, filename);
		else
			report(E_NOTICE, NULL, MSG_CNR, filename);

		RF->hdr.file_size = sizeof(RF_file_hdr) + sizeof(OD_block);
		RF->hdr.lost_space = 0L;
		RF->hdr.FOB = sizeof(RF_file_hdr);
		RF->hdr.create_time = RF->hdr.modify_time = current_time();
		strcpy(RF->hdr.signature, RF_SIGNATURE);

		if (!write_file(filename, &RF->hdr, sizeof(RF_file_hdr)))
			report(E_FATAL, NULL, MSG_CWR, filename);

		tmp = (OD_block*) mem_alloc(sizeof(OD_block));
		tmp->next = 0L;
		for (i = 0; i < OD_SIZE; i++) {
			tmp->flags[i] = SA_UNUSED;
			tmp->index[i] = 0;
		}

		if (!append_file(filename, tmp, sizeof(OD_block)))
			report(E_FATAL, NULL, MSG_CWR, filename);

		mem_free(tmp);
	}

	r_read(RF->file, &RF->hdr, sizeof(RF_file_hdr));

	if (strcmp(RF->hdr.signature, RF_SIGNATURE))
		report(E_FATAL, NULL, MSG_OBF, filename);

	RF->touched = 0;

	next = RF->hdr.FOB;
	prev = &RF->root;
	while (next) {
		link = (OD_link*) mem_alloc(sizeof(OD_link));

		link->touched = 0;
		link->origin = lseek(RF->file, next, SEEK_SET);
		r_read(RF->file, &link->blk, sizeof(OD_block));

		next = link->blk.next;
		*prev = link;
		prev = &link->next;
	}
	*prev = NULL;

	return (RF);
}