Exemple #1
0
int init_module(void)
{
	struct proc_dir_entry *dir, *dp;
	int rc;

	printk("installing /proc/net/ftp-proxy interface\n");

	/*
	** First, verify that /proc/net is available
	*/
	for (dir = proc_root.subdir; dir; dir = dir->next) {
		if (mystrcmp(dir->name, "net") == 0)
			break;
	}
	if (dir == NULL)
		return -ENOENT;

	/*
	** Then, see if the file is already there
	*/
	for (dp = dir->subdir; dp; dp = dp->next) {
		if (mystrcmp(dp->name, "ftp_proxy") == 0)
			return 0;
	}

	/*
	** Let's go and install the file
	*/
	if ((rc = proc_register(dir, &proc_ftp)) == 0)
		return 0;

	printk(KERN_ALERT "unable to install /proc/net/ftp-proxy\n");
	return rc;
}
Exemple #2
0
/**
   Get the system memory usage.
*/
double get_usage_mem(void){
    double mem=0;
    FILE *fp;
    long memtot;
    long memfree;
    long membuf;
    long memcache;
    fp=fopen("/proc/meminfo","r");
    char line[1024];
    if(!fp) return 0;
    int count=0;
    while(fgets(line, sizeof(line), fp) && count<4){
	if(!mystrcmp(line, "MemTotal:")){
	    if(sscanf(line, "%*s %ld %*s", &memtot)!=1) break;
	    count++;
	}else if(!mystrcmp(line, "MemFree:")){
	    if(sscanf(line, "%*s %ld %*s", &memfree)!=1) break;
	    count++;
	}else if(!mystrcmp(line, "Buffers:")){
	    if(sscanf(line, "%*s %ld %*s", &membuf)!=1) break;
	    count++;
	}else if(!mystrcmp(line, "Cached:")){
	    if(sscanf(line, "%*s %ld %*s", &memcache)!=1) break;
	    count++;
	}
    }
    fclose(fp);
    if(count!=4){
	warning("failed to read meminfo\n");
	return 0;
    }else{
	mem=(double)(memtot-(memfree+membuf+memcache))/(double)memtot;
	return mem;
    }
}
struct index_entry* index_get (const char *key, int key_len) {
  int l = -1;
  int r = index_size;
  while (r-l > 1) {
    int x = (r+l)>>1;
    struct index_entry *entry = (struct index_entry *)&index_binary_data[index_offset[x]];
    if (mystrcmp (entry->data, entry->key_len, key, key_len) < 0) {
      l = x;
    } else {
      r = x;
    }
  }
  if (verbosity>=4) {
    fprintf (stderr, "(l,r) = (%d,%d)\n", l, r);
    fprintf (stderr, "index_size = %d\n", index_size);
  }
  l++;
  struct index_entry *entry;
  if (l < index_size) {
    entry = (struct index_entry *)&index_binary_data[index_offset[l]];
    vkprintf (4, "entry->key_len = %d, key_len = %d\n", entry->key_len, key_len);
    if (verbosity >= 6) {
      int i;
      for (i = 0; i < entry->key_len; i++)
        fprintf (stderr, "%c", entry->data[i]);
      fprintf (stderr, "\n");
    }
  }
  if (l < index_size && !mystrcmp (entry->data, entry->key_len, key, key_len)) { 
    vkprintf (4, "Item found in index.\n");
    return entry;
  }
  return &empty_index_entry;
}
	bool operator == (const Param& p) const
	{
		return mystrcmp(f_fullname, p.f_fullname) == 0
		    // f_name is part of fullname -- already compared
		    && mystrcmp(f_type, p.f_type) == 0
		    // f_ftype is part of fullname -- already compared
		    && mystrcmp(f_default_value, p.f_default_value) == 0
		    && f_function == p.f_function;
	}
/*
 * The following are simple tests to help you.
 * You should develop more extensive tests to try and find bugs.
 */
int main()
{
	const int SIZE = 100;
	char buffer[SIZE];

	assert(mystrlen("cmpt 300") == 8);
	assert(mystrlen("") == 0);

	assert(mystrcmp("adam", "") == 1);
	assert(mystrcmp("", "adam") == -1);
	mystrcpy(buffer, "adam");
	assert(mystrcmp(buffer, "adam") == 0);
	assert(mystrcmp(buffer, "adampie") == -1);
	assert(mystrcmp("applepie", "apple") == 1);
	assert(mystrcmp("", "") == 0);
	assert(mystrcmp(buffer, "ADAM") != 0);
	assert(mystrcmp ("I love coding", "I love coding") == 0);

	char *dupStr = mystrdup(buffer);
	assert (!mystrcmp(buffer, dupStr));
	assert (buffer != dupStr);

	if (dupStr != NULL)
		free (dupStr);

	printf ("\nPassed VERY simple tests, remember to develop more tests.\n");

	return 0;
}
Exemple #6
0
alias_used_builtins ()
{
  int rule, one_builtin_used = false;
  brother = laststdpred;
  for (builtin = laststdpred; builtin != nil; builtin = BROTHER (builtin))
    if ((builtin != cut) && (builtin != nestarset) &&
        (!mystrcmp (REPR (builtin), "select")) &&
        (builtin != tltraditionalterm) &&
        (builtin != transformlatticeterm) &&
        (builtin != tltraditional) &&
        (builtin != transformlattice) &&
        (builtin != skip) &&
        (builtin != explintersect) &&
        (builtin != getip) &&
        (builtin != falseip) &&
        (builtin != restoreip) &&
        (builtin != evalmeta) &&
        (builtin != initmeta) &&
        (builtin != evalmeta) && (builtin != resetinputptr) && (builtin != nestaralt) && (builtin != where))
    {
      int mem, alt;
      char *n, *m = REPR (builtin);
      if (!builtin_used ())
        continue;
      one_builtin_used = true;
      if (det_flag)
        if ((builtin == tltraditional) || (builtin == tltraditionalterm)
            || (mystrcmp (REPR (builtin), "select")) || (mystrcmp (REPR (builtin), "delete")))
          continue;
      make_new_rule (brother);
      new_rule = brother;

      n = (char *) malloc (strlen (m) + 7);
      if (n == NULL)
        fprintf (stderr, "glammar: Out of memory.\n"), exit (-1);
      strcpy (n, "built_"), strcpy (n + 6, m);
      REPR (new_rule) = n;
      SET (new_rule, external);
      PART (new_rule) = PART (root);
      for (rule = root; rule != laststdpred; rule = BROTHER (rule))
        for (alt = SON (rule); alt != nil; alt = BROTHER (alt))
          for (mem = SON (alt); mem != nil; mem = BROTHER (mem))
            if ((builtin == DEF (mem)) && !(TERMINAL (mem)))
            {
              DEF (mem) = new_rule;
              REPR (mem) = n;
            }
    }
  if (!one_builtin_used)
    return;
  for (rule = root; BROTHER (rule) != laststdpred; rule = BROTHER (rule));
  BROTHER (rule) = new_rule;
}
static int ngramcmp_str(const void *a, const void *b)
{
	ngram_t *x = (ngram_t *)a;
	ngram_t *y = (ngram_t *)b;
	
	return mystrcmp( x->str, y->str );
}
bool CTalkName::Add(bool _left, int _num, ...){

	if (_num>0){
		va_list args;
		va_start(args, _num);	//_numが大きすぎたときの処置方法はないのか?

		int side = (_left? 0: 1);
		NowLeft = _left;

		for (int h=0; h<_num; h++){
			char* tmp = va_arg(args, char*);
			
			for (int i=0; i<NAME_NUM; i++){	
				if (mystrcmp(Name[side][i], tmp)){
					break;
				}else if (Name[side][i][0]=='\0'){
					mystrcpy(Name[side][i], tmp, 32);
					break;
				}else if (i==NAME_NUM-1){
					ErrorDx("Error->CTalkName::Add->Too many names :%s", __FILE__, __LINE__, tmp);
					va_end(args);
					return false;
				}				
			}
		}
		va_end(args);
		return true;

	}else{
Exemple #9
0
//session 1
int main(int argc, char*argv[])
{

	for(int i=0;i<argc;i++)
	{	
	//Check my name in the argument
		if(mystrcmp("Chen",argv[i])==0)
		{	
			//copy"Hello" to the array 
			char hi[30];
			mystrcpy(hi,"Hello, ");
			//put my name after hello
			mystrcat(hi,argv[i]);
			printf("%s\n",hi);
		}
		else{
			printf("%s\n",argv[i]);
		}
	}
	

//session 6
	int a[10];
	
	for(int i=0; i<10;i++)
	{
		a[i]=i*i;
		printf("%d\n", *(a+i));
	}
		
}
Exemple #10
0
Local int
compare_string(unsigned char *a, unsigned char *b)

{
    int     i = 0;
    int     j = 0;
    unsigned char      al;
    unsigned char      bl;

    while((a[i] != EOS) || (b[j] != EOS)) 
       {
	if(a[i] == EOS)
	    return(-1);
	if(b[j] == EOS)
	    return(1);
        
	if(blank_ignore)
	   {
	    if(a[i] == SPC)
		i++;
	    if(b[j] == SPC)
		j++;
	   }
	al = TOLOWER(a[i]);
	bl = TOLOWER(b[j]);

	if(al != bl)
	    return(charcmp(al, bl));
	i++;
	j++;
       }
    return(mystrcmp(a, b));
}
Exemple #11
0
void basicresult(int* colname_do,int* likeequal,char(*colvalue)[COLUMN_NAME_MAX],int* operater,Column* columnindex,Data** table_now,int linenum)
{
	int counti=0;   //Count of Column 
	while(colname_do[counti]!=-1)  //not arriver at the end of a table
	{
		int _type= columnindex[colname_do[counti]].nametype;  //Datastyle
		int col = colname_do[counti];  //current column number
		if(likeequal[counti]==0)// It's like
		{
			if(_type) operater[counti]=1;
			else{
				if(mystrstr(table_now[col][linenum].str,colvalue[counti])!=NULL)  //match the needs
					operater[counti]=1;
				else operater[counti]=0;
			}
		}
		else  // It's =
		{
			if(_type)
			{
				operater[counti]= ( (int)table_now[col][linenum].num == atoi(colvalue[counti]) )?1:0;
			}
			else
			{
				if(!mystrcmp(table_now[col][linenum].str,colvalue[counti])) operater[counti]=1;
				else operater[counti]=0;
			}
		}
		counti++;
	}
	operater[counti]=-1;
}
Exemple #12
0
Argptr TpCheckIsProcInScope(char *name,int *currlevel,
		int *proclevel,int *no_of_arg,int *is_func,Typeptr *tptr)
{  Funptr fptr;
   int i,found;
   fptr=currfun;	
   *currlevel=currfun->level;
   // check for parent and grands
   while(fptr->level)	// i.e. dont check for outer block	
   { if(mystrcmp(fptr->fname,name)==0)
     { *proclevel=fptr->level;
	*no_of_arg=fptr->no_of_arg;     
	*is_func=(currfun->ret_type!=NULL);
	 *tptr=currfun->ret_type;
	return fptr->arglist;     
     }
    fptr=fptr->parent; 
   }
   // check for child
   fptr=currfun;
   i=currfun->no_of_children;
   while(i--)
   { if((mystrcmp(currfun->children[i]->fname,name))==0)
	   {*proclevel=fptr->level+1;
	  *no_of_arg=currfun->children[i]->no_of_arg;     
	*is_func=(currfun->ret_type!=NULL);
	 *tptr=currfun->ret_type;
	    return currfun->children[i]->arglist;	   	
	   }
   }
   // check for siblings defined before
   i=currfun->parent->no_of_children;  found=0;
   fptr=currfun->parent->children[0];
   while(--i && !found)
   {  if(mystrcmp(fptr->fname,currfun->fname)==0)
	   found=1;
      else {
	      if(mystrcmp(fptr->fname,name)==0)
	      { *proclevel=currfun->level;
		 *no_of_arg=fptr->no_of_arg;     
	*is_func=(currfun->ret_type!=NULL);
	 *tptr=currfun->ret_type;
		 return fptr->arglist;     
	      }
   	}	      
   }
   return NULL;
}
Exemple #13
0
int Deletetable(char* filename,char (*tableindex)[TABLE_NAME_MAX],Column** columnindex,Data*** database)
{
	over=start=0;
	start=clock();
	FILE* file = fopen(filename,"r+");
	if(NULL == file)
	{
		printf("Error in opening the command file!\n");
		return 0;
	}
	char buffer[COLUMN_NAME_MAX];
	char* command=getwords(file,buffer);
	//Check Key word Delete
	if(mystrcmp("delete",command)) 
	{
		printf("The file should be included the keyword update!\n");
		return 0;
	}
	command=getwords(file,buffer); //Reading  from
	if(mystrcmp("from",buffer)) 
	{
		printf("The file should be included the keyword from!\n");
		return 0;
	}
	//Reading table name 
	command=getwords(file,buffer);
	int tableoperate = tablenow(buffer,tableindex);  //The order of opertating table
	if(tableoperate==-1) 
	{
		printf("Can't Locate the table!\n");
		return 0;
	}

	int andor[AND_OR_MAX]; //  and or ARRAY   or=0 and=1    -1 is the end  
	int likeequal[LIKE_EQUAL_MAX]; //like  = Array   -1 is the end   0=like 1 = =  
	char colvalue[COL_READ_MAX][COLUMN_NAME_MAX];   //Recieve every column value
	int colname_do[COL_READ_MAX];  //Order of column to delete  
	int col_delete=0;
	checkline2(file,andor,likeequal,colvalue,colname_do,tableoperate,columnindex); //Reading the last line
	fclose(file);  //close file
	int* index = CreateIndex(tableoperate,colname_do,0,likeequal,colvalue,andor,columnindex,database) ; //Create Searching Index
	int loriginal = columnindex[tableoperate][0].length;  //Reading data length of the original one
	Data** head = deleteatable(columnindex,database,tableoperate,index);
	int count=fprintalltable(columnindex[tableoperate],head,tableoperate,"074090_delete.txt");  //write to the file
	free(index);
	return loriginal-count;
}
Exemple #14
0
RTT_TEST_END

RTT_TEST_START(rtu32tostr_should_print_in_base_8)
{
    char buf[32];
    RTT_EXPECT(RTU32ToString(03673451u, RTBASE_8, buf, sizeof(buf)) == 7);
    RTT_EXPECT(mystrcmp(buf, "3673451") == 0);
}
Exemple #15
0
RTT_TEST_END

RTT_TEST_START(rtu32tostr_should_print_in_base_16)
{
    char buf[32];
    RTT_EXPECT(RTU32ToString(0xdeadbeefU, RTBASE_16, buf, sizeof(buf)) == 8);
    RTT_EXPECT(mystrcmp(buf, "deadbeef") == 0);
}
Exemple #16
0
RTT_TEST_END

RTT_TEST_START(rt32tostr_should_print_negative_i32)
{
    char buf[32];
    RTT_EXPECT(RT32ToString(-756123, buf, sizeof(buf)) == 7);
    RTT_EXPECT(mystrcmp(buf, "-756123") == 0);
}
Exemple #17
0
int main(void) {
  char *str1 = "Stro311";
  char *str2 = "Stro31112312";
  int res1 = mystrcmp(str1, str2);
  int res2 = strcmp(str1, str2);
  printf("%d\n%d\n", res1, res2);
  return 0;
}
Exemple #18
0
RTT_TEST_END

RTT_TEST_START(rtu32tostr_should_print_in_base_auto)
{
    char buf[32];
    RTT_EXPECT(RTU32ToString(1074893997, RTBASE_AUTO, buf, sizeof(buf)) == 10);
    RTT_EXPECT(mystrcmp(buf, "1074893997") == 0);
}
Exemple #19
0
int main(int c, char **v)
{
    if (c != 3)
        return -1;

    printf("%d\n", mystrcmp(v[1], v[2]));

    return 0;
}
static int is_irt_interface_whitelisted(const char *interface_name) {
  int i;
  for (i = 0; i < NACL_ARRAY_SIZE(irt_interface_whitelist); i++) {
    if (mystrcmp(interface_name, irt_interface_whitelist[i]) == 0) {
      return 1;
    }
  }
  return 0;
}
Exemple #21
0
void process_client_command(char recieved[MAX_STR_SIZE],char * data ){
	int recieved_tokens_num;
	char recieved_tokens[MAX_ARRAY_SIZE][MAX_STR_SIZE];
	tokenizer(recieved, " ", &recieved_tokens_num, recieved_tokens);
	if(mystrcmp( recieved_tokens[0],"Selected" )==0 ){
		strcat(data,recieved_tokens[1]);
		printf("server data is:%s\n",data );
	}

}
Exemple #22
0
int isUnique(BinSTreeNode* node) {
  BinSTreeNode* parent = node->parent;
  while(parent != NULL) {  /* look until root node */
    if (!mystrcmp(node->str, parent->str)) {  /* found a node which has the same name */
      return false;
    }
    parent = parent->parent;
  }
  return true;
}
Exemple #23
0
RTT_TEST_END

RTT_TEST_START(rtu32tostr_should_print_in_base_2)
{
    char buf[34];
    const char* expected = "11001010111111101101111011001010";
                         /* ccccaaaaffffeeeeddddeeeeccccaaaa */

    RTT_EXPECT(RTU32ToString(0xcafedecaU, RTBASE_2, buf, sizeof(buf)) == 32);
    RTT_EXPECT(mystrcmp(buf, expected) == 0);
}
Exemple #24
0
TpCheckIsStdFunc(char *name)
{   char *ptr; int i=0;
    for(i=0;i<30;i++)
    {  ptr=std_func_list[i];
	if(mystrcmp(ptr,name)==0)
	{	printf("\n stdfunc case %d found",i); getchar();
		return 1;
	}
    }	   
   return 0; 
}
int main()
{
    char s[10] = {mascarpon};
    char t[10] = {mascert};

    int l = mystrcmp(s,t,3);

    printf("valore %d" ,l);

    return 0;
}
Exemple #26
0
int columnnow(char* name,int tableoperate , Column** columnindex) //return the order of the column with the name 
{
	int count=0;
	while(columnindex[tableoperate][count].name[0]!='\0')
	{
		if(mystrcmp(columnindex[tableoperate][count].name,name) == 0)
			return count;
		count++;
	}
	return -1;
}
int mystrcmp(char * s1, char * s2) {
	if (*s1 < *s2)
        return -1;
 
    if (*s1 > *s2)
        return 1;
 
    if (*s1 == '\0')
        return 0;
 
    return mystrcmp(s1 + 1, s2 + 1);
}
int sysFind(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
{
	if ((j<0)||(j+len>lsrc)) return NIL;
	src+=j;
	if (i<0) i=0;
	while(i+len<=ldst)
	{
		if (!mystrcmp(dst+i,src,len)) return INTTOVAL(i);
		i++;
	}
	return NIL;
}
int sysFindrev(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
{
	if ((j<0)||(j+len>lsrc)) return NIL;
	src+=j;
	if(i+len>ldst) i=ldst-len;
	while(i>=0)
	{
		if (!mystrcmp(dst+i,src,len)) return INTTOVAL(i);
		i--;
	}
	return NIL;
}
Exemple #30
0
str
suffix_sub (const char *s, const char *sfx1, const char *sfx2)
{
  if (!s)
    return NULL;
  int len0, len1;
  len0 = strlen (s);
  len1 = strlen (sfx1);
  if (len0 < len1 || !mystrcmp (s + len0 - len1, sfx1))
    return NULL;
  return (strbuf (str (s, len0 - len1)) << sfx2);
}