示例#1
0
文件: rm.c 项目: ajinkya93/OpenBSD
/*
 * 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);
}
示例#2
0
文件: rm.c 项目: GnoConsortium/gno
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);
}
示例#3
0
文件: rm.c 项目: 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);
}
示例#4
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 */
}
示例#5
0
文件: rm.c 项目: hmatyschok/MeshBSD
/*
 * 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);
}
示例#6
0
文件: rm.c 项目: Gwenio/DragonFlyBSD
/*
 * 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);
}
示例#7
0
文件: rm.c 项目: 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;
}