Example #1
0
int
main(int argc, char *argv[])
{
	getargs(argc, argv);
	getfile();
	if (flags & SHAPEONLY) {
		printf("%d %d\n", irows, icols);
		exit(0);
	}
	prepfile();
	putfile();
	exit(0);
}
Example #2
0
int getID(const char *filename)
{
    char buf1[MAXLINE],buf2[MAXLINE];
    char path1[MAXLINE],path2[MAXLINE],*ptr;
    DIR *db,*directory;
    struct dirent *p;

    db=opendir("/proc/");

    if(db==NULL)
    {
	return -1;
    }

    while ((p=readdir(db)))
    {
	if((strcmp(p->d_name,".")==0)||(strcmp(p->d_name,"..")==0))
	    continue;
	else
	{
	    memset(buf1,0,sizeof(buf1));
	    sprintf(buf1,"/proc/%s",p->d_name);

	    if(isdir(buf1))
	    {
		memset(buf2,0,sizeof(buf2));
		sprintf(buf2,"%s/exe",buf1);
		if(access(buf2,F_OK)==0) // 文件存在 或者是有权限访问
		{
		    memset(path1,0,sizeof(path1));
		    if(readlink(buf2,path1,sizeof(path1))==-1)
			continue;
		    ptr=getfile(path1);

		    if(strcmp(ptr,filename)==0)
		    {
			/* memset(path2,0,sizeof(path2)); */
			/* sprintf(path2,"%s/status",buf1); */
			/* ptr=readstatus(path2); */
			sprintf(buf1,"%s",p->d_name);

			int i;
			i = atoi(buf1);
			return i;
		    }
		}
	    }
	}
    }
    closedir(db);
}
Example #3
0
/******************************************************************************
 * (FSCANF-STRING <stream> <scanf-format>)
 * This routine calls fscanf(3s) on a <stream> that was previously openend
 * via open or popen. It will not work on an USTREAM.
 * <scanf-format> is a format string containing a single conversion
 * directive that will result in a string valued conversion.
 * %s, %c, and %[...] style conversions are acceptable for
 * this routine.
 * WARNING: specifying a <scanf-format> that will result in the conversion
 * of a result larger than 1024 characters will result in corrupted
 * memory and core dumps.
 * 
 * This routine will return a string if fscanf() returns 1 (i.e. if
 * the one expected conversion has succeeded. It will return NIL if the
 * conversion wasn't successful, or if EOF was reached.
 ******************************************************************************/
LVAL Prim_FSCANF_STRING()
{
  LVAL lval_stream;
  char* fmt;
  char result[BUFSIZ];

  
  lval_stream = xlgastream();
  if (getfile(lval_stream) == NULL)
    xlerror("File not opened.", lval_stream);
  fmt = (char *) getstring(xlgastring());
  xllastarg();
  
  result[0] = result[1] = '\0';	/* if the conversion is %c, then fscanf
				   doesn't null terminate the string,
				   so do it just incase */

  /* if scanf returns result <1 then an error or eof occured. */
  if (fscanf(getfile(lval_stream), fmt, result) < 1)
    return (NIL);
  else
    return (cvstring(result));
}
int main(int argc,
	 char *argv[])
{
    bptr = NULL;
    unsigned long exp_num_exts=0;
    unsigned long num_blks=0;
    unsigned short type=0;
    char dir_name[20];
    unsigned int i=0;
 
    long int lret;

    if (argc != 2) {
	fprintf(stdout, "Usage : %s <disk cache directory>\n", argv[0]);
	exit(-1);
    }

    strcpy(dir_name, argv[1]);
    getfile(dir_name);

    num_blks = 0;
    type = 1;
    for (i = 0; i < g_tot_containers; i++) {
	exp_num_exts = (cnptr+i)->num_exts;
        (cnptr+i)->fid=fopen((cnptr+i)->name,"r");
        if((cnptr+i)->fid==NULL) {
            fprintf(stdout,"Unable to open container file %s for reading\n",(cnptr+i)->name);
            exit(-1);
        }
	lret = readContainerFile((cnptr+i)->fid, exp_num_exts, num_blks,
				 (cnptr+i)->uri_prefix, type); 
	if ((lret < 0) && (lret > -9999)) {
	    fprintf(stderr, "Error returned from readContainerFile : %ld\n",
		    lret);
	    exit(-1);
	} else {
	    num_blks = (unsigned long)lret;
	    fprintf(stdout, "Number of blocks = %lu\n", num_blks);
	}
        if((cnptr+i)->fid) {
            fclose((cnptr+i)->fid);
        }
    }
    verifyContainerOverlap(num_blks);

    type = 1;
    //  printContainers(num_blks,type);
    return (0);
}
Example #5
0
int main(int argc, char *argv[]){
      	struct stat buf;
        void *start;
        char *point;
        char *point1;
      	if (argc != 3) {
	        fprintf(stderr, "Error input \n");
	        exit(EXIT_FAILURE);
      	}
       	int imgfile = open(argv[1], O_RDONLY);
        char *filename=argv[2];
       	if (imgfile < 0){
            fprintf(stderr, "Error no such file \n");
	          exit(EXIT_FAILURE);
      	}
        fstat(imgfile, &buf);
        start = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, imgfile, 0);
     
        if(start == MAP_FAILED) 
        return;
        
        point=start;
        point1=start;
        block_size=blocksize(point);
        int rd_s=rds(point);
        int rd_b=rdb(point);
        int n=0;
        ss=block_size*rd_s;
        point=point+block_size*rd_s;
        while(point[0]!=0x00){
        readfile(point);

        n++;
        point=point+64;
        }
      //  printf("%d",n);
        getfile(point1,filename,n);


        

//info end

        munmap(start, buf.st_size);
        close(imgfile);

return 0;

}
Example #6
0
int main (void) {
	struct mmapfile mf = { ptr:NULL, size:0 };
	int i = 0;
	char *ptr, title[64];
	FILE *fp;

	while (sina[i].title) {
		getfile(sina[i].url);
		if (!file_exist(TMPFILE)) {
			i++;
			continue;
		}
		if (NULL == (fp = fopen(POSTFILE, "w")))
			return 0;

		if (mmapfile(TMPFILE, &mf) < 0) {
			i++;
			continue;
		}
		if (mf.size <= 0) {
			i++;
			continue;
		}
		ptr = mf.ptr;
		MMAP_TRY {
			if (NULL == 
				(ptr = weather_date(fp, ptr, 
				 sina[i].title, sina[i].type))) {

				MMAP_UNTRY;
				mmapfile(NULL, &mf);
				continue;
			}
			weather_item(fp, ptr, sina[i].type);
		} MMAP_CATCH {
		} MMAP_END mmapfile(NULL, &mf);
		fclose(fp);
		sprintf(title, "%s城市24小时天气预报(%s)", 
				sina[i].type ? "国际" : "国内", 
				sina[i].title);
		postfile(POSTFILE, "deliver", BOARD, title);
		unlink(TMPFILE);
		unlink(POSTFILE);
		i++;
	}
	return 1;
}
Example #7
0
File: setup.c Project: stqism/DEMOS
setsym()
{
        INT             relflg;
        INT             symval, symflg;
        SYMSLAVE        *symptr;
        SYMPTR          symp;
        TXTHDR          txthdr;

        fsym=getfile(symfil,1);
        txtmap.ufd=fsym;
        IF read(fsym, txthdr, TXTHDRSIZ)==TXTHDRSIZ
        THEN    magic=txthdr[0];
                IF magic!=0411 ANDF magic!=0410 ANDF magic!=0407 ANDF magic!=0405
                THEN    magic=0;
                ELSE    symnum=txthdr[4]/SYMTABSIZ;
                        txtsiz=txthdr[1];
                        datsiz=txthdr[2];
                        symbas=txtsiz+datsiz;
                        txtmap.b1=0;
                        txtmap.e1=(magic==0407?symbas:txtsiz);
                        txtmap.f1 = TXTHDRSIZ;
                        txtmap.b2=datbas=(magic==0410?round(txtsiz,TXTRNDSIZ):0);
                        txtmap.e2=txtmap.b2+(magic==0407?symbas:datsiz);
                        txtmap.f2 = TXTHDRSIZ+(magic==0407?0:txtmap.e1);
                        entrypt=txthdr[5];
                        relflg=txthdr[7];
                        IF relflg!=1 THEN symbas =<< 1; FI
                        symbas += TXTHDRSIZ;

                        /* set up symvec */
                        symvec=sbrk(shorten((1+symnum))*sizeof (SYMSLAVE));
                        IF (symptr=symvec)==-1
                        THEN    printf("%s\n",BADNAM);
                                symptr=symvec=sbrk(sizeof (SYMSLAVE));
                        ELSE    symset();
                                WHILE (symp=symget()) ANDF errflg==0
                                DO  symval=symp->symv; symflg=symp->symf;
                                    symptr->valslave=symval;
                                    symptr->typslave=SYMTYPE(symflg);
                                    symptr++;
                                OD
                        FI
                        symptr->typslave=ESYM;
                FI
        FI
        IF magic==0 THEN txtmap.e1=maxfile; FI
}
Example #8
0
File: cpp3.c Project: cjapes/core
void addfile(FILE* fp, char* filename)
/*
 * Initialize tables for this open file.  This is called from openfile()
 * above (for #include files), and from the entry to cpp to open the main
 * input file.  It calls a common routine, getfile() to build the FILEINFO
 * structure which is used to read characters.  (getfile() is also called
 * to setup a macro replacement.)
 */
{
        register FILEINFO       *file;
        extern FILEINFO         *getfile( int, char * );
        file = getfile(NBUFF, filename);
        file->fp = fp;                  /* Better remember FILE *       */
        file->buffer[0] = EOS;          /* Initialize for first read    */
        line = 1;                       /* Working on line 1 now        */
        wrongline = TRUE;               /* Force out initial #line      */
}
Example #9
0
/* xlgetc - get a character from a file or stream */
int xlgetc(LVAL fptr)
{
    LVAL lptr, cptr=NULL;
    FILE *fp;
    int ch;

    /* check for input from nil */
    if (fptr == NIL)
        ch = EOF;

    /* otherwise, check for input from a stream */
    else if (ustreamp(fptr)) {
        if ((lptr = gethead(fptr)) == NIL)
            ch = EOF;
        else {
            if (!consp(lptr) || (cptr = car(lptr)) == NIL || !charp(cptr))
                xlfail("bad stream");
            sethead(fptr,lptr = cdr(lptr));
            if (lptr == NIL)
                settail(fptr,NIL);
            ch = getchcode(cptr);
        }
    }

    /* otherwise, check for a buffered character */
    else if ((ch = getsavech(fptr)))
        setsavech(fptr,'\0');

    /* otherwise, check for terminal input or file input */
    else {
        fp = getfile(fptr);
        if (fp == stdin || fp == STDERR)
            ch = ostgetc();
        else
            ch = osagetc(fp);
#ifdef DEBUG_INPUT
        if (read_by_xlisp && ch != -1) {
			putc(ch, read_by_xlisp);
		}
#endif
    }

    /* return the character */
    return (ch);
}
Example #10
0
int
copyout(register Ftw_t* ftw)
{
	register Archive_t*	ap = state.out;
	register File_t*	f = &ap->file;

	if (getfile(ap, f, ftw))
	{
		if (selectfile(ap, f))
		{
			f->fd = openin(ap, f);
			deltaout(NiL, ap, f);
		}
		else
			ftw->status = FTW_SKIP;
	}
	return 0;
}
Example #11
0
/* xloutflush -- flush output buffer */
void xloutflush(LVAL fptr)
{
    FILE *fp;

    /* check for output to nil or unnamed stream */
    if (fptr == NIL || ustreamp(fptr))
        ;

    /* otherwise, check for terminal output or file output */
    else {
        fp = getfile(fptr);
        if (!fp)
            xlfail("file not open");
        else if (fp == stdout || fp == STDERR)
            ostoutflush();
        else
            osoutflush(fp);
    }    
}
Example #12
0
int
sys_open(SyscallFrame *f)
{
    char *fname;
    long l;
    int omode, fd;
    File *file;

    if (argstr(f, 0, &fname) < 0)
        return -1;

    if (arglong(f, 1, &l) < 0)
        return -1;

    omode = (long)l;

    if (omode & (OEXEC | OTRUNC | OCEXEC | ORCLOSE)) {
        // todo errstr
        return -1;
    }

    if (omode & (OWRITE | ORDWR) && !canwrite(fname)) {
        // todo errstr
        return -1;
    }

    file = getfile(fname);
    if (file == nil)
        return -1;

    file->omode = omode;

    fd = allocfd(proc, file);

    if (fd == -1) {
        // todo errstr
        releasefile(file);
        return -1;
    }

    return fd;
}
Example #13
0
File: setup.c Project: stqism/DEMOS
setcor()
{
        fcor=getfile(corfil,2);
        datmap.ufd=fcor;
        IF read(fcor, corhdr, ctob(USIZE))==ctob(USIZE)
        THEN    txtsiz = corhdr->u_tsize << 6;
                datsiz = corhdr->u_dsize << 6;
                stksiz = corhdr->u_ssize << 6;
                datmap.b1 = datbas = (magic==0410?round(txtsiz,TXTRNDSIZ):0);
                datmap.e1=(magic==0407?txtsiz:datmap.b1)+datsiz;
                datmap.f1 = ctob(USIZE);
                datmap.b2 = maxstor-stksiz;
                datmap.e2 = maxstor;
                datmap.f2 = ctob(USIZE)+(magic==0410?datsiz:datmap.e1);
                IF magic ANDF magic!=corhdr[0].u_exdata.ux_mag
                THEN    printf("%s\n",BADMAG);
                FI
        ELSE    datmap.e1 = maxfile;
        FI
}
Example #14
0
/* xlgetfile - get a file or stream */
LVAL xlgetfile P1C(int, outflag)
{
    LVAL arg;

    /* get a file or stream (cons) or nil */
    if (null(arg = xlgetarg()))
	return outflag ? NIL : getvalue(s_stdin);
    else if (streamp(arg)) {
	if (getfile(arg) == CLOSED)
	    xlfail("file not open");
#ifdef BIGNUMS
	if (arg->n_sflags & S_BINARY)
	  xlfail("binary file");
#endif
    }
    else if (arg == s_true)
	return getvalue(s_termio);
    else if (!ustreamp(arg))
	xlbadtype(arg);
    return arg;
}
int main (int argc,char *argv[])
{
   void *buf;
   size_t length;
   int fd;

   mem_open (NULL);
   log_open (NULL,LOG_NORMAL,0);
   atexit (mem_close);
   atexit (log_close);

   if (argc != 2)
	 {
		const char *progname;

		(progname = strrchr (argv[0],'/')) != NULL ? progname++ : (progname = argv[0]);
		log_printf (LOG_ERROR,"usage: %s <filename>\n",progname);
		exit (EXIT_FAILURE);
	 }

   if ((fd = open (argv[1],O_RDONLY)) < 0)
	 {
		log_printf (LOG_ERROR,"open %s: %m\n",argv[1]);
		exit (EXIT_FAILURE);
	 }

   if ((buf = getfile (fd,&length)) == NULL)
	 {
		close (fd);
		exit (EXIT_FAILURE);
	 }

   hexdump (LOG_NORMAL,buf,length);

   mem_free (buf);
   close (fd);

   exit (EXIT_SUCCESS);
}
Example #16
0
void
setsym(void)
{
	Symbol s;

	if((fsym = getfile(symfil, 1, wtflag)) < 0) {
		symmap = dumbmap(-1);
		return;
	}
	if (crackhdr(fsym, &fhdr)) {
		machbytype(fhdr.type);
		symmap = loadmap(symmap, fsym, &fhdr);
		if (symmap == 0)
			symmap = dumbmap(fsym);
		if (syminit(fsym, &fhdr) < 0)
			dprint("%r\n");
		if (mach->sbreg && lookup(0, mach->sbreg, &s))
			mach->sb = s.value;
	}
	else
		symmap = dumbmap(fsym);
}
Example #17
0
void init_edit(HWND hwnd) {
    struct strl *e;
    int n = 0;

    makefonts();

    e = editfiles;
    if (e)
    {
        do {
            char buff[MAX_PATH];
            int line_nr;
            getfile(buff, e->str, &line_nr);

            if (n == 0)
            {
                if (0 == set_currentdir(buff))
                    GetCurrentDirectory(256, currentdir);
                //dbg_printf("currentdir <%s> <%s>", currentdir, buff);
            }

            if (LoadFile(buff))
            {
                ed_cmd(EK_INIT, 0, 0, 0);
                if (line_nr) {
                    ed_cmd(EK_GOTOLINE,line_nr-1);
                    //ed_cmd(EK_MARK,lpos,imin(lpos+1,nextline(lpos,1)));
                }
            }
            e=e->next;
            ++n;
        } while (e);
        edp = ed0;
    }

    SetCurrentDirectory(strcpy(projectdir, currentdir));

    settitle();
}
Example #18
0
static void io_readfrom() {
	lua_Object f = lua_getparam(FIRSTARG);
	if (f == LUA_NOOBJECT) {
		closefile(FINPUT);
		setreturn(1, FINPUT);
	} else if (lua_tag(f) == gettag(IOTAG)) {
		int32 id = lua_getuserdata(f);
		LuaFile *current = getfile(id);
		if (!current) {
			pushresult(0);
			return;
		}
		setreturn(id, FINPUT);
	} else {
		const char *s = luaL_check_string(FIRSTARG);
		Common::String fileName = Common::lastPathComponent(s, '\\');
		LuaFile *current = NULL;
		Common::SeekableReadStream *inFile = NULL;
		Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
		inFile = saveFileMan->openForLoading(fileName);
		if (!inFile) {
			inFile = g_resourceloader->openNewStreamFile(s);
		}
		if (inFile) {
			current = new LuaFile();
			current->_in = inFile;
			current->_filename = s;
		} else {
			warning("liolib.cpp, io_readfrom(): Could not open file %s", s);
		}
		if (!current) {
			delete current;
			pushresult(0);
		} else {
			setreturn(addfile(current), FINPUT);
		}
	}
}
Example #19
0
int viewfile(int f, int n)
{				/* visit a file in VIEW mode */
	char fname[NFILEN];	/* file user wishes to find */
	int s;		/* status return */
	struct window *wp;	/* scan for windows that need updating */

	if (restflag)		/* don't allow this command if restricted */
		return resterr();
	if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE)
		return s;
	s = getfile(fname, FALSE);
	if (s) {		/* if we succeed, put it in view mode */
		curwp->w_bufp->b_mode |= MDVIEW;

		/* scan through and update mode lines of all windows */
		wp = wheadp;
		while (wp != NULL) {
			wp->w_flag |= WFMODE;
			wp = wp->w_wndp;
		}
	}
	return s;
}
Example #20
0
static void
to_line(offset_t ln)
{
	outfile = getfile();
	if (ln != LAST) {
		if (curline > ln)
			fatal("%s - out of range\n", targ);
		while (curline < ln) {
			if (getaline(TRUE) == NULL)
				fatal("%s - out of range\n", targ);
			flush();
		}
	} else		/* last file */
		if (getaline(TRUE) != NULL) {
			flush();
			for (;;) {
				if (getaline(TRUE) == NULL)
					break;
				flush();
			}
		} else
			fatal("%s - out of range\n", targ);
	closefile();
}
Example #21
0
void
add_include(struct filepointer *filep, struct inclist *file,
	    struct inclist *file_red, const char *include, int type,
	    boolean failOK)
{
	register struct inclist	*newfile;
	register struct filepointer	*content;

	/*
	 * First decide what the pathname of this include file really is.
	 */
	newfile = inc_path(file->i_file, include, type);
	if (newfile == NULL) {
		if (failOK)
		    return;
		if (file != file_red)
			warning("%s (reading %s, line %ld): ",
				file_red->i_file, file->i_file, filep->f_line);
		else
			warning("%s, line %ld: ", file->i_file, filep->f_line);
		warning1("cannot find include file \"%s\"\n", include);
		show_where_not = TRUE;
		newfile = inc_path(file->i_file, include, type);
		show_where_not = FALSE;
	}

	if (newfile) {
		included_by(file, newfile);
		if (!(newfile->i_flags & SEARCHED)) {
			newfile->i_flags |= SEARCHED;
			content = getfile(newfile->i_file);
			find_includes(content, newfile, file_red, 0, failOK);
			freefile(content);
		}
	}
}
Example #22
0
int
main (int argc, char *argv[])
{
  unsigned char *data;
  int len;
  JpegDecoder *dec;
  char *fn = "c:\\data\\liboil\\test.jpg";
  unsigned char *ptr;
  int rowstride;
  int width;
  int height;

  /*if (argc < 2) {
        printf("jpeg_test <file.jpg>\n");
        exit(1);
  }*/
  if (argc > 1)
        fn = argv[1];
  
  std_log(LOG_FILENAME_LINE, "Test Started examples_jpeg");
  dec = jpeg_decoder_new ();    //to create decoder instance
  
  data = getfile (fn, &len);

  jpeg_decoder_addbits (dec, data, len);
  jpeg_decoder_decode (dec);

  jpeg_decoder_get_component_ptr (dec, 1, &ptr, &rowstride);
  jpeg_decoder_get_component_size (dec, 1, &width, &height);

  dump_pgm (ptr, rowstride, width, height);
  
  std_log(LOG_FILENAME_LINE, "Test Successful");
  create_xml(0);
  return 0;
}
Example #23
0
File: cpp3.c Project: vidarh/FPL
ReturnCode addfile(struct Global *global,
		   FILE *fp,		/* Open file pointer */
		   char *filename)	/* Name of the file  */
{
  /*
   * Initialize tables for this open file.  This is called from openfile()
   * above (for #include files), and from the entry to cpp to open the main
   * input file. It calls a common routine, getfile() to build the FILEINFO
   * structure which is used to read characters. (getfile() is also called
   * to setup a macro replacement.)
   */

  FILEINFO *file;
  ReturnCode ret;
  
  ret = getfile(global, NBUFF, filename, &file);
  if(ret)
    return(ret);
  file->fp = fp;			/* Better remember FILE *	*/
  file->buffer[0] = EOS;		/* Initialize for first read	*/
  global->line = 1;			/* Working on line 1 now	*/
  global->wrongline = TRUE;		/* Force out initial #line	*/
  return(FPP_OK);
}
Example #24
0
/*
 * Pipe a one line command into a window
 * Bound to ^X @
 * We use a unique temporary file name so that multiple instances of
 * MicroEMACS don't try to use the same file.
 */
pipecmd(f, n)
{
	register WINDOW *wp;	/* pointer to new window */
	register BUFFER *bp;	/* pointer to buffer to zot */
	register char *tmp;	/* ptr to TMP DOS environment variable */
	char line[NLINE];	/* command line send to shell */
	static char bname[] = "command";
	static char filnam[NSTRING];
	char *getenv();

	/* don't allow this command if restricted */
	if (restflag)
		return(resterr());

	/* get rid of the command output buffer if it exists */
        if ((bp=bfind(bname, FALSE, 0)) != FALSE) {
		/* try to make sure we are off screen */
		wp = wheadp;
		while (wp != NULL) {
			if (wp->w_bufp == bp) {
				onlywind(FALSE, 1);
				break;
			}
			wp = wp->w_wndp;
		}
		/* get rid of the existing command buffer */
		if (zotbuf(bp) != TRUE)
			return(FALSE);
	}

	/* get the command to pipe in */
        if (mlreply("@", line, NLINE) != TRUE)
                return(FALSE);

	/* Call mktemp() to get a unique filename in the tmp directory. */
	if ((tmp = getenv("TMP")) == NULL)
		filnam[0] = 0;
	else {
		strcpy(filnam, tmp);
		if (filnam[strlen(filnam) - 1] != '\\')
			strcat(filnam, "\\");
        }
	strcat(filnam,"eXXXXXX");
	mktemp(filnam);

	/* redirect the command output to the output file */
	strcat(line, " >>");
	strcat(line, filnam);
	movecursor(term.t_nrow - 1, 0);

	/* execute the command */
	TTkclose();
	system(line);
	TTkopen();
        sgarbf = TRUE;

	/* did the output file get generated? */
	if (access( filnam, 0) != 0)
		return(FALSE);
		
	/* split the current window to make room for the command output */
	if (splitwind(FALSE, 1) == FALSE)
			return(FALSE);

	/* and read the stuff in */
	if (getfile(filnam, FALSE) == FALSE)
		return(FALSE);

	/* rename the buffer */
	strcpy( curwp->w_bufp->b_bname, "command");
	/* make this window in VIEW mode, update all mode lines */
	curwp->w_bufp->b_mode |= MDVIEW;
	wp = wheadp;
	while (wp != NULL) {
		wp->w_flag |= WFMODE;
		wp = wp->w_wndp;
	}

	/* and get rid of the temporary file */
	unlink(filnam);
	return(TRUE);
}
Example #25
0
int
extractfile(char *name)
{
	int flags;
	uid_t uid;
	gid_t gid;
	mode_t mode;
	int extsize;
	struct timeval mtimep[2], ctimep[2];
	struct entry *ep;
	char *buf;

	curfile.name = name;
	curfile.action = USING;
	mtimep[0].tv_sec = curfile.atime_sec;
	mtimep[0].tv_usec = curfile.atime_nsec / 1000;
	mtimep[1].tv_sec = curfile.mtime_sec;
	mtimep[1].tv_usec = curfile.mtime_nsec / 1000;
	ctimep[0].tv_sec = curfile.atime_sec;
	ctimep[0].tv_usec = curfile.atime_nsec / 1000;
	ctimep[1].tv_sec = curfile.birthtime_sec;
	ctimep[1].tv_usec = curfile.birthtime_nsec / 1000;
	extsize = curfile.extsize;
	uid = getuid();
	if (uid == 0)
		uid = curfile.uid;
	gid = curfile.gid;
	mode = curfile.mode;
	flags = curfile.file_flags;
	switch (mode & IFMT) {

	default:
		fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
		skipfile();
		return (FAIL);

	case IFSOCK:
		vprintf(stdout, "skipped socket %s\n", name);
		skipfile();
		return (GOOD);

	case IFDIR:
		if (mflag) {
			ep = lookupname(name);
			if (ep == NULL || ep->e_flags & EXTRACT)
				panic("unextracted directory %s\n", name);
			skipfile();
			return (GOOD);
		}
		vprintf(stdout, "extract file %s\n", name);
		return (genliteraldir(name, curfile.ino));

	case IFLNK:
		lnkbuf[0] = '\0';
		pathlen = 0;
		buf = setupextattr(extsize);
		getfile(xtrlnkfile, xtrattr, xtrlnkskip);
		if (pathlen == 0) {
			vprintf(stdout,
			    "%s: zero length symbolic link (ignored)\n", name);
			return (GOOD);
		}
		if (linkit(lnkbuf, name, SYMLINK) == GOOD) {
			if (extsize > 0)
				set_extattr_link(name, buf, extsize);
			(void) lchown(name, uid, gid);
			(void) lchmod(name, mode);
			(void) lutimes(name, ctimep);
			(void) lutimes(name, mtimep);
			(void) lchflags(name, flags);
			return (GOOD);
		}
		return (FAIL);

	case IFIFO:
		vprintf(stdout, "extract fifo %s\n", name);
		if (Nflag) {
			skipfile();
			return (GOOD);
		}
		if (uflag)
			(void) unlink(name);
		if (mkfifo(name, 0600) < 0) {
			fprintf(stderr, "%s: cannot create fifo: %s\n",
			    name, strerror(errno));
			skipfile();
			return (FAIL);
		}
		if (extsize == 0) {
			skipfile();
		} else {
			buf = setupextattr(extsize);
			getfile(xtrnull, xtrattr, xtrnull);
			set_extattr_file(name, buf, extsize);
		}
		(void) chown(name, uid, gid);
		(void) chmod(name, mode);
		(void) utimes(name, ctimep);
		(void) utimes(name, mtimep);
		(void) chflags(name, flags);
		return (GOOD);

	case IFCHR:
	case IFBLK:
		vprintf(stdout, "extract special file %s\n", name);
		if (Nflag) {
			skipfile();
			return (GOOD);
		}
		if (uflag)
			(void) unlink(name);
		if (mknod(name, (mode & (IFCHR | IFBLK)) | 0600,
		    (int)curfile.rdev) < 0) {
			fprintf(stderr, "%s: cannot create special file: %s\n",
			    name, strerror(errno));
			skipfile();
			return (FAIL);
		}
		if (extsize == 0) {
			skipfile();
		} else {
			buf = setupextattr(extsize);
			getfile(xtrnull, xtrattr, xtrnull);
			set_extattr_file(name, buf, extsize);
		}
		(void) chown(name, uid, gid);
		(void) chmod(name, mode);
		(void) utimes(name, ctimep);
		(void) utimes(name, mtimep);
		(void) chflags(name, flags);
		return (GOOD);

	case IFREG:
		vprintf(stdout, "extract file %s\n", name);
		if (Nflag) {
			skipfile();
			return (GOOD);
		}
		if (uflag)
			(void) unlink(name);
		if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
		    0600)) < 0) {
			fprintf(stderr, "%s: cannot create file: %s\n",
			    name, strerror(errno));
			skipfile();
			return (FAIL);
		}
		buf = setupextattr(extsize);
		getfile(xtrfile, xtrattr, xtrskip);
		if (extsize > 0)
			set_extattr_fd(ofile, name, buf, extsize);
		(void) fchown(ofile, uid, gid);
		(void) fchmod(ofile, mode);
		(void) futimes(ofile, ctimep);
		(void) futimes(ofile, mtimep);
		(void) fchflags(ofile, flags);
		(void) close(ofile);
		return (GOOD);
	}
	/* NOTREACHED */
}
Example #26
0
/*
 * Verify that the tape drive can be accessed and
 * that it actually is a dump tape.
 */
void
setup(void)
{
	int i, j, *ip;
	struct stat stbuf;

	vprintf(stdout, "Verify tape and initialize maps\n");
	if (pipecmdin) {
		if (setenv("RESTORE_VOLUME", "1", 1) == -1) {
			fprintf(stderr, "Cannot set $RESTORE_VOLUME: %s\n",
			    strerror(errno));
			done(1);
		}
		popenfp = popen(magtape, "r");
		mt = popenfp ? fileno(popenfp) : -1;
	} else
#ifdef RRESTORE
	if (host)
		mt = rmtopen(magtape, 0);
	else
#endif
	if (pipein)
		mt = 0;
	else
		mt = open(magtape, O_RDONLY, 0);
	if (mt < 0) {
		fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
		done(1);
	}
	volno = 1;
	setdumpnum();
	FLUSHTAPEBUF();
	if (!pipein && !pipecmdin && !bflag)
		findtapeblksize();
	if (gethead(&spcl) == FAIL) {
		fprintf(stderr, "Tape is not a dump tape\n");
		done(1);
	}
	if (pipein) {
		endoftapemark.s_spcl.c_magic = FS_UFS2_MAGIC;
		endoftapemark.s_spcl.c_type = TS_END;
		ip = (int *)&endoftapemark;
		j = sizeof(union u_spcl) / sizeof(int);
		i = 0;
		do
			i += *ip++;
		while (--j);
		endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
	}
	if (vflag || command == 't')
		printdumpinfo();
	dumptime = _time64_to_time(spcl.c_ddate);
	dumpdate = _time64_to_time(spcl.c_date);
	if (stat(".", &stbuf) < 0) {
		fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
		done(1);
	}
	if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
		fssize = TP_BSIZE;
	if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
		fssize = stbuf.st_blksize;
	if (((TP_BSIZE - 1) & stbuf.st_blksize) != 0) {
		fprintf(stderr, "Warning: filesystem with non-multiple-of-%d "
		    "blocksize (%d);\n", TP_BSIZE, stbuf.st_blksize);
		fssize = roundup(fssize, TP_BSIZE);
		fprintf(stderr, "\twriting using blocksize %ld\n", fssize);
	}
	if (spcl.c_volume != 1) {
		fprintf(stderr, "Tape is not volume 1 of the dump\n");
		done(1);
	}
	if (gethead(&spcl) == FAIL) {
		dprintf(stdout, "header read failed at %ld blocks\n", blksread);
		panic("no header after volume mark!\n");
	}
	findinode(&spcl);
	if (spcl.c_type != TS_CLRI) {
		fprintf(stderr, "Cannot find file removal list\n");
		done(1);
	}
	maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
	dprintf(stdout, "maxino = %ju\n", (uintmax_t)maxino);
	map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
	if (map == NULL)
		panic("no memory for active inode map\n");
	usedinomap = map;
	curfile.action = USING;
	getfile(xtrmap, xtrmapskip, xtrmapskip);
	if (spcl.c_type != TS_BITS) {
		fprintf(stderr, "Cannot find file dump list\n");
		done(1);
	}
	map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
	if (map == (char *)NULL)
		panic("no memory for file dump list\n");
	dumpmap = map;
	curfile.action = USING;
	getfile(xtrmap, xtrmapskip, xtrmapskip);
	/*
	 * If there may be whiteout entries on the tape, pretend that the
	 * whiteout inode exists, so that the whiteout entries can be
	 * extracted.
	 */
	SETINO(WINO, dumpmap);
	/* 'r' restores don't call getvol() for tape 1, so mark it as read. */
	if (command == 'r')
		tapesread = 1;
}
Example #27
0
static int
chpasswd(AuthConn *c, char *id)
{
	ulong len;
	int rv = -1, newpasslen = 0;
	mpint *H, *Hi;
	uchar *memfile;
	char *newpass, *passck;
	char *list, *cur, *next, *hexHi;
	char *f[8], prompt[128];

	H = mpnew(0);
	Hi = mpnew(0);
	/* changing our password is vulnerable to connection failure */
	for(;;){
		snprint(prompt, sizeof(prompt), "new password for %s: ", id);
		newpass = readcons(prompt, nil, 1);
		if(newpass == nil)
			goto Out;
		if(strlen(newpass) >= 7)
			break;
		else if(strlen(newpass) == 0){
			fprint(2, "!password change aborted\n");
			goto Out;
		}
		print("!password must be at least 7 characters\n");
	}
	newpasslen = strlen(newpass);
	snprint(prompt, sizeof(prompt), "retype password: "******"readcons failed\n");
		goto Out;
	}
	if(strcmp(passck, newpass) != 0){
		fprint(2, "passwords didn't match\n");
		goto Out;
	}

	c->conn->write(c->conn, (uchar*)"CHPASS", strlen("CHPASS"));
	hexHi = PAK_Hi(id, newpass, H, Hi);
	c->conn->write(c->conn, (uchar*)hexHi, strlen(hexHi));
	free(hexHi);
	mpfree(H);
	mpfree(Hi);

	if(getfile(c->conn, ".", (uchar **)(void*)&list, &len, nil, 0) < 0){
		fprint(2, "directory listing failed.\n");
		goto Out;
	}

	/* Loop over files and reencrypt them; try to keep going after error */
	for(cur=list; (next=strchr(cur, '\n')) != nil; cur=next+1){
		*next = '\0';
		if(tokenize(cur, f, nelem(f))< 1)
			break;
		fprint(2, "reencrypting '%s'\n", f[0]);
		if(getfile(c->conn, f[0], &memfile, &len, (uchar*)c->pass, c->passlen) < 0){
			fprint(2, "getfile of '%s' failed\n", f[0]);
			continue;
		}
		if(putfile(c->conn, f[0], memfile, len, (uchar*)newpass, newpasslen) < 0)
			fprint(2, "putfile of '%s' failed\n", f[0]);
		free(memfile);
	}
	free(list);
	c->conn->write(c->conn, (uchar*)"BYE", 3);
	rv = 0;

Out:
	if(newpass != nil){
		memset(newpass, 0, newpasslen);
		free(newpass);
	}
	c->conn->free(c->conn);
	return rv;
}
Example #28
0
/**
 * @brief Main function
 * @return 0 if no errors occurred
 */
int main(void) {
    // Print some informations
    printf("%s\n               Updater %s\n    %s\n%s\n\n", UPDATER_BOX, UPDATER_VERSION, UPDATER_WEB, UPDATER_BOX);


    // Open configuration file
    FILE *configfile = fopen(CONFIG_PATH, "r");
    if(configfile == NULL) {
        fprintf(stderr, "Could not read updater configuration file!\n");
        return 1;
    }

    char localversion[64], latestversion[64];
    char url[1024];

    fscanf(configfile, "%64[^\n]", localversion);
    fscanf(configfile, "%s", url);
    fclose(configfile);

    if(strlen(localversion) == 0 || strlen(url) == 0) {
        fprintf(stderr, "Corrupt updater configuration file!\n");
        return 1;
    }

    FILE *versionfile = fopen(TMP_FILE, "w");

    // Download versionfile
    if(!getfile(url, versionfile))
        return 1;

    // Make sure the cache is written to the disk!
    // Note: fflush() did not work here!?!
    freopen(TMP_FILE, "r", versionfile);

    // Now read the file
    fscanf(versionfile, "%64[^\n]", latestversion);

    if(strlen(latestversion) == 0) {
        fprintf(stderr, "Corrupt updater version file!\n");
        fclose(versionfile);
        return 1;
    }

    // Print versions
    printf("Local version:   %s\n", localversion);
    printf("Latest version:  %s\n\n", latestversion);

    // Compare versions
    if(strcmp(localversion, latestversion) == 0)
        printf("No update available.");
    else {
        printf("An update is available!\n");

        if(CHECK_FOR_BETA && strlen(latestversion) > 3) {
            if(latestversion[strlen(latestversion)-4] == 'b' &&
                    latestversion[strlen(latestversion)-3] == 'e' &&
                    latestversion[strlen(latestversion)-2] == 't' &&
                    latestversion[strlen(latestversion)-1] == 'a')
            {
                printf("Note: Latest version is a beta version. Update on your own risk!\n");
            }
        }
    }

    fclose(versionfile);
    remove(TMP_FILE);

    return 0;
}
Example #29
0
void mpsxx::compress_qc_mpos (const size_t& N, const std::string& opname, const std::string& prefix)
{
  std::vector<size_t> Msav(N-1,0);

  size_t iter = 0;
  bool conv = false;
  while(!conv) {
    std::cout << "\t====================================================================================================" << std::endl;
    std::cout << "\t\tMPO compression sweep :: " << iter << std::endl;
    btas::QSTArray<double,4,fermion> lmpo;
    btas::QSTArray<double,4,fermion> rmpo;

    std::cout << "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
    std::cout << "\t\t\tFORWARD SWEEP" << std::endl;
    std::cout << "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;

    // forward sweep
    std::vector<size_t> Mfwd(N-1,0);
    load(lmpo,getfile(opname,prefix,0));
    for(size_t i = 0; i < N-1; ++i) {
      std::cout << "\t====================================================================================================" << std::endl;
      std::cout << "\t\tSITE [ " << std::setw(3) << i << " ] " << std::endl;
      std::cout << "\t----------------------------------------------------------------------------------------------------" << std::endl;
      std::cout << "\t\t\t";

      load(rmpo,getfile(opname,prefix,i+1));
      Mfwd[i] = compress_mpos_2site(1,lmpo,rmpo);
      save(lmpo,getfile(opname,prefix,i));
      lmpo = rmpo;
    }
    save(lmpo,getfile(opname,prefix,N-1));

    std::cout << "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
    std::cout << "\t\t\tBACKWARD SWEEP" << std::endl;
    std::cout << "\t++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;

    // backward sweep
    std::vector<size_t> Mbwd(N-1,0);
    for(size_t i = N-1; i > 0; --i) {
      std::cout << "\t====================================================================================================" << std::endl;
      std::cout << "\t\tSITE [ " << std::setw(3) << i << " ] " << std::endl;
      std::cout << "\t----------------------------------------------------------------------------------------------------" << std::endl;
      std::cout << "\t\t\t";

      load(lmpo,getfile(opname,prefix,i-1));
      Mbwd[i-1] = compress_mpos_2site(0,lmpo,rmpo);
      save(rmpo,getfile(opname,prefix,i));
      rmpo = lmpo;
    }
    save(rmpo,getfile(opname,prefix,0));

    conv  = std::equal(Mfwd.begin(),Mfwd.end(),Msav.begin());
    conv &= std::equal(Mbwd.begin(),Mbwd.end(),Msav.begin());

    ++iter;

    Msav = Mbwd;
  }

  size_t Msum = 0;
  std::cout << "\t\tCheck boundary size..." << std::endl;
  std::cout << "\t\t\tM = 1:";
  for(size_t s = 0; s < Msav.size(); ++s) {
    Msum += Msav[s];
    std::cout << Msav[s] << ":";
  }
  std::cout << "1" << std::endl;
}
Example #30
0
static char const* parseFiles(tr_info* inf, tr_variant* files, tr_variant const* length)
{
    int64_t len;

    inf->totalSize = 0;

    if (tr_variantIsList(files)) /* multi-file mode */
    {
        struct evbuffer* buf;
        char const* result;

        if (path_component_is_suspicious(inf->name))
        {
            return "path";
        }

        buf = evbuffer_new();
        result = NULL;

        inf->isFolder = true;
        inf->fileCount = tr_variantListSize(files);
        inf->files = tr_new0(tr_file, inf->fileCount);

        for (tr_file_index_t i = 0; i < inf->fileCount; i++)
        {
            tr_variant* file;
            tr_variant* path;

            file = tr_variantListChild(files, i);

            if (!tr_variantIsDict(file))
            {
                result = "files";
                break;
            }

            if (!tr_variantDictFindList(file, TR_KEY_path_utf_8, &path))
            {
                if (!tr_variantDictFindList(file, TR_KEY_path, &path))
                {
                    result = "path";
                    break;
                }
            }

            if (!getfile(&inf->files[i].name, inf->name, path, buf))
            {
                result = "path";
                break;
            }

            if (!tr_variantDictFindInt(file, TR_KEY_length, &len))
            {
                result = "length";
                break;
            }

            inf->files[i].length = len;
            inf->totalSize += len;
        }

        evbuffer_free(buf);
        return result;
    }
    else if (tr_variantGetInt(length, &len)) /* single-file mode */
    {
        if (path_component_is_suspicious(inf->name))
        {
            return "path";
        }

        inf->isFolder = false;
        inf->fileCount = 1;
        inf->files = tr_new0(tr_file, 1);
        inf->files[0].name = tr_strdup(inf->name);
        inf->files[0].length = len;
        inf->totalSize += len;
    }
    else
    {
        return "length";
    }

    return NULL;
}