Example #1
0
int do_wri(u8 * file){
	s8 ret,fd;
	u32 retlba ;
	u8 i=0;
	u32 ch;
	u8 buff[256] = {0};
	if (!check_for_args(WRI,1))return 1;
	fd = openf(file,O_RW);
	if ( fd == -1){
		retlba=NO_LBA;
		if (ERROR_NO == NO_DIR_FILE)
			retlba  = creatf(file , 064);
		if (retlba  == NO_LBA){
			vd_puts ( "COULD NOT OPEN OR CREATE THE DESTINATION FILE\n" );
				errormessage(geterror());
			closef(fd);
			fl_clean();
			return 0;
		}
		fd = openf(file,O_RW);
	}
	if(fd == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
		errormessage(geterror());
		fl_clean();
		return 1;
	}
	while(1){
		ch=getche();
		if(ch == 1)
			break;
        if( ch == 13 || ch == 10){printf("\n"); ch = '\n';}
		if (i == 255){
			i=0;
			ret = writef(fd,buff,256);
			if(ret == -1){
				vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
				errormessage(geterror());
				unlinkf(file);
				fl_clean();
				return 1;
			}
		}
		buff[i++] = ch;
	}
	ret = writef(fd,buff,i);
	if(ret == -1){
		vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
		errormessage(geterror());
		unlinkf(file);
		fl_clean();
		return 1;
	}
	closef(fd);
	vd_puts(" \n");
	fl_clean();
	return 0;
}
Example #2
0
void DDS_Security_log (unsigned   log_level,
		       const char *message,
		       const char *category)
{
	struct timeval	tv;
	FILE		*f;
	struct tm	tm_data, *tm;
	char		tmbuf [40];
	DDS_LogInfo	log_info;

	if (!log_options_set || log_level < log_options.log_level)
		return;

	if (!log_options.log_file && !log_options.distribute) {
		log_printf (SEC_ID, log_level, "%s: %s\r\n", category, message);
		return;
	}
	if (log_options.log_file) {
		if (openf (f, logname, "a")) {
			gettimeofday (&tv, NULL);
#ifdef _WIN32
			_localtime32_s (&tm_data, &tv.tv_sec);
			tm = &tm_data;
#else
			tm = localtime_r (&tv.tv_sec, &tm_data);
			if (!tm) {
#ifdef LOG_DATE
				fprintf (f, "\?\?\?\?-\?\?\?-\?\? ");
#endif
				fprintf (f, "\?\?:\?\?:\?\?.\?\?\? ");
			}
			else
#endif
			{
				tmbuf [0] = '\0';
#ifdef LOG_DATE
				strftime (tmbuf, sizeof (tmbuf), "%Y-%m-%d ", tm);
#endif
				strftime (&tmbuf [strlen (tmbuf)],
						sizeof (tmbuf) - strlen (tmbuf),
						"%H:%M:%S.", tm);
				snprintf (&tmbuf [strlen (tmbuf)],
					  sizeof (tmbuf) - strlen (tmbuf),
					  "%03lu ", (unsigned long) tv.tv_usec / 1000);
				fprintf (f, "%s", tmbuf);
			}
			fprintf (f, "%s: %s\r\n", category, message);
			fclose (f);
		}
	}
	if (log_options.distribute && log_writer) {
		log_info.log_level = log_level;
		log_info.message = (char *) message;
		log_info.category = (char *) category;
		DDS_DataWriter_write (log_writer, &log_info, 0);
	}
}
Example #3
0
int
open(const char* fn, int flags, ...)
{
  va_list aq;
  va_start(aq, flags);
  fprintf(stderr, "[%d] opening %s ...", (int)getpid(), fn);
  int des = openf(fn, flags, aq);
  fprintf(stderr, " -> %d\n", des);
  va_end(aq);
  return des;
}
Example #4
0
int do_app(u8 * file){
	s8 ret,fd;
	u8 i=0;
	u32 ch;
	u8 buff[256];
	struct fnode fn;
	u32 size;
	if (!check_for_args(APP,1)) return 1;
	fd = openf(file,O_RW);
	if(fd == -1){
		vd_puts( "CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	finfo(fd, & fn);
	size = fn.size;
	ret= seekf(fd,  size,SEEK_BEG);
	while(1){
		ch=getche();
		if(ch == 1)
			break;
        if (ch == 13 || ch == 10 ){
            printf("\n");ch='\n';
        }
		if (i == 255){
			i=0;
			ret = writef(fd,buff,256);
			if(ret == -1){
				vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
                errormessage(geterror());
				unlinkf(file);
                fl_clean();
				return 1;
			}
		}
		buff[i++] = (u8)ch;
	}
	ret = writef(fd,buff,i);
	if(ret == -1){
		vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n");
				errormessage(geterror());
		unlinkf(file);
				fl_clean();
		return 1;
	}
    puts(" ");
	closef(fd);
		fl_clean();
	return 0;

}
Example #5
0
int
matchfile(Resub *match)
{
	if(match[1].sp) {
		int len = match[1].ep - match[1].sp;

		strncpy(name, match[1].sp, len);
		strcpy(name+len, suffix);
		openf();
		return 1;
	} 
	return nextfile();
}
Example #6
0
int
open(const char* fn, int flags, ...)
{
  mode_t mode = S_IRUSR | S_IWUSR;
  if(flags & O_CREAT) {
    va_list lst;
    va_start(lst, flags);
    mode = va_arg(lst, mode_t);
    va_end(lst);
  }
  if(!matches(transferlibs, fn) || flags & O_RDONLY ||
     strncmp(fn, "/tmp", 4) == 0 ||
     strncmp(fn, "/dev", 4) == 0) {
    TRACE(posix, "%s opened, but ignored by policy.", fn);
    const int des = openf(fn, flags, mode);
    return des;
  }
  const int des = openf(fn, flags, mode);
  if(des <= 0) { /* open failed; ignoring this file. */
    TRACE(posix, "posix-opening %s ignored due to open failure", fn);
    return des;
  } else {
    TRACE(posix, "posix-opening %s...", fn);
  }

  /* need an empty entry in the table to store the return value. */
  int empty = 0;
  struct openposixfile* of = ofposix_find(posix_files, fd_of, &empty);
  if(of == NULL) {
    WARN(posix, "out of open files.  skipping '%s'", fn);
    return des;
  }
  assert(of->name == NULL);
  of->name = strdup(fn);
  of->fd = des;
  file(transferlibs, fn);
  return des;
}
 void write_asm(Syntax* complete_syntax,Stack* string_stack){
	 tablevar = list_new();
	openf("output.s"); //open file.
	emit_format();
	emit_str(string_stack);
	emit_header();	//print .text
	function_declare("main"); //declare .globl main
	emit_init(); //alloc for main.
	if(complete_syntax->type == BLOCK){
		emitblock(complete_syntax);
	}else
		printf("invalid syntax");
	emit_footer(); //ralloc for main
	closef(fp); //close file.
	free(tablevar);
}
Example #8
0
int
nextfile(void)
{
	static int canopen = 1;

	if(suff[0] > 'z') {
		if(canopen)
			fprint(2, "split: file %szz not split\n",stem);
		canopen = 0;
	} else {
		snprint(name, sizeof name, "%s%s", stem, suff);
		if(++suff[1] > 'z') 
			suff[1] = 'a', ++suff[0];
		openf();
	}
	return canopen;
}
Example #9
0
int do_show(u8 * file){
	s8 fd, ret ; u32 i ;
	struct fnode fn;
	u32 size;
	u8 buff[1025];

	if (!check_for_args(SHOW,1)) return 1;
	fd=openf(file,O_READ);
	if ( fd == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}

	ret = finfo(fd,&fn);
	if ( ret == -1){
		vd_puts("CANNOT OPEN THE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	size=fn.size;
	while(size){
		ret = readf(fd,buff,(size < 1024 ? size : 1024));
		if ( ret == -1){
			vd_puts("CANNOT  READ THE FILE\n");
					errormessage(geterror());
					fl_clean();
			return 1;
		}
		buff[(size < 1024 ? size : 1024)]=0 ;
		for(i = 0 ; i < (size < 1024 ? size : 1024) ; ++i )
			if ( buff[i] == 10 || buff[i] == 13) buff[i] = '\n';
		vd_puts( buff);
		vd_puts("\n");
		if (size >= 1024)
		    size-=1024 ;
		else
			size=0;
	}
	closef(fd);
	fl_clean();
	return 0;
}
Example #10
0
int main(){
        int m,n;
        int bs;

        a=(int*)malloc(0*sizeof(int));

        printf("How many threads?!\n");
        scanf("%d",&m);

        l=m;

        bs=openf(a);

        thwork(m);

        madef(lev,bs);

        return 0;
}
Example #11
0
int main(int argc, char *argv[]){
	if(argc!=2){
		printf("usage: prog joblibst\n");	
		printf("Run jobs with definite num. of seconds since run useless\n");
		return EARG;
	}
	FILE *f;
	openf(f,argv[1],"r");
	int sec;
 	char * comm = NULL;
	size_t len = 0;
	while(fscanf(f,"%d ",&sec)==1){
		getline(&comm, &len, f);
		add_job(comm,sec);
	}
	fclose(f);
	qsort(jobs,cnt,sizeof(joblist),cmp); 
	print_job();
	exec_job();
	return SUCC;
}
Example #12
0
int topline (char *group, char *fn, char *buf, int size)
{
   int fd, i;
   char *cp;

   if (NULL == group)
      fd = open(fn, O_RDONLY);
   else
      fd = openf(0, O_RDONLY, "%s/%s", group, fn);
   if (-1 == fd)
      return -1;
   i = read(fd, buf, size - 1);
   close(fd);
   if (i <= 0)
      return i;
   buf[i] = '\0';
   if ((cp = strchr(buf, '\n')))
   {
      *cp = '\0';
      return (cp - buf);
   }
   return i;
}
Example #13
0
int do_cp(u8 * src , u8 * dst){
	s8 sfd,dfd,ret ;
		u32 retlba;
	struct fnode fn;
	u32 size;
	u8 buff[1024];
	if (!check_for_args(CP,2)) return 1;
	sfd=openf(src,O_READ);
	if ( sfd == -1){
		vd_puts("COULD NOT OPEN SOURCE FILE\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	dfd = openf(dst, O_RW);
	if ( dfd == -1){
		retlba  = creatf(dst , 064);
		if (retlba  == NO_LBA){
			vd_puts("COULD NOT OPEN  OR CREATE THE DESTINATION FILE\n");
						errormessage(geterror());
						fl_clean();
					return 0;
			   }
		   dfd = openf(dst,O_RW);
	}

	ret = finfo(sfd, &fn);
	if (ret == -1){
		vd_puts("HAD PROBLEMS WITH GETTING INFO  OF SOURCE FILE\n");
				 errormessage(geterror());
		closef(sfd);
		closef(dfd);
				fl_clean();
		return 1;
	}
	size = fn.size;
		while (size ){
			ret = readf(sfd  , buff,  (size < 1024  ?  size  :  1024));
			if ( ret == -1){
				vd_puts("ERRROR OCCURED IN READING SOURCE FILE\n");
						errormessage(geterror());
				closef(sfd);
				closef(dfd);
						fl_clean();
				return 1;
			}
			ret = writef(dfd, buff , (size < 1024  ?  size  :  1024));
			if (ret == -1){
				vd_puts("ERROR IN WRITE  DELETING THE FILE\n");
					   errormessage(geterror());
				closef(sfd);
				closef(dfd);
				unlinkf(dst);
						 fl_clean();
				return 1;
			}
				if (size >= 1024){
						size-=1024;
				}else
						size=0;

		}
		fl_clean();
	return 0;
}