Exemplo n.º 1
0
void test_scan_while(){
	int fd = open("scanner_test_code", O_RDONLY);
	check_msg(fd != -1, "failed to open the scanner_test_code file");
	scanner_p scan = scan_open(fd);
	slice_t slice;
	
	// Throw the first two lines away
	scan_until(scan, &slice, '\n');
	check_str(slice.ptr, "\"hello world\"");
	free(slice.ptr);
	scan_until(scan, &slice, '\n');
	check_str(slice.ptr, "\t ");
	free(slice.ptr);
	
	int c = scan_while(scan, &slice, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
	check_msg(c == '\n', "expected newline as terminator but got %d", c);
	check_msg(slice.length == 10, "expected length of 10 but got %d", slice.length);
	check_str(slice.ptr, "1234567890");
	free(slice.ptr);
	
	c = scan_while(scan, &slice, '\n', '-');
	check_msg(c == EOF, "expected EOF as terminator but got %d", c);
	check_msg(slice.length == 5, "expected length of 10 but got %d", slice.length);
	check_str(slice.ptr, "\n----");
	free(slice.ptr);
	
	scan_close(scan);
	close(fd);
}
Exemplo n.º 2
0
void test_string_scanner(){
	scanner_p scan = scan_open_string("say(hello)");
	slice_t slice;
	
	int c = scan_while_func(scan, &slice, isalpha);
	check_msg(c == '(', "expected ( as terminator but got %c", c);
	check_msg(slice.length == 3, "expected 3 characters for the first word but got length %d", slice.length);
	check_str(slice.ptr, "say");
	free(slice.ptr);
	
	c = scan_one_of(scan, '(');
	check_msg(c == '(', "somehow reading the opening braces failed, got %c", c);
	
	c = scan_until(scan, &slice, ')');
	check_msg(c == ')', "expected ) as terminator but got %c", c);
	check_str(slice.ptr, "hello");
	free(slice.ptr);
	
	c = scan_until(scan, &slice, EOF);
	check_msg(c == EOF, "expected EOF as terminator but got %d", c);
	check_msg(slice.length == 0, "expected an empty string until EOF but got length %d", slice.length);
	check_str(slice.ptr, "");
	free(slice.ptr);
	
	scan_close(scan);
}
Exemplo n.º 3
0
void test_scan_until(){
	int fd = open("scanner_test_code", O_RDONLY);
	check_msg(fd != -1, "failed to open the scanner_test_code file");
	scanner_p scan = scan_open(fd);
	slice_t slice;
	
	int c = scan_until(scan, &slice, '"');
	check_msg(c == '"', "expected terminator \" but got %c (%d)", c, c);
	check_msg(slice.length == 0, "expected length of 0 but got %d", slice.length);
	check_str(slice.ptr, "");
	free(slice.ptr);
	
	c = scan_until(scan, &slice, '"');
	check_msg(c == '"', "expected terminator \" but got %c (%d)", c, c);
	check_msg(slice.length == 11, "expected length of 11 but got %d", slice.length);
	check_str(slice.ptr, "hello world");
	free(slice.ptr);
	
	c = scan_until(scan, &slice, EOF);
	check_msg(c == EOF, "expected terminator EOF but got %d", c);
	check_str(slice.ptr, "\n\t \n1234567890\n----");
	free(slice.ptr);
	
	scan_close(scan);
	close(fd);
}
Exemplo n.º 4
0
int check_arg(char *nom, char *prenom, char *tel)
{
    if (check_str(nom, 1) != 0)
       return 1;
    if (check_str(prenom, 2) != 0)
        return 1;
    if(tel[0] != '0' && strlen(tel) < 10)
    {
        printf("Le numero de telephone rentre n'est pas au bon format\n");
        return 1;
    }
    return 0;
}
Exemplo n.º 5
0
void extract_params(struct intr_frame* f, const char* format, ...)
{
  va_list ap;
  va_start(ap, format);
  char *esp = (char*) f->esp + sizeof(int);
  char *str;
  void *buff;
  unsigned int size;
  while (format && *format) {
	  CHECK_ESP(esp);
    switch (*format) {
    case 'i': // int
      EXTRACT_PARAM(ap, esp, int);
      break;
    case 'u': // unsigned int
      EXTRACT_PARAM(ap, esp, unsigned int);
      break;
    case 's': // string (char*)
      POP_STACK_PARAM(esp, char*, str);
      check_str(str);
      ARG_PARAM(ap, void*) = str;
      break;
    case 'b': // buffer (void* + size_t)
      POP_STACK_PARAM(esp, void*, buff);
      POP_STACK_PARAM(esp, size_t, size);
      check_ptr(buff, size);
      ARG_PARAM(ap, void*) = buff;
      ARG_PARAM(ap, size_t) = size;
      break;
    }
    format++;
  }
  va_end(ap);
}
Exemplo n.º 6
0
double		my_getnbr(char *str)
{
  if (str == NULL)
    fatal_error("Sorry, we have to exit (fatal_error[my_getnbr])\n");
  check_str(str);
  return (atof(str));
}
Exemplo n.º 7
0
unsigned int	my_getnbr_base(char *str, char *base)
{
  if (str == NULL)
    return (0);
  if (str[0] == 0 || base[0] == 0)
    return (0);
  if (check_str(str, base) == 0)
    return (eval_nbr(str, base));
  else
    return (0);
}
Exemplo n.º 8
0
int check_hex_to_decimal(char *in, char *expected)
{
	char buf[20];
	char *out;

	out = hex_to_decimal(in, strlen(in), buf, 20);
	if (out == NULL) {
		fprintf(stderr, "NULL returned from hex_to_decimal\n");
		return 1;
	}
	return check_str(out, expected);
}
Exemplo n.º 9
0
Arquivo: main.c Projeto: ajdavis/mongo
static void
query_docs(WT_CURSOR *cursor, bool mod)
{
	WT_ITEM key, value;
	int i;

	for (i = 0; i < NUM_QUERIES; i++) {
		testutil_check(cursor->next(cursor));
		testutil_check(cursor->get_key(cursor, &key));
		testutil_check(cursor->get_value(cursor, &value));
		check_str((uint64_t)key.data, (char *)value.data, mod);
	}
	printf("%d documents read\n", NUM_QUERIES);
}
Exemplo n.º 10
0
void 		my_exit(t_mysh *mysh)
{
  int 		exite;

  exite = (mysh->tab_com[1]) ? check_str(mysh->tab_com[1]) : 0;
  if (comp_str(mysh->tab_com[0], "exit") == 1)
    {
      if (aff_prompt() == 1)
	my_putstr("exit\n");
      free_command(mysh);
      free_struct(mysh);
      exit(exite);
    }
}
Exemplo n.º 11
0
bool
__check_arg_str (const char *str, const char *file, const char *func, size_t line)
{
  if (!check_str (str))
    {
      rc_errno_set (EINVAL);

      debug_message (file, func, line, "Invalid string passed!\n");

      return false;
    }

  return true;
}
Exemplo n.º 12
0
void test_scan_until_func(){
	int fd = open("scanner_test_code", O_RDONLY);
	check_msg(fd != -1, "failed to open the scanner_test_code file");
	scanner_p scan = scan_open(fd);
	slice_t slice;
	
	int c = scan_until_func(scan, &slice, isspace);
	check_msg(c == ' ', "expected a space as terminator but got %d", c);
	check_msg(slice.length == 6, "expected length of 6 but got %d", slice.length);
	check_str(slice.ptr, "\"hello");
	free(slice.ptr);
	
	scan_close(scan);
	close(fd);
}
Exemplo n.º 13
0
void test_scan_while_func(){
	int fd = open("scanner_test_code", O_RDONLY);
	check_msg(fd != -1, "failed to open the scanner_test_code file");
	scanner_p scan = scan_open(fd);
	slice_t slice;
	
	int c = scan_while_func(scan, &slice, ispunct, islower, isblank);
	check_msg(c == '\n', "expected newline as terminator but got %c", c);
	check_msg(slice.length == 13, "expected length of 13 but got %d", slice.length);
	check_str(slice.ptr, "\"hello world\"");
	free(slice.ptr);
	
	scan_close(scan);
	close(fd);
}
Exemplo n.º 14
0
int	my_getnbr_base(char *str, char *base)
{
  int	sign;
  int	i;

  i = 0;
  if (str[0] == 0 || base[0] == 0)
    return (0);
  sign = det_sign(str);
  while (str[i] == '-' || str[i] == '+')
    str++;
  if (check_str(str, base) == 0)
    return (eval_nbr(sign, str, base));
  else
    return (0);
}
Exemplo n.º 15
0
Arquivo: main.c Projeto: jjzhang/dlm
static void show_all_nodes(int count, struct dlmc_node *nodes_in)
{
	struct dlmc_node *n = nodes_in;
	int i;

	for (i = 0; i < count; i++) {
		printf("nodeid %d member %d failed %d start %d seq_add %u seq_rem %u check %s\n",
			n->nodeid,
			member_int(n),
			n->fail_reason,
			(n->flags & DLMC_NF_START) ? 1 : 0,
			n->added_seq,
			n->removed_seq,
			check_str(n));
		n++;
	}
}
Exemplo n.º 16
0
t_pers *modif(t_pers *annuaire)
{
    char nom[40], nom2[40], prenom[40], tel[11];
    t_pers *tmp = annuaire;
    int choix;

    printf("Saisissez le nom de la personne a modifier\n");
    scanf("%s", nom);
    printf("Saisissez le prenom de la personne a modifier\n");
    scanf("%s", prenom);
    while (tmp != NULL && (strcmp(tmp->nom, strcapitalize(nom)) != 0 && strcmp(tmp->prenom, strcapitalize(prenom)) != 0))
        tmp = tmp->nxt;
    if(tmp != NULL)
    {
        do
        {
            printf("Que voulez vous modifier ?\n");
            printf("1 - Prenom\n2 - Telephone\n3 - Retour au menu principal\n");
            scanf("%d", &choix);
            switch (choix)
            {
                case 1 :
                    do
                    {
                        printf("Saissisez le nouveau prenom\n");
                        scanf("%s", nom);
                    }while(check_str(nom, 2));
                    tmp->prenom = strdup(strcapitalize(nom));
                    printf("Le prenom a bien ete modifie\n");
                break;
                case 2 :
                    printf("Saissisez le nouveau numero de telephone\n");
                    scanf("%s", nom);
                    tmp->tel = strdup(strcapitalize(nom));
                    printf("Le numero de telephone a bien ete modifie a bien ete modifie\n");
                break;
            };
        }while (choix != 3);
    }
    else
        printf("La personne n'a pas ete trouvee\n");
    system("pause");
    system("cls");
    return annuaire;
}
Exemplo n.º 17
0
int cppcms_capi_session_pool_init_from_json(cppcms_capi_session_pool *pool,char const *json)
{
	try {
		if(!pool)
			return -1;
		check_str(json);
		cppcms::json::value v;
		std::istringstream f(json);
		int line = 0;
		if(!v.load(f,true,&line)) {
			std::ostringstream ss;
			ss << "Failed to parse json syntax error in line " << line;
			throw std::runtime_error(ss.str());
		}
		pool->p.reset(new cppcms::session_pool(v));
		pool->p->init();
	} CATCH(pool,0,-1);
}
Exemplo n.º 18
0
static int		check_str(char *str, t_rooms *room)
{
	static int	flag = 1;
	int			i;

	i = 0;
	if (flag == 1)
	{
		if (check_room(str, 0) == 0)
		{
			flag = 2;
			return (check_str(str, room));
		}
		else
			return (1);
	}
	return (check_tube(str, 0, room));
}
Exemplo n.º 19
0
int ss_conf_getnstr(const ss_conf_data_t *conf, const char *conf_name, char *conf_value, const size_t n, const char *comment, const char *default_value)
{
	if (NULL == conf || NULL == conf_name || NULL == conf_value || 0 == n) {
		return SS_CONF_NULL;
	}

	if (conf->build != SS_CONF_READCONF) {
		if (write_comment(conf->conf_file, comment) == SS_CONF_SUCCESS) {
			if (default_value != NULL) {
				fprintf(conf->conf_file, "#[default configure(string), %s : %s]\n%s : %s", conf_name, conf_value, conf_name, conf_value);
			} else {
				fprintf(conf->conf_file, "%s : ", conf_name);
			}
			return SS_CONF_SUCCESS;
		}
		return SS_CONF_NULL;
	}

	int ret;

	ret = load_str(conf, conf_name, conf_value, n);

	if (ret == SS_CONF_LOST) {
		if (default_value != NULL) {
			snprintf(conf_value, n, "%s", default_value);
			SS_LOG_WARNING("load string [%s] fail, use default value [%s]", conf_name, default_value);
			return SS_CONF_DEFAULT;
		}
		SS_LOG_WARNING("load string fail, not found[%s]", conf_name);
		return SS_CONF_LOST;
	}

	if (check_str(conf, conf_name, conf_value) != SS_CONF_CHECKSUCCESS) {
		return SS_CONF_CHECKFAIL;
	}

	SS_LOG_TRACE("get string value [%s : %s]", conf_name, conf_value);

	return ret;

}
Exemplo n.º 20
0
void test_scan_one_of(){
	int fd = open("scanner_test_code", O_RDONLY);
	check_msg(fd != -1, "failed to open the scanner_test_code file");
	scanner_p scan = scan_open(fd);
	
	int c = scan_one_of(scan, '"');
	check_msg(c == '"', "expected an \", got %c", c);
	
	// This tests if scan_one_of really consumes one character and not only
	// increments the buffer position.
	slice_t slice;
	c = scan_until(scan, &slice, '"');
	check_str(slice.ptr, "hello world");
	free(slice.ptr);
	
	c = scan_one_of(scan, '\n');
	check_msg(c == '\n', "expected a line break, got %d", c);
	c = scan_one_of(scan, ' ', '\n', '\t');
	check_msg(c == '\t', "expected a tab, got %d", c);
	
	scan_close(scan);
	close(fd);
}
Exemplo n.º 21
0
int RDFParser::read_rules(stringstream & stream) {
	int ret=0;
	string rulename;
	string rulestr;
	Rule * rule;
	rdfg->graph->resolve();
	while (ret >= 0) {
		ret = check_str(stream, "rule");
		if (ret<0)
			break;
		stream >> rulename;
		rule = new Rule(rulename);
		ret = read_str(stream, "{");
		if (ret < 0)
			return ret;
		ret = read_str(stream, "left");
		if (ret < 0)
			return ret;
		ret = read_graph(stream, rule->left());
		if (ret < 0)
			return ret;
		ret = read_str(stream, "right");
		if (ret < 0)
			return ret;
		ret = read_graph(stream, rule->right());
		if (ret < 0)
			return ret;
		ret = read_str(stream, "}");
		if (ret < 0)
			return ret;

		rule->preprocess();
		rdfg->add_rule(rule);		
	}
	return 0;
}
Exemplo n.º 22
0
int					get_next_line(int const fd, char **line)
{
	static char		*str[256] = {NULL};
	t_line			in;

	in.chr = NULL;
	in.tmp = NULL;
	if (!line || fd < 0 || fd > 256 || !(in.buff = (char *)malloc(sizeof(char)
	* (BUFF_SIZE + 1))))
		return (-1);
	*line = NULL;
	if (str[fd])
		check_str(&in, line, &str[fd]);
	while (!in.chr && (in.oct = read(fd, in.buff, BUFF_SIZE)))
	{
		if (in.oct == -1)
			return (-1);
		in.buff[in.oct] = '\0';
		if (read_buffer(line, &in, &str[fd]))
			break ;
	}
	free_mem(&(in.buff));
	return (*line || str[fd] ? 1 : 0);
}
Exemplo n.º 23
0
void test_scan_peek(){
	scanner_p scan = scan_open_string("say(hello)");
	
	int c = scan_peek(scan);
	check_msg(c == 's', "expected the first character but got %c", c);
	check_msg(scan->col == 1, "expected to still be at column 1 but got column %d", scan->col);
	
	slice_t slice;
	c = scan_while_func(scan, NULL, isalpha);
	check_msg(c == '(', "expected ( as terminator but got %c", c);
	check_str(slice.ptr, "say");
	free(slice.ptr);
	
	c = scan_peek(scan);
	check_msg(c == '(', "expected ( but got %c", c);
	
	c = scan_until(scan, NULL, EOF);
	check_msg(c == EOF, "expected EOF as terminator but got %d", c);
	
	c = scan_peek(scan);
	check_msg(c == EOF, "expected EOF but got %d", c);
	
	scan_close(scan);
}
Exemplo n.º 24
0
char		*ft_strstr(const char *s1, const char *s2)
{
	int		i;
	int		j;
	int		check;

	i = j = 0;
	check = 0;
	if (ft_strlen(s2) == 0)
		return ((char *) s1);
	while (s1[i])
	{
		if (s1[i] == s2[j])
		{
			check = check_str((char *)s1, (char *)s2, i);
			if (check)
				return ((char *)s1 + i);
			check = 0;
			j = 0;
		}
		i++;
	}
	return (NULL);
}
Exemplo n.º 25
0
Arquivo: main.c Projeto: ajdavis/mongo
int
main(int argc, char *argv[])
{
	TEST_OPTS *opts, _opts;
	WT_CURSOR *rcursor, *wcursor;
	WT_ITEM key, value;
	WT_SESSION *session, *session2;
	pthread_t thread;
	uint64_t i;

	char str[] = "0000000000000000";

	/*
	 * Create a clean test directory for this run of the test program if the
	 * environment variable isn't already set (as is done by make check).
	 */
	opts = &_opts;
	memset(opts, 0, sizeof(*opts));
	testutil_check(testutil_parse_opts(argc, argv, opts));
	testutil_make_work_dir(opts->home);
	testutil_check(wiredtiger_open(opts->home,
	    NULL, "create,cache_size=200M", &opts->conn));

	testutil_check(
	    opts->conn->open_session(opts->conn, NULL, NULL, &session));
	testutil_check(
	    opts->conn->open_session(opts->conn, NULL, NULL, &session2));

	testutil_check(session->create(session, name,
	    "key_format=Q,value_format=S"));

	/* Populate the table with some data. */
	testutil_check(session->open_cursor(
	    session, name, NULL, "overwrite", &wcursor));
	for (i = 0; i < NUM_DOCS; i++) {
		wcursor->set_key(wcursor, i);
		rand_str(i, str);
		wcursor->set_value(wcursor, str);
		testutil_check(wcursor->insert(wcursor));
	}
	testutil_check(wcursor->close(wcursor));
	printf("%d documents inserted\n", NUM_DOCS);

	/* Perform some random reads */
	testutil_check(session->open_cursor(
	    session, name, NULL, "next_random=true", &rcursor));
	query_docs(rcursor, false);
	testutil_check(rcursor->close(rcursor));

	/* Setup Transaction to pin the current values */
	testutil_check(
	    session2->begin_transaction(session2, "isolation=snapshot"));
	testutil_check(session2->open_cursor(
	    session2, name, NULL, "next_random=true", &rcursor));

	/* Perform updates in a txn to confirm that we see only the original. */
	testutil_check(session->open_cursor(
	    session, name, NULL, "overwrite", &wcursor));
	for (i = 0; i < NUM_DOCS; i++) {
		rand_str(i, str);
		str[0] = 'A';
		wcursor->set_key(wcursor, i);
		wcursor->set_value(wcursor, str);
		testutil_check(wcursor->update(wcursor));
	}
	testutil_check(wcursor->close(wcursor));
	printf("%d documents set to update\n", NUM_DOCS);

	/* Random reads, which should see the original values */
	query_docs(rcursor, false);
	testutil_check(rcursor->close(rcursor));

	/* Finish the txn */
	testutil_check(session2->rollback_transaction(session2, NULL));

	/* Random reads, which should see the updated values */
	testutil_check(session2->open_cursor(
	    session2, name, NULL, "next_random=true", &rcursor));
	query_docs(rcursor, true);
	testutil_check(rcursor->close(rcursor));

	/* Setup a pre-delete txn */
	testutil_check(
	    session2->begin_transaction(session2, "isolation=snapshot"));
	testutil_check(session2->open_cursor(
	    session2, name, NULL, "next_random=true", &rcursor));

	/* Delete all but one document */
	testutil_check(session->open_cursor(
	    session, name, NULL, "overwrite", &wcursor));
	for (i = 0; i < NUM_DOCS - 1; i++) {
		wcursor->set_key(wcursor, i);
		testutil_check(wcursor->remove(wcursor));
	}
	testutil_check(wcursor->close(wcursor));
	printf("%d documents deleted\n", NUM_DOCS - 1);

	/* Random reads, which should not see the deletes */
	query_docs(rcursor, true);
	testutil_check(rcursor->close(rcursor));

	/* Rollback the txn so we can see the deletes */
	testutil_check(session2->rollback_transaction(session2, NULL));

	/* Find the one remaining document 3 times */
	testutil_check(session2->open_cursor(
	    session2, name, NULL, "next_random=true", &rcursor));
	for (i = 0; i < 3; i++) {
		testutil_check(rcursor->next(rcursor));
		testutil_check(rcursor->get_key(rcursor, &key));
		testutil_check(rcursor->get_value(rcursor, &value));
		/* There should only be one value available to us */
		testutil_assertfmt((uint64_t)key.data == NUM_DOCS - 1,
		    "expected %d and got %" PRIu64,
		    NUM_DOCS - 1, (uint64_t)key.data);
		check_str((uint64_t)key.data, (char *)value.data, true);
	}
	printf("Found the deleted doc 3 times\n");
	testutil_check(rcursor->close(rcursor));

	/* Repopulate the table for compact. */
	testutil_check(session->open_cursor(
	    session, name, NULL, "overwrite", &wcursor));
	for (i = 0; i < NUM_DOCS - 1; i++) {
		wcursor->set_key(wcursor, i);
		rand_str(i, str);
		str[0] = 'A';
		wcursor->set_value(wcursor, str);
		testutil_check(wcursor->insert(wcursor));
	}
	testutil_check(wcursor->close(wcursor));

	/* Run random cursor queries while compact is running */
	testutil_check(session2->open_cursor(
	    session2, name, NULL, "next_random=true", &rcursor));
	testutil_check(pthread_create(&thread, NULL, compact_thread, session));
	query_docs(rcursor, true);
	testutil_check(rcursor->close(rcursor));
	testutil_check(pthread_join(thread, NULL));

	/* Delete everything. Check for infinite loops */
	testutil_check(session->open_cursor(
	    session, name, NULL, "overwrite", &wcursor));
	for (i = 0; i < NUM_DOCS; i++) {
		wcursor->set_key(wcursor, i);
		testutil_check(wcursor->remove(wcursor));
	}
	testutil_check(wcursor->close(wcursor));

	testutil_check(session2->open_cursor(
	    session2, name, NULL, "next_random=true", &rcursor));
	for (i = 0; i < 3; i++)
		testutil_assert(rcursor->next(rcursor) == WT_NOTFOUND);
	printf("Successfully got WT_NOTFOUND\n");

	testutil_cleanup(opts);
	return (EXIT_SUCCESS);
}
Exemplo n.º 26
0
void
rc_log_domain (const char *new_domain)
{
  if (check_str (new_domain))
    log_domain = (char *)new_domain;
}
Exemplo n.º 27
0
static int mrb_vm1_setup(void)
{
	char mmc_name[64] = {};
	char mmc_serial[64] = {};
	int ret = 0;
	int fd = -1;

#ifdef CONFIG_MRB_VM1_PTDEV_USB
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_USB_ID_1,
			CONFIG_MRB_VM1_PTDEV_USB_DEVINFO_1);
#endif /*CONFIG_MRB_VM1_PTDEV_USB*/

#ifdef CONFIG_MRB_VM1_PTDEV_AUDIO
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_AUDIO_ID,
			CONFIG_MRB_VM1_PTDEV_AUDIO_DEVINFO);
#endif /*CONFIG_MRB_VM1_PTDEV_AUDIO*/

#ifdef CONFIG_MRB_VM1_PTDEV_AUDIO_CODEC
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_AUDIO_CODEC_ID,
			CONFIG_MRB_VM1_PTDEV_AUDIO_CODEC_DEVINFO);
#endif /*CONFIG_MRB_VM1_PTDEV_AUDIO*/

#ifdef CONFIG_MRB_VM1_PTDEV_CSME
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_CSME_ID,
			CONFIG_MRB_VM1_PTDEV_CSME_DEVINFO);
#endif /*CONFIG_MRB_VM1_PTDEV_CSME*/

#ifdef CONFIG_MRB_VM1_PTDEV_IPU
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_IPU_ID,
			CONFIG_MRB_VM1_PTDEV_IPU_DEVINFO);
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_IPU_I2C_ID,
			CONFIG_MRB_VM1_PTDEV_IPU_I2C_DEVINFO);
#endif /*CONFIG_MRB_VM1_PTDEV_IPU*/

#ifdef CONFIG_MRB_VM1_PTDEV_SD
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_SD_ID,
			CONFIG_MRB_VM1_PTDEV_SD_DEVINFO);
#endif /*CONFIG_MRB_VM1_PTDEV_SD*/

#ifdef CONFIG_MRB_VM1_PTDEV_WIFI
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_WIFI_ID,
			CONFIG_MRB_VM1_PTDEV_WIFI_DEVINFO);
#endif /*CONFIG_MRB_VM1_PTDEV_WIFI*/

#ifdef CONFIG_MRB_VM1_PTDEV_BLUETOOTH
	PTDEV_SETUP(CONFIG_MRB_VM1_PTDEV_BLUETOOTH_ID,
			CONFIG_MRB_VM1_PTDEV_BLUETOOTH_DEVINFO);
#endif /*CONFIG_MRB_VM1_PTDEV_BLUETOOTH*/

	memset(kernel_cmdline, 0, sizeof(kernel_cmdline));

	fd = open("/sys/block/mmcblk1/device/name", O_RDONLY);
	if (fd >= 0) {
		ret = read(fd, mmc_name, sizeof(mmc_name));
		if (ret >= sizeof(mmc_name))
			mmc_name[sizeof(mmc_name) - 1] = 0;
		check_str(mmc_name, sizeof(mmc_name));
		close(fd);
	}

	fd = open("/sys/block/mmcblk1/device/serial", O_RDONLY);
	if (fd >= 0) {
		ret = read(fd, mmc_serial, sizeof(mmc_serial));
		if (ret >= sizeof(mmc_serial))
			mmc_name[sizeof(mmc_serial) - 1] = 0;
		check_str(mmc_serial, sizeof(mmc_serial));
		close(fd);
	}

	snprintf(kernel_cmdline, sizeof(kernel_cmdline) - 1, cmdline_fmt,
		       mmc_name, mmc_serial);

	return 0;
}
Exemplo n.º 28
0
int main() {
	{
		void* table[2];
		ArrayList buf = new_array_list(table);

		check_int(2, buf.capacity);
		check_int((size_t)0, buf.size(&buf));
		check_int(table, buf.pBuf);

		char str1[] = "hello";
		buf.add(&buf, str1);

		check_int(2, buf.capacity);
		check_int((size_t)1, buf.size(&buf));
		check_int(table, buf.pBuf);

		char str2[] = "world";
		buf.add(&buf, str2);

		check_int(2, buf.capacity);
		check_int((size_t)2, buf.size(&buf));
		check_int(table, buf.pBuf);

		//check_int(str1, buf.remove(&buf, str1));
		check_str(str1, (char*)buf.remove(&buf, str1));

		check_int(2, buf.capacity);
		check_int((size_t)1, buf.size(&buf));
		check_str(str2, (char*)buf.get(&buf, 0));

		check_int(NULL, buf.remove(&buf, str1));

		check_int(2, buf.capacity);
		check_int((size_t)1, buf.size(&buf));
		check_str(str2, (char*)buf.get(&buf, 0));

		//check_int(str2, buf.remove(&buf, str2));
		check_str(str2, (char*)buf.remove(&buf, str2));

		check_int(2, buf.capacity);
		check_int((size_t)0, buf.size(&buf));

		check_int(NULL, buf.remove(&buf, str2));
	}

	{
		char tmpFileName[L_tmpnam + 1];
		tmpnam(tmpFileName);

		FILE* fp = fopen(tmpFileName, "wb");
		check_bool(true, write_int(fp, 1231));
		check_bool(true, write_int(fp, 1));
		check_bool(true, write_int(fp, 441));
		check_int(0, fclose(fp));

		int_sorter(tmpFileName);

		fp = fopen(tmpFileName, "rb");
		check_int(1, read_int(fp));
		check_int(441, read_int(fp));
		check_int(1231, read_int(fp));
		check_int(0, fclose(fp));
	}

	{
		char tmpFileName[L_tmpnam + 1];
		tmpnam(tmpFileName);

		FILE* fp = fopen(tmpFileName, "w");
		check_int(0, fclose(fp));

		int_sorter(tmpFileName);
	}

	{
		int_sorter("--------------xxxxxxxxxxxxxxxxxxxxx");
	}
}
Exemplo n.º 29
0
int
get_mail(char *host, char *oboard, char *iboard)
{
	int fd;
	FILE *fp0;
	int i;
	struct sockaddr_in xs;
	struct hostent *he;
	char dir[80], file[80], buf[256], brk[80];
//      file: 本地文件名, buf: 临时变量, brk: 分隔符.

	servernow = host;

	do_log("gethostbyname %s", host);
	bzero((char *) &xs, sizeof (xs));
	xs.sin_family = AF_INET;
	if ((he = gethostbyname(host)) != NULL)
		bcopy(he->h_addr, (char *) &xs.sin_addr, he->h_length);
	else
		xs.sin_addr.s_addr = inet_addr(host);
	xs.sin_port = htons(PORT);
	do_log("connecting %s", host);
	fd = socket(AF_INET, SOCK_STREAM, 0);
	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
	if (connect(fd, (struct sockaddr *) &xs, sizeof (xs)) < 0) {
		fd_set fds;
		struct timeval timeout;
		timeout.tv_sec = 10;
		timeout.tv_usec = 0;
		FD_ZERO(&fds);
		FD_SET(fd, &fds);
		if (select(fd + 1, NULL, &fds, NULL, &timeout) <= 0) {
			do_log("can't connect to %s", host);
			close(fd);
			return;
		}
		if (connect(fd, (struct sockaddr *) &xs, sizeof (xs)) < 0) {
			do_log("can't connect to %s", host);
			close(fd);
			return;
		}
	}
	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
	do_log("connected %s", host);
	fp0 = fdopen(fd, "r+");
	if (fgets(brk, 80, fp0) == 0)
		goto E;
	if (strlen(brk) < 10)
		goto E;
	fprintf(fp0, "select * from %s where dt < %d\n", oboard,
		time(0) - last);
	fflush(fp0);
	do_log("SEND request %s %d", oboard, time(0) - last);
	while (1) {
		FILE *fp;
		int t;
		struct fileheader x;
		char owner[256];
		bzero(&x, sizeof (x));
		do_log("reading...");
		if (fgets(x.title, sizeof (x.title), fp0) == 0)
			break;
		if (fgets(owner, sizeof (owner), fp0) == 0)
			break;
		fh_setowner(&x, owner, 0);
		check_str(x.title);
		check_str(x.owner);
		removetailspace(x.title);
		do_log("%s", x.title);
		sprintf(file, "boards/%s/", iboard);
		t = trycreatefile(file, "M.%d.A", time(NULL), 100);
		x.filetime = t;
		do_log(file);
		do_log(fh2fname(&x));
		fp = fopen(file, "w");
		while (1) {
			if (fgets(buf, 255, fp0) == 0)
				break;
			if (!strcmp(buf, brk))
				break;
			fprintf(fp, "%s", buf);
		}
		fclose(fp);
		if (!valid_user(x.owner)) {
			unlink(file);
			do_log("bad user: %s", x.owner);
			continue;
		}
		fh_find_thread(&x, iboard);
		sprintf(dir, "boards/%s/.DIR", iboard);
		fd = open(dir, O_WRONLY | O_APPEND | O_CREAT, 0660);
		write(fd, &x, sizeof (x));
		close(fd);
		do_log("updatelastpost %s", iboard);
		updatelastpost(iboard);
	};
      E:fclose(fp0);
	close(fd);
	do_log("done");
}
Exemplo n.º 30
0
/* Returns the new priorities if SYSTEM is specified in
 * an allocated string, or just a copy of the provided
 * priorities, appended with any additional present in
 * the priorities string.
 *
 * The returned string must be released using free().
 */
static char *resolve_priorities(const char* priorities)
{
char *p = (char*)priorities;
char *additional = NULL;
char *ret = NULL;
char *ss, *line = NULL;
unsigned ss_len;
int l;
FILE* fp = NULL;
size_t n, n2 = 0, line_size;

	while (c_isspace(*p))
		p++;

	if (*p == '@') {
		ss = p+1;

		additional = strchr(p, ':');
		if (additional != NULL) {
			ss_len = additional - ss;
			additional++;
		} else {
			ss_len = strlen(ss);
		}

		fp = fopen(SYSTEM_PRIORITY_FILE, "r");
		if (fp == NULL) {/* fail */
			ret = NULL;
			goto finish;
		}

		do {
			l = getline(&line, &line_size, fp);
			if (l > 0) {
				p = check_str(line, line_size, ss, ss_len);
				if (p != NULL)
					break;
			}
		} while (l>0);

		if (p == NULL) {
			ret = NULL;
			goto finish;
		}

		n = strlen(p);
		if (additional)
			n2 = strlen(additional);

		ret = malloc(n+n2+1+1);
		if (ret == NULL) {
			goto finish;
		}

		memcpy(ret, p, n);
		if (additional != NULL) {
			ret[n] = ':';
			memcpy(&ret[n+1], additional, n2);
			ret[n+n2+1] = 0;
		} else {
			ret[n] = 0;
		}
	} else {
		return strdup(p);
	}

finish:
	if (ret != NULL) {
		_gnutls_debug_log("selected priority string: %s\n", ret);
	}
	free(line);
	if (fp != NULL)
		fclose(fp);

	return ret;
}