예제 #1
0
파일: du.c 프로젝트: Zeke-OS/zeke
int
main(int argc, char *argv[])
{
    struct recursor r = { .fn = du, .hist = NULL, .depth = 0, .maxdepth = 0,
                          .follow = 'P', .flags = 0 };
    off_t n = 0;
    int kflag = 0, dflag = 0;
    char *bsize;

    ARGBEGIN {
    case 'a':
        aflag = 1;
        break;
    case 'd':
        dflag = 1;
        maxdepth = estrtonum(EARGF(usage()), 0, MIN(LLONG_MAX, SIZE_MAX));
        break;
    case 'h':
        hflag = 1;
        break;
    case 'k':
        kflag = 1;
        break;
    case 's':
        sflag = 1;
        break;
    case 'x':
        r.flags |= SAMEDEV;
        break;
    case 'H':
    case 'L':
    case 'P':
        r.follow = ARGC();
        break;
    default:
        usage();
    } ARGEND;

    if ((aflag && sflag) || (dflag && sflag))
        usage();

    bsize = getenv("BLOCKSIZE");
    if (bsize)
        blksize = estrtonum(bsize, 1, MIN(LLONG_MAX, SIZE_MAX));
    if (kflag)
        blksize = 1024;

    if (!argc) {
        recurse(".", &n, &r);
        printpath(n, ".");
    } else {
        for (; *argv; argc--, argv++) {
            n = 0;
            recurse(*argv, &n, &r);
            printpath(n, *argv);
        }
    }

    return fshut(stdout, "<stdout>") || recurse_status;
}
예제 #2
0
파일: output.c 프로젝트: fuzxxl/digest
static int format_bsd(const uint8_t *p, size_t plen, off_t flen, const char *path) {
	char buf[7] = "00000 \0";

	if (plen != 2) {
		fputs("Digest incompatible to output format\n", stderr);
		return 1;
	}

	short2str(buf, p[0] << 8 | p[1]);
	fputs(buf, stdout);

	/* Implementation restriction: Can only hash files with up to 64 MiB */
	if (flen >= UINT16_MAX * 1024) {
		fputs("File too large for this format\n", stderr);
		fputs("?????", stdout);
		printpath(path);
		return 1;
	} else {
		flen = (flen + 1023) >> 10;
		memset(buf, ' ', 5);
		short2str(buf, flen);
		buf[5] = '\0';
		fputs(buf, stdout);
		printpath(path);
		return 0;
	}
}
예제 #3
0
파일: output.c 프로젝트: fuzxxl/digest
static int format_sysv(const uint8_t *p, size_t plen, off_t flen, const char *path) {
	char buf[7];

	buf[5] = ' ';
	buf[6] = '\0';

	if (plen != 2) {
		fputs("Digest incompatible to output format\n", stderr);
		return 1;
	}

	fputs(short2str(buf, p[0] << 8 | p[1]), stdout);

	/* Implementation restriction: Can only hash files with up to 32 MiB */
	if (flen > UINT16_MAX * 512) {
		fputs("File too large for this format\n", stderr);
		fputs("?????", stdout);
		printpath(path);
		return 1;
	} else {
		flen = (flen + 511) >> 9;
		buf[5] = '\0';
		fputs(short2str(buf, flen), stdout);
		printpath(path);
		return 0;
	}
}
예제 #4
0
static void
decode_renameat(struct tcb *tcp)
{
	print_dirfd(tcp, tcp->u_arg[0]);
	printpath(tcp, tcp->u_arg[1]);
	tprints(", ");
	print_dirfd(tcp, tcp->u_arg[2]);
	printpath(tcp, tcp->u_arg[3]);
}
예제 #5
0
파일: link.c 프로젝트: MoroJr/strace
int
sys_link(struct tcb *tcp)
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprints(", ");
		printpath(tcp, tcp->u_arg[1]);
	}
	return 0;
}
예제 #6
0
파일: link.c 프로젝트: MoroJr/strace
int
sys_symlinkat(struct tcb *tcp)
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprints(", ");
		print_dirfd(tcp, tcp->u_arg[1]);
		printpath(tcp, tcp->u_arg[2]);
	}
	return 0;
}
예제 #7
0
파일: link.c 프로젝트: MoroJr/strace
int
sys_linkat(struct tcb *tcp)
{
	if (entering(tcp)) {
		print_dirfd(tcp, tcp->u_arg[0]);
		printpath(tcp, tcp->u_arg[1]);
		tprints(", ");
		print_dirfd(tcp, tcp->u_arg[2]);
		printpath(tcp, tcp->u_arg[3]);
		tprints(", ");
		printflags(at_flags, tcp->u_arg[4], "AT_???");
	}
	return 0;
}
예제 #8
0
파일: 69p.c 프로젝트: RAJU009F/my-work
main()
    {
    
    
        struct BT *rt=NULL;
        rt=nn(95);
        rt->l=nn(90);
        rt->r=nn(99);
        rt->l->l=nn(91);
        rt->l->r=nn(92);
        rt->r->l=nn(98);
        rt->r->r=nn(97);
        rt->r->l->l=nn(96);
        rt->r->r->l=nn(100);
        rt->l->r->l=nn(1);
       
       
       
       int i;
       
        for(i=0;i<10;i++)
            {
                printlevelorder(rt,i);
                printf("\n");
            }    
            
      // printlevel(rt);
      int path[1000]; 
    printpath(rt,path,0);
    }
예제 #9
0
파일: fanotify.c 프로젝트: MoroJr/strace
int
sys_fanotify_mark(struct tcb *tcp)
{
	unsigned long long mask = 0;
	int argn;

	if (exiting(tcp))
		return 0;

	printfd(tcp, tcp->u_arg[0]);
	tprints(", ");
	printflags(fan_mark_flags, (unsigned) tcp->u_arg[1], "FAN_MARK_???");
	tprints(", ");
	/*
	 * the mask argument is defined as 64-bit,
	 * but kernel uses the lower 32 bits only.
	 */
	argn = getllval(tcp, &mask, 2);
	printflags(fan_event_flags, mask, "FAN_???");
	tprints(", ");
	if ((int) tcp->u_arg[argn] == FAN_NOFD)
		tprints("FAN_NOFD, ");
	else
		print_dirfd(tcp, tcp->u_arg[argn]);
	printpath(tcp, tcp->u_arg[argn + 1]);

	return 0;
}
예제 #10
0
파일: ipc.c 프로젝트: Ale1ster/kerneldir
int
sys_mq_open(struct tcb *tcp)
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprints(", ");
		/* flags */
		tprint_open_modes(tcp->u_arg[1]);
		if (tcp->u_arg[1] & O_CREAT) {
# ifndef HAVE_MQUEUE_H
			tprintf(", %lx", tcp->u_arg[2]);
# else
			struct mq_attr attr;
			/* mode */
			tprintf(", %#lo, ", tcp->u_arg[2]);
			if (umove(tcp, tcp->u_arg[3], &attr) < 0)
				tprints("{ ??? }");
			else
				tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
					(long) attr.mq_maxmsg,
					(long) attr.mq_msgsize);
# endif
		}
	}
	return 0;
}
예제 #11
0
static void
decode_chmod(struct tcb *tcp, const int offset)
{
	printpath(tcp, tcp->u_arg[offset]);
	tprints(", ");
	print_numeric_umode_t(tcp->u_arg[offset + 1]);
}
예제 #12
0
파일: print.c 프로젝트: cheusov/nbase
/*
 * print [inode] [size] name
 * return # of characters printed, no trailing characters.
 */
static int
printaname(FTSENT *p, int inodefield, int sizefield)
{
	struct stat *sp;
	int chcnt;
	char szbuf[5];

	sp = p->fts_statp;
	chcnt = 0;
	if (f_inode)
		chcnt += printf("%*"PRIu64" ", inodefield, sp->st_ino);
	if (f_size) {
		if (f_humanize) {
			if ((humanize_number(szbuf, sizeof(szbuf), sp->st_size,
			    "", HN_AUTOSCALE,
			    (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
				err(1, "humanize_number");
			chcnt += printf("%*s ", sizefield, szbuf);
		} else {
			chcnt += printf(f_commas ? "%'*llu " : "%*llu ",
			    sizefield, (unsigned long long)
			    howmany(sp->st_blocks, blocksize));
		}
	}
	if (f_octal || f_octal_escape)
		chcnt += safe_printpath(p);
	else if (f_nonprint)
		chcnt += printescapedpath(p);
	else
		chcnt += printpath(p);
	if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
		chcnt += printtype(sp->st_mode);
	return (chcnt);
}
예제 #13
0
static void
decode_execve(struct tcb *tcp, const unsigned int index)
{
	printpath(tcp, tcp->u_arg[index + 0]);
	tprints(", ");

	if (!tcp->u_arg[index + 1] || !verbose(tcp))
		printaddr(tcp->u_arg[index + 1]);
	else {
		tprints("[");
		printargv(tcp, tcp->u_arg[index + 1]);
		tprints("]");
	}
	tprints(", ");

	if (!tcp->u_arg[index + 2] || !verbose(tcp))
		printaddr(tcp->u_arg[index + 2]);
	else if (abbrev(tcp))
		printargc("[/* %d var%s */]", tcp, tcp->u_arg[index + 2]);
	else {
		tprints("[");
		printargv(tcp, tcp->u_arg[index + 2]);
		tprints("]");
	}
}
예제 #14
0
파일: maze.c 프로젝트: Karikaturist/WPC
void drawpath()
{
  char m[HEIGHT+2][WIDTH+2]; 
  size_t i, j;
  for (i = 0; i <= HEIGHT; ++i)
    for (j = 0; j <= WIDTH; ++j)
      m[i][j] = d[i][j]!=0 ? '.' : ' ';

  m[1][1] = getdirchar(D+R);
  for (i = 1; i < curpathlen-1; i++)
  {
    int y = curpath[i][0], x = curpath[i][1];
    int yl = curpath[i-1][0], xl = curpath[i-1][1];
    int yr = curpath[i+1][0], xr = curpath[i+1][1];
    int left = getdir(y,x,yl,xl);
    int right = getdir(y,x,yr,xr);
    m[y][x] = getdirchar(left+right);
  }

  for (i = 0; i <= HEIGHT; ++i)
  {
    for (j = 0; j <= WIDTH; ++j)
      printf("%c", m[i][j]);
    printf("\n");
  }
  printf("\n");
  printpath();
}
예제 #15
0
static int
pathlist_f(void)
{
	int		i;

	for (i = 0; i < fs_count; i++)
		printpath(&fs_table[i], i, 1, &fs_table[i] == fs_path);
	return 0;
}
예제 #16
0
파일: bjm.c 프로젝트: fengidri/typhoon
int
sys_create_module(struct tcb *tcp)
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprintf(", %lu", tcp->u_arg[1]);
	}
	return RVAL_HEX;
}
예제 #17
0
파일: access.c 프로젝트: MoroJr/strace
static int
decode_access(struct tcb *tcp, int offset)
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[offset]);
		tprints(", ");
		printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
	}
	return 0;
}
예제 #18
0
파일: uid.c 프로젝트: MoroJr/strace
int
sys_chown(struct tcb *tcp)
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		printuid(", ", tcp->u_arg[1]);
		printuid(", ", tcp->u_arg[2]);
	}
	return 0;
}
예제 #19
0
파일: btrfs.c 프로젝트: yunchih/strace
static bool
print_btrfs_data_container_ino_path(struct tcb *tcp, void *elem_buf,
				       size_t elem_size, void *data)
{
	const uint64_t *const offset = elem_buf;
	const uint64_t *const val_addr = data;

	printpath(tcp, *val_addr + *offset);

	return true;
}
예제 #20
0
int dothedir(const char *path,mpz_t size, int output, unsigned int depth){
  DIR *d;
  struct dirent *de;
  mpz_t cursize;
  mpz_t tmpsize;
  char tmppath[PATH_MAX+1];
  size_t pathsize;

  /* try to open the dir */
  d=opendir(path);
  if(!d)
    return 2;

  /* calculate the pathsize and return an error if > PATH_MAX */
  pathsize=strlen(path);
  if(path[pathsize-1]!='/') pathsize+=1;
  if(pathsize>PATH_MAX)
    return 3;

  /* copy the path to tmppath and add a '/' if needed */
  strcpy(tmppath,path);
  if(path[pathsize-1]!='/') strcat(tmppath,"/");

  /* start with cursize of 0 */
  mpz_init_set_ui(cursize,0);
  mpz_init(tmpsize);

  /* for each directory entry... */
  while(de=readdir(d))
    /* if the entry is not "." or ".."... */
    if( strcmp(de->d_name,".") && strcmp(de->d_name,"..") ){
      /* if the resultant path will be larger than PATH_MAX return an error */
      if(strlen(de->d_name)+pathsize > PATH_MAX){
	mpz_clear(cursize); /* free cursize */
	mpz_clear(tmpsize); /* free tmpsize */
	return 3;
      }
      strcat(tmppath,de->d_name); /* add the entry to the path */
      if(!dothepath(tmppath,tmpsize,0,depth)) /* handle the new path */
	mpz_add(cursize,cursize,tmpsize); /* add to tally if successful */
      tmppath[pathsize]=0; /* remove the entry from the path */
    }

  closedir(d); /* close the directory */

  if(output || opt_outputall)
    printpath(cursize,path); /* output the result */

  mpz_swap(size,cursize); /* return the result */
  mpz_clear(cursize); /* free cursize */
  mpz_clear(tmpsize); /* free tmpsize */

  return 0;
}
예제 #21
0
static int
print_f(
	int		argc,
	char		**argv)
{
	int		i;

	for (i = 0; i < fs_count; i++)
		printpath(&fs_table[i], i, 0, 0);
	return 0;
}
예제 #22
0
파일: statfs.c 프로젝트: MoroJr/strace
int
sys_statfs(struct tcb *tcp)
{
	if (entering(tcp)) {
		printpath(tcp, tcp->u_arg[0]);
		tprints(", ");
	} else {
		printstatfs(tcp, tcp->u_arg[1]);
	}
	return 0;
}
int main()
{
    struct node* tr=newnode(1);
    tr->left=newnode(2);
    tr->left->left=newnode(4);
    tr->left->right=newnode(5);
    tr->right=newnode(3);
    tr->right->left=newnode(10);
    printpath(tr);
    return 0;
}
예제 #24
0
파일: dijkstra.c 프로젝트: malikvivek/Work
void printpath(int x,int i,int p[]){
	printf("\n");
	if(i==x){
		printf("%d",x);
	}
	else if(p[i]==0)
		printf("no path from %d to %d",x,i);
	else{
		printpath(x,p[i],p);
		printf("..%d",i);
	}
}
예제 #25
0
파일: 69p.c 프로젝트: RAJU009F/my-work
void printpath(struct BT *root,int p[],int level)
    {
        if(!root)
            return;
            
            p[level]=root->data;
            level++;
            if(!root->l&&!root->r)
                printarray(p,level);
                
             else
                {
                    printpath(root->l,p,level);
                    printpath(root->r,p,level);
                
                
                }   
    
    
    
    }   
예제 #26
0
파일: du.c 프로젝트: Zeke-OS/zeke
static void
du(const char *path, struct stat *st, void *total, struct recursor *r)
{
    off_t subtotal = 0;

    if (st && S_ISDIR(st->st_mode))
        recurse(path, &subtotal, r);
    *((off_t *)total) += subtotal + nblks(st ? st->st_blocks : 0);

    if (!sflag && r->depth <= maxdepth && r->depth && st &&
        (S_ISDIR(st->st_mode) || aflag))
        printpath(subtotal + nblks(st->st_blocks), path);
}
예제 #27
0
파일: system.c 프로젝트: GeoffGats/strace
int
sys_mount(struct tcb *tcp)
{
	if (entering(tcp)) {
		int ignore_type = 0, ignore_data = 0;
		unsigned long flags = tcp->u_arg[3];

		/* Discard magic */
		if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
			flags &= ~MS_MGC_MSK;

		if (flags & MS_REMOUNT)
			ignore_type = 1;
		else if (flags & (MS_BIND | MS_MOVE))
			ignore_type = ignore_data = 1;

		printpath(tcp, tcp->u_arg[0]);
		tprints(", ");

		printpath(tcp, tcp->u_arg[1]);
		tprints(", ");

		if (ignore_type && tcp->u_arg[2])
			tprintf("%#lx", tcp->u_arg[2]);
		else
			printstr(tcp, tcp->u_arg[2], -1);
		tprints(", ");

		printflags(mount_flags, tcp->u_arg[3], "MS_???");
		tprints(", ");

		if (ignore_data && tcp->u_arg[4])
			tprintf("%#lx", tcp->u_arg[4]);
		else
			printstr(tcp, tcp->u_arg[4], -1);
	}
	return 0;
}
예제 #28
0
static int
decode_open(struct tcb *tcp, int offset)
{
	printpath(tcp, tcp->u_arg[offset]);
	tprints(", ");
	/* flags */
	tprint_open_modes(tcp->u_arg[offset + 1]);
	if (tcp->u_arg[offset + 1] & O_CREAT) {
		/* mode */
		tprintf(", %#lo", tcp->u_arg[offset + 2]);
	}

	return RVAL_DECODED | RVAL_FD;
}
예제 #29
0
파일: dijkstra.c 프로젝트: malikvivek/Work
int main(){
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);
	int graph[15][15],pathestimate[15],mark[15],s[15];
	int num_of_vertices,source,i,j,u,predecessor[15];
	int count=0;
	printf("enter the no.of vertices :");
	scanf("%d",&num_of_vertices);
	if(num_of_vertices<=0){
		printf("\nthis is meaningless\n");
		exit(1);
	}
	printf("\nenter the cost matrix\n");
    for(i=1;i<=num_of_vertices;i++){
    	printf("\nenter the elements of row %d\n",i);
    	for(j=1;j<=num_of_vertices;j++){
    		scanf("%d",&graph[i][j]);
    	}
    }
    printf("\nenter the source vertex\n");
    scanf("%d",&source);
    for(j=1;j<=num_of_vertices;j++){
    	mark[j]=0;
    	pathestimate[j]=INT_MAX;
    	predecessor[j]=0;
    }
    pathestimate[source]=0;
    while(count<num_of_vertices){
    	u=minimum(pathestimate,mark,num_of_vertices);
    	s[++count]=u;
    	mark[u]=1;
    	for(i=1;i<=num_of_vertices;i++){
    		if(graph[u][i]>0){
    			if(mark[i]!=1){
    				if(pathestimate[i]>pathestimate[u]+graph[u][i]){
    					pathestimate[i]=pathestimate[u]+graph[u][i];
    					predecessor[i]=u;
    				}
    			}
    		}
    	}
    }
    for(i=1;i<=num_of_vertices;i++){
    	printpath(source,i,predecessor);
    	if(pathestimate[i]!=INT_MAX){
    		printf("->(%d)\n",pathestimate[i]);
    	}
    }
 return(0);
}
예제 #30
0
static int
decode_open(struct tcb *tcp, int offset)
{
	printpath(tcp, tcp->u_arg[offset]);
	tprints(", ");
	/* flags */
	tprint_open_modes(tcp->u_arg[offset + 1]);
	if (tcp->u_arg[offset + 1] & (O_CREAT | STRACE_O_TMPFILE)) {
		/* mode */
		tprints(", ");
		print_numeric_umode_t(tcp->u_arg[offset + 2]);
	}

	return RVAL_DECODED | RVAL_FD;
}