Exemple #1
0
uint16_t event_manager::create_log_event(event_record_t *rec) {

    std::ostringstream buffer;
    ofstream myfile;
    logheader_t hdr = {0};

    buffer << eventpath << "/" << int(rec->logid) ;

    hdr.eyecatcher     = g_eyecatcher;
    hdr.version        = g_version;
    hdr.logid          = rec->logid;
    hdr.timestamp      = rec->timestamp;
    hdr.detailsoffset  = offsetof(logheader_t, messagelen);
    hdr.messagelen     = getlen(rec->message);
    hdr.severitylen    = getlen(rec->severity);
    hdr.associationlen = getlen(rec->association);
    hdr.reportedbylen  = getlen(rec->reportedby);
    hdr.debugdatalen   = rec->n;

    myfile.open(buffer.str() , ios::out|ios::binary);
    myfile.write((char*) &hdr, sizeof(hdr));
    myfile.write((char*) rec->message, hdr.messagelen);
    myfile.write((char*) rec->severity, hdr.severitylen);
    myfile.write((char*) rec->association, hdr.associationlen);
    myfile.write((char*) rec->reportedby, hdr.reportedbylen);
    myfile.write((char*) rec->p, hdr.debugdatalen);
    myfile.close();

    logcount++;

    return rec->logid;
}
Exemple #2
0
int MMapBuf::add(const void *data, int len) 
{ 
  if (len <= 0) return 0;
  resize(getlen() + len);
  memcpy((char*)get(getlen() - len, len), data, len);
  return getlen() - len;
}
Exemple #3
0
int loadFDI(Floppy* flp,const char* name) {
	std::ifstream file(name,std::ios::binary);
	if (!file.good()) return ERR_CANT_OPEN;

	unsigned char* buf = new unsigned char[14];
	Sector sct;
	Sector trkimg[256];
	int i,j,scnt;
	unsigned char fcnt,tmp;
	unsigned short tmpa,tmpb,slen;
	size_t tmpd,tmph,tmpt,tmps,cpos;

	file.read((char*)buf,14);
	if (strncmp((const char*)buf,"FDI",3) != 0) return ERR_FDI_SIGN;
	bool err = (buf[3] != 0);
	tmpa = buf[4] + (buf[5] << 8);		// cylinders
	tmpb = buf[6] + (buf[7] << 8);		// heads
	if ((tmpb != 1) && (tmpb != 2)) return ERR_FDI_HEAD;
	tmpd = buf[10] + (buf[11] << 8);	// sectors data pos
	tmph = buf[12] + (buf[13] << 8) + 14;	// track headers data pos
	file.seekg(tmph);				// read tracks data
	for (i = 0; i < tmpa; i++) {
		for (j = 0; j < tmpb; j++) {
//			trkimg.clear();
			tmpt = tmpd + getlen(&file,4);
			file.seekg(2,std::ios_base::cur);		// skip 2 bytes
			tmp = file.get();			// sectors in disk;
			for (scnt=0; scnt < tmp; scnt++) {
				sct.cyl = file.get();
				sct.side = file.get();
				sct.sec = file.get();
				sct.len = file.get();
				fcnt = file.get();				// flag
				sct.type = (fcnt & 0x80) ? 0xf8 : 0xfb;
				tmps = tmpt + getlen(&file,2);
				cpos = file.tellg();			// remember current pos
				file.seekg(tmps);
				slen = (128 << sct.len);		// sector len
				sct.data = new unsigned char[slen];
				file.read((char*)sct.data,slen);	// read sector data
				file.seekg(cpos);
				trkimg[scnt] = sct;
				//trkimg.push_back(sct);
			}
			flpFormTrack(flp, (i << 1) + j, trkimg, tmp);
		}
	}
	flp->flag &= ~FLP_PROTECT;
	if (err) flp->flag |= FLP_PROTECT;
	flp->flag |= FLP_INSERT;
	loadBoot(flp);
	flp->flag &= ~FLP_CHANGED;
	flp->path = (char*)realloc(flp->path,sizeof(char) * (strlen(name) + 1));
	strcpy(flp->path,name);

	return ERR_OK;
}
Exemple #4
0
uint16_t event_manager::create_log_event(event_record_t *rec)
{
	std::ostringstream buffer;
	ofstream myfile;
	logheader_t hdr = {0};
	size_t event_size=0;

	buffer << eventpath << "/" << int(rec->logid) ;

	hdr.eyecatcher     = g_eyecatcher;
	hdr.version        = g_version;
	hdr.logid          = rec->logid;
	hdr.timestamp      = rec->timestamp;
	hdr.detailsoffset  = offsetof(logheader_t, messagelen);
	hdr.messagelen     = getlen(rec->message);
	hdr.severitylen    = getlen(rec->severity);
	hdr.associationlen = getlen(rec->association);
	hdr.reportedbylen  = getlen(rec->reportedby);
	hdr.debugdatalen   = rec->n;

	event_size = sizeof(logheader_t) + \
			hdr.messagelen     + \
			hdr.severitylen    + \
			hdr.associationlen + \
			hdr.reportedbylen  + \
			hdr.debugdatalen;

	if((event_size + currentsize)  >= maxsize) {
		syslog(LOG_ERR, "event logger reached maximum capacity, event not logged");
		rec->logid = 0;

	} else if (logcount >= maxlogs) {
		syslog(LOG_ERR, "event logger reached maximum log events, event not logged");
		rec->logid = 0;

	} else {
		currentsize += event_size;
		myfile.open(buffer.str() , ios::out|ios::binary);
		myfile.write((char*) &hdr, sizeof(hdr));
		myfile.write((char*) rec->message, hdr.messagelen);
		myfile.write((char*) rec->severity, hdr.severitylen);
		myfile.write((char*) rec->association, hdr.associationlen);
		myfile.write((char*) rec->reportedby, hdr.reportedbylen);
		myfile.write((char*) rec->p, hdr.debugdatalen);
		myfile.close();

		if (is_logid_a_log(rec->logid)) {
			logcount++;
		} else {
			cout << "Warning: Event not logged, failed to store data" << endl;
			rec->logid = 0;
		}
	}

	return rec->logid;
}
Exemple #5
0
bool streq(const char* buff1, const char* buff2){
  int len1 = getlen(buff1);
  int len2 = getlen(buff2);
  if (len1 != len2){
    return false;
  }
  for (int i = 0; i < len1; ++i){
    if (buff1[i] != buff2[i]){
      return false;
    }
  }
  return true;
}
Exemple #6
0
char		*ft_itoa(int n)
{
	char	*str;
	int		i;
	int		len;

	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	len = getlen(n);
	i = len - 1;
	str = malloc(sizeof(char) * (len + 1));
	if (str == NULL)
		return (NULL);
	if (n < 0)
	{
		n = -n;
		str[0] = '-';
	}
	while (n >= 10)
	{
		str[i--] = n % 10 + '0';
		n = n / 10;
	}
	str[i] = n + '0';
	str[len] = '\0';
	return (str);
}
Exemple #7
0
char		*ft_strtrim(char const *s)
{
	char	*ret;
	int		size;
	int		startindex;
	int		i;

	i = 0;
	if (!s)
		return (NULL);
	size = getlen(s);
	ret = (char*)malloc(sizeof(char) * (size + 1));
	if (size == (int)ft_strlen(s))
		return (ft_strcpy(ret, s));
	if (!ret || !s)
		return (NULL);
	while (s[i] == ' ' || s[i] == '\t' || s[i] == '\n')
		i++;
	startindex = i;
	while (i - startindex < size)
	{
		ret[i - startindex] = s[i];
		i++;
	}
	ret[i - startindex] = '\0';
	return (ret);
}
Exemple #8
0
int main(int argc, char** argv) {
  int num;
  scanf("%d",&num);
  while(num--){
    int n;
    scanf("%d", &n);
    float* a = (float*)malloc(sizeof(float)*n);
    int idx = n - 1;
    while(idx>=0){
      scanf("%f",&a[idx]);
      idx--;
    }
    int i,j;
    float sum = 0.0;
    for(i=0;i<n;i++){
      for(j=n-1;j>i;j--){
        if(a[j] > a[j-1]){
          swap(a+j,a+j-1);
        }
      }
      sum+=getlen(a[i]);
      //printf("%f:%f\n", sum,a[i]);
      if(sum>20.0){
        printf("%d\n", i+1);
        break;
      }
    }
    free(a);
  }
  return 0;
}
Exemple #9
0
static int
put1(void)
{
	/* len1 = length of left side */
	/* nchars = num of chars including tabs */

	char	*bp;


	if ((bp = fgetline(fdes1)) != NULL) {
		len1 = getlen(0, bp);
		if ((!silent || change != ' ') && len1 != 0)
			putline(stdout, bp, nchars);

		if (oflag) {
		/*
		 * put left side either to output file
		 * if identical to right
		 * or left temp file if not
		 */

			if (change == ' ')
				putline(odes, bp, strlen(bp));
			else
				putline(left, bp, strlen(bp));
		}
		if (change != ' ')
			putmid(1);
		num1++;
		return (1);
	} else
		return (0);
}
Exemple #10
0
int main() {

	const long fileHandle = open(".");
	if (fileHandle == -1006) {
		puts("ls: .: access denied\n");
		return 0;	
	}
	else if(fileHandle < 0)	{
		puts("ls failed\n");
		return 0;
	}


	const long fileLength = getlen(fileHandle);
	for(int a = 0; a < fileLength; a += 16)
	{
		char fileName[16];
		read(fileHandle, fileName, 16);
		fileName[12] = 0;
		if (fileName[0] != '.') {
			puts(fileName);
			puts("\n");		
		}
	}
    return 0;
}
Exemple #11
0
void cpy_stack(char* des, char* scr) {
   strcpy(des, scr);
   int len = strlen(scr);
   int c = getlen(scr);
   for(int i = len; i < c; i++) {
      des[i] = '\0';
   }
}
Exemple #12
0
int strindex(char s[], char t[]) {
    int rindex_s, len_t, rindex_t, lindex_s;
    int rcmp_s, lcmp_s, lcmp_t, rcmp_t;
    len_t = getlen(t);
    rindex_t = len_t - 1;
    for (rindex_s = getlen(s) - 1; rindex_s > 0; rindex_s--) {
        lindex_s = rindex_s - len_t;
        if (lindex_s < 0)
            return -1;
        for (lcmp_t = 0, lcmp_s = lindex_s; lcmp_t < len_t && s[lcmp_s] == t[lcmp_t]; lcmp_s++, lcmp_t++);
        if (lcmp_t == len_t)
            return lindex_s;
        
    }
    return -1;
    
}
Exemple #13
0
int
main(int argc, char *argv[])
{
        char           *line;
        double          sumlen = 0;
        int             debug = 0;
        char            delim = '\n';
        char            opt;

        while ((opt = getopt(argc, argv, "d0h")) != -1) {
                switch (opt) {
                case 'd':
                        debug = 1;
                        break;
                case '0':
                        delim = '\0';
                        break;
                case 'h':
                        usage();
                        return (EX_OK);
                default:
                        usage();
                        return (EX_USAGE);
                }
        }

        if ((line = malloc(LINELEN)) == NULL)
                err(EX_SOFTWARE, "malloc(%d)", LINELEN);

        while (fgets(line, LINELEN, stdin) != NULL) {
                char           *p;
                double          l;

                if ((p = strchr(line, (int)'\n')) != NULL)
                        *p = '\0';

                if (getlen(line, &l) == -1)
			continue;

                if (debug)
                        fprintf(stderr, "%s: %s: %f total: %f max: %d\n",
                                getprogname(), line, l, sumlen + l, MAXLEN);

                if ((sumlen += l) > MAXLEN)
                        break;

		fputs(line, stdout);
		putchar(delim);
        }
        if (ferror(stdin))
                errx(EX_SOFTWARE, "gets");

        free(line);

        return (EX_OK);
}
Exemple #14
0
int scpy(char *src, char *dst, int dsize){
  int count = getlen(src);
  if (count >= dsize){
    count = dsize-1;
  }
  dst[count] = '\0';
  for (int i=0; i < count; ++i){
    dst[i] = src[i];
  }
  return count;
}
int target(int fd, const char *s) {
  char buffer[10];
  int bs = read(fd, buffer, 5);
  if(bs < 0) {
    int l = getlen(s);
    reportError(buffer, l);
    return -30;
  }

  return bs + 6;
}
 int longestConsecutive(vector<int> &num) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     int len = num.size();
     if(!len)
         return 0;
     map<int, bool> vm;
     for(int i = 0; i < len; i++)
     {
         vm.insert(pair<int, bool>(num[i], true));
     }
     int maxl = 0;
     for(int i = 0; i < len; i++)
     {
         map<int, bool>::iterator iter = vm.find(num[i]);
         if(iter == vm.end())
             continue;
         int cur = 1 + getlen(vm, iter->first-1, false) + getlen(vm ,iter->first+1, true);
         maxl = max(maxl, cur);
     }
     return maxl;
 }
int main()
{
	int len;
	int ll;
	int res;
	int flag;

	scanf("%d", &len);
	getchar();
	gets(str);

	res = 0;
	flag = 0;
	ll = 0;
	result = strtok(str, delims);

	while(result != NULL)
	{
		if (getlen(result) + 1 > len)
			flag = 1;
		if (ll + strlen(result) + 1 > len)
		{
			res++;
			ll = getlen(result) + 1;
		}
		else
			ll += strlen(result) + 1;
        result = strtok(NULL, delims);
    }
	res++;

	if (flag)
		printf("Impossible\n");
	else
		printf("%d\n", res);
	return 0;
}
Exemple #18
0
int main() {
    long fd = open(".");
    if (fd < 0) {
        exit(fd);
    }
    long n = getlen(fd) / 16;
    for (long i = 0; i<n; i++) {
        char buf[13];
        seek(fd,i*16);
        readFully(fd,buf,12); 
        buf[12] = 0;
        puts(buf);
        puts("\n");
    }
    return 0;
}
Exemple #19
0
UnZip::UnZip(const unsigned short* pPkgPath)
{
	itemNum = 0;
	unpackSize = 0;
	cur_entry.Index = (DWORD)-1;	
	huz = NULL;

	UnzipOpenFile(&huz, pPkgPath, NULL);		
	char* pkgdir_char = UnzipGetRootDir(huz);
	pkgDir = pkgdir_char;
    dirLen = getlen(pkgdir_char);
	ZIPENTRY ze;
	ze.Index = (DWORD)-1;
	UnzipGetItem(huz, &ze);
	itemNum = ze.Index;
	getTotalFilesSize();
}
Exemple #20
0
int main(int argc, char** argv) {
	if(argc <= 1)return 0;
	for(int i=1; i<argc; i++){
		long id = open(argv[i]);
		if(id < 0){
			puts(argv[0]);
			puts(": ");
			puts(argv[i]);
			puts(": No such file or directory\n");
		}
		long len = getlen(id);
		char* buf = (char*)malloc(len + 1);
		readFully(id, (void*)buf, len);
		buf[len] = 0;
		puts(buf);
	}
	return 0;
}
Exemple #21
0
int convertstr(char s[])
{
	int len = getlen(s);
	int i, j;

	if(s[len - 1] == '\0' || s[len - 1] == '\n')
		len--;

	for(i = 0, j = len - 1; i != j; i++, j--)
	{
		char tmp;
		tmp = s[i];
		s[i] = s[j];
		s[j] = tmp;
	}

	return 0;
}
Exemple #22
0
int main() {
    puts("INSIDE LS\n");
    long fd = open(".");
    long len = getlen(fd);
    char* buff = malloc(len);
    read(fd,buff,len);

    int i = 0;
    while(i < len){
      puts(buff+i);
      puts("\n");
      i += 16;
    }

    free(buff);

    return 0;
}
Exemple #23
0
static int
put2(void)
{
	char	*bp;

	if ((bp = fgetline(fdes2)) != NULL) {
		(void) getlen((hlen + WGUTTER) % 8, bp);

		/*
		 * if the left and right are different they are always
		 * printed.
		 * If the left and right are identical
		 * right is only printed if leftonly is not specified
		 * or silent mode is not specified
		 * or the right contains other than white space (len1 !=0)
		 */
		if (change != ' ') {

		/*
		 * put right side to right temp file only
		 * because left side was written to output for
		 * identical lines
		 */

			if (oflag)
				putline(right, bp, strlen(bp));

			if (midflg == 0)
				putmid(1);
			putline(stdout, bp, nchars);
		} else
			if (!silent && !leftonly && len1 != 0) {
				if (midflg == 0)
					putmid(1);
				putline(stdout, bp, nchars);
			}
		num2++;
		len1 = 0;
		return (1);
	} else {
		len1 = 0;
		return (0);
	}
}
Exemple #24
0
int* plusOne(int* A, int n1, int *length_of_array) {

        /*
         * *length_of_array = n1 + 1; // length of result array
         * int *result = (int *) malloc(*length_of_array * sizeof(int));
         * // DO STUFF HERE. NOTE : length_of_array can be n1 OR n1 + 1.
         * return result;
         */

         int indx=0;
         int len = n1;
         int *result;
         unsigned  long long sum =0;
         int i=1;
         int leading_zero = A[0];
         int newlen=0;

         for(indx =0; indx <len; indx++)
         {
            if(!leading_zero){

              leading_zero = (A[indx+1]!=0)?1:0;
              printf("leading_zero val = %d\n",leading_zero);
              continue;
            }
             sum = A[indx]+ sum*i;
             printf("index=%d sum=%llu\n",indx,sum);
            i= 10;
         }
         printf("original nubmer = %llu\n",sum);
         sum = sum+1;
         newlen = getlen(sum);
         printf("Newlen=%d\n",newlen);
         result = (int*)malloc(sizeof(int)*newlen);
         for(i=newlen-1; i>=0;i--)
         {
           result[i]=sum%10;
           printf("result[%d]=%d",i,result[i]);
           sum = sum/10;
         }
         *length_of_array = newlen;
         return result;
}
Exemple #25
0
int getprefix(char *s)
{
  int i=0, c;
  
  txtpref[0] = 0;
  while ( (c=*s++) && (i < 199) )
  {
    if ( c == '/' )  break;
    if ( ((c>='0') && (c<='9')) || ((c>='a') && (c<='f')) || ((c>='A') && (c<='F')) || (c==':') )
    {
      txtpref[i++] = c;
      txtpref[i] = 0;
    }
    else
      return 0;
  }
  if (c == '/') getlen(s); else preflen=128;
  return i;
}
Exemple #26
0
int main() {
	
	int len, i;
	char line[MAXLEN];
	
	/* пока вход¤ща¤ строка не пуста¤ ... */
	while((len = getlen(line)) != 0) {
		reverse(line, len);
		i = 0;
		
		/* посимвольно выводим на печать строку дл¤ предотвращени¤ выведени¤ символов предыдущей строки, если она была длиннее текущей */
		while (i < len) {
			printf("%c", line[i]);
			++i;
		}
	printf("\n");
	}
		
	return 0;
}
Exemple #27
0
int split(char* buffer, char** strs, const char delimiter, int maxparts){

    //obtain len
    int len = getlen(buffer);
    int split = 0;
    strs[split] = buffer;
    
    for(int i = 0; i < len; ++i){
      if (buffer[i] == delimiter){
        buffer[i] = '\0';
        if( i + 1 != len){
          ++split;
          strs[split] = &buffer[i+1];
          if(split == maxparts - 1)
            break;
        }
      }
    }
    return split + 1;
}
Exemple #28
0
char* strip(char* buffer){

  //obtain len
  int len = getlen(buffer);
  int i;
  for ( i = len - 1; i >= 0; --i){
    if (space(buffer[i])){
      buffer[i] = '\0';
    }
    else{
      break;
    }
  }
  len = i + 1;
  for (i = 0; i < len; ++i){
    if (!space(buffer[i])){
        break;
    }
   }
  return &buffer[i];
}
Exemple #29
0
int main() {

	const long fileHandle = open(".");
	if(fileHandle < 0)
	{
		puts("didn't work\n");
	}

	const long fileLength = getlen(fileHandle);
	for(int a = 0; a < fileLength; a += 16)
	{
		char fileName[16];
		read(fileHandle, fileName, 16);
		fileName[12] = 0;
		if (fileName[0] != '.') {
			puts(fileName);
			puts("\n");		
		}
	}
    return 0;
}
Exemple #30
0
static void message(int log, const char *prefix, const char *fmt, ...)
{
	char *buf;
	va_list arglist;
	int len;

	va_start(arglist, fmt);
	len = strlen(prefix) + getlen(fmt, arglist) + 1;
	buf = malloc(len);

	/* Must restart args on some archs */
	va_start(arglist, fmt);
	strcpy(buf, prefix);
	vsnprintf(buf + strlen(buf), len, fmt, arglist);

	if (log)
		// modutils-2.4 would buffer these up
		syslog(LOG_INFO, "%s", buf);
	else
		fprintf(stderr, "%s", buf);
}