Example #1
0
void rm_tree(btnode tr, int ispointer) {
	if(!tr);
	else {
		rm_tree(tr->lsubtr, ispointer);
		rm_tree(tr->rsubtr, ispointer);
		if(ispointer)
			free(tr->data);
		free(tr);
	}
}
Example #2
0
/* delsubtr: delete subtree
 * return -1 if we didnt find node */
int del_subtr (bintree tree, Telemtype entry) {

	int comp;
	btnode tr = tree->root;
	btnode parent = tr;
	while(tr) {
		comp = compare(entry, tr->data);
		switch (comp) {
		case 0:
			rm_tree(tr,tree->ispntr);
			if (parent) {					//change parent node 
				parent->lsubtr = (parent->lsubtr == tr) ? NULL : parent->lsubtr;
				parent->rsubtr = (parent->lsubtr == tr) ? NULL : parent->rsubtr;
			}
			/* delete completed */
			return 0;
			break;
		case 1:
			tr = tr->rsubtr;
			break;
		case -1:
			tr = tr->lsubtr;
			break;
		}
	}
	/* Could not find exact point, return 0 */
	return -1;
}
Example #3
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
main(int argc, char *argv[])
{
	int ch, rflag;

	setlocale(LC_ALL, "");

	Pflag = rflag = 0;
	while ((ch = getopt(argc, argv, "dfiPRr")) != -1)
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (Pflag) {
		if (pledge("stdio rpath wpath cpath getpw", NULL) == -1)
			err(1, "pledge");
	} else {
		if (pledge("stdio rpath cpath getpw", NULL) == -1)
			err(1, "pledge");
	}

	if (argc < 1 && fflag == 0)
		usage();

	checkdot(argv);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		if (rflag)
			rm_tree(argv);
		else
			rm_file(argv);
	}

	exit(eval);
}
Example #4
0
main(int argc,
	char *argv[])
#endif
{
	int ch, rflag;

#if defined(__GNO__)  &&  defined(__STACK_CHECK__)
	_beginStackCheck();
	atexit(report_stack);
#endif
	rflag = 0;
	while ((ch = getopt(argc, argv, "dfiPRr")) != EOF)
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
#ifndef __ORCAC__
	argv += optind;
#else
	argv = argv + optind;
#endif

	if (argc < 1)
		usage();

	checkdot(argv);
	if (!*argv)
		exit (eval);

	stdin_ok = isatty(STDIN_FILENO);
	uid = geteuid();

	if (rflag)
		rm_tree(argv);
	else
		rm_file(argv);
	exit (eval);
}
Example #5
0
File: rm.c Project: Open343/bitrig
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
rmmain(int argc, char *argv[])
{

	checkdot(argv);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		rm_tree(argv);
	}

	return (eval);
}
Example #6
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
main(int argc, char *argv[])
{
	int ch, rflag;

	setprogname(argv[0]);
	(void)setlocale(LC_ALL, "");

	Pflag = rflag = xflag = 0;
	while ((ch = getopt(argc, argv, "dfiPRrvWx")) != -1)
		switch (ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
		case 'x':
			xflag = 1;
			break;
#ifndef __ANDROID__
		case 'W':
			Wflag = 1;
			break;
#endif
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc < 1) {
		if (fflag)
			return 0;
		usage();
	}

	(void)signal(SIGINFO, progress);

	checkdot(argv);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		if (rflag)
			rm_tree(argv);
		else
			rm_file(argv);
	}

	exit(eval);
	/* NOTREACHED */
}
Example #7
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.	The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 *	file removal.
 */
int
main(int argc, char *argv[])
{
    int ch;
    char *p;

    (void)setlocale(LC_ALL, "");

    /*
     * Test for the special case where the utility is called as
     * "unlink", for which the functionality provided is greatly
     * simplified.
     */
    if ((p = strrchr(argv[0], '/')) == NULL)
        p = argv[0];
    else
        ++p;
    if (strcmp(p, "unlink") == 0) {
        while (getopt(argc, argv, "") != -1)
            usage();
        argc -= optind;
        argv += optind;
        if (argc != 1)
            usage();
        rm_file(&argv[0]);
        exit(eval);
    }

    Pflag = rflag = xflag = 0;
    while ((ch = getopt(argc, argv, "dfiIPRrvWx")) != -1)
        switch(ch) {
        case 'd':
            dflag = 1;
            break;
        case 'f':
            fflag = 1;
            iflag = 0;
            break;
        case 'i':
            fflag = 0;
            iflag = 1;
            break;
        case 'I':
            Iflag = 1;
            break;
        case 'P':
            Pflag = 1;
            break;
        case 'R':
        case 'r':			/* Compatibility. */
            rflag = 1;
            break;
        case 'v':
            vflag = 1;
            break;
        case 'W':
            Wflag = 1;
            break;
        case 'x':
            xflag = 1;
            break;
        default:
            usage();
        }
    argc -= optind;
    argv += optind;

    if (argc < 1) {
        if (fflag)
            return (0);
        usage();
    }

    checkdot(argv);
    checkslash(argv);
    uid = geteuid();

    (void)signal(SIGINFO, siginfo);
    if (*argv) {
        stdin_ok = isatty(STDIN_FILENO);

        if (Iflag) {
            if (check2(argv) == 0)
                exit (1);
        }
        if (rflag)
            rm_tree(argv);
        else
            rm_file(argv);
    }

    exit (eval);
}
Example #8
0
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
main(int argc, char *argv[])
{
	int ch;
	const char *p;
	pid_t tty_pgrp;

	/*
	 * Test for the special case where the utility is called as
	 * "unlink", for which the functionality provided is greatly
	 * simplified.
	 */
	if ((p = strrchr(argv[0], '/')) == NULL)
		p = argv[0];
	else
		++p;
	if (strcmp(p, "unlink") == 0) {
		while (getopt(argc, argv, "") != -1)
			usage();
		argc -= optind;
		argv += optind;
		if (argc != 1)
			usage();
		rm_file(&argv[0]);
		exit(eval);
	}

	Pflag = rflag = 0;
	while ((ch = getopt(argc, argv, "dfiIPRrvW")) != -1) {
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'I':
			/*
			 * The -I flag is intended to be generally aliasable
			 * in /etc/csh.cshrc.  We apply it only to foreground
			 * processes.
			 */
			if (ioctl(0, TIOCGPGRP, &tty_pgrp) == 0) {
				if (tty_pgrp == getpgrp())
					Iflag = 1;
			}
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
		case 'W':
			Wflag = 1;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 1) {
		if (fflag)
			return 0;
		usage();
	}

	checkdot(argv);
	uid = geteuid();
	
	signal(SIGINFO, siginfo);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		if (Iflag && !iflag) {
			if (check2(argv) == 0)
				exit (1);
		}
		if (rflag)
			rm_tree(argv);
		else
			rm_file(argv);
	}

	exit (eval);
}
Example #9
0
/* del_tree: delete a tree
 * lazy soul edition */
void del_tree(bintree tr) {
	rm_tree(tr->root, tr->ispntr);
	/* this may leave a dangerous opertion here, when we try to visit tr after we free tr*/
	free(tr);

}
Example #10
0
File: rm.c Project: dezelin/kBuild
/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
kmk_builtin_rm(int argc, char *argv[], char **envp)
{
	int ch, rflag;

	/* reinitialize globals */
	argv0 = argv[0];
	dflag = eval = fflag = iflag = Pflag = vflag = Wflag = stdin_ok = 0;
	uid = 0;
	kBuildProtectionInit(&g_ProtData);

	/* kmk: reset getopt and set program name. */
	g_progname = argv[0];
	opterr = 1;
	optarg = NULL;
	optopt = 0;
	optind = 0; /* init */

	Pflag = rflag = 0;
	while ((ch = getopt_long(argc, argv, "dfiPRvW", long_options, NULL)) != -1)
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
#if 0
		case 'r':			/* Compatibility. */
#endif
			rflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
#ifdef FTS_WHITEOUT
		case 'W':
			Wflag = 1;
			break;
#endif
		case 261:
			kBuildProtectionTerm(&g_ProtData);
			usage(stdout);
			return 0;
		case 262:
			kBuildProtectionTerm(&g_ProtData);
			return kbuild_version(argv[0]);
		case 263:
			kBuildProtectionDisable(&g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE);
			break;
		case 264:
			kBuildProtectionEnable(&g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE);
			break;
		case 265:
			kBuildProtectionEnable(&g_ProtData, KBUILDPROTECTIONTYPE_FULL);
			break;
		case 266:
			kBuildProtectionDisable(&g_ProtData, KBUILDPROTECTIONTYPE_FULL);
			break;
		case 267:
			if (kBuildProtectionSetDepth(&g_ProtData, optarg)) {
			    kBuildProtectionTerm(&g_ProtData);
			    return 1;
			}
			break;
		case '?':
		default:
			kBuildProtectionTerm(&g_ProtData);
			return usage(stderr);
		}
	argc -= optind;
	argv += optind;

	if (argc < 1) {
		kBuildProtectionTerm(&g_ProtData);
		if (fflag)
			return (0);
		return usage(stderr);
	}

	if (!kBuildProtectionScanEnv(&g_ProtData, envp, "KMK_RM_")) {
		checkdot(argv);
		uid = geteuid();

		if (*argv) {
			stdin_ok = isatty(STDIN_FILENO);
			if (rflag)
				eval |= rm_tree(argv);
			else
				eval |= rm_file(argv);
		}
	} else {
		eval = 1;
	}

	kBuildProtectionTerm(&g_ProtData);
	return eval;
}