rmdir.c revision 4fce32e15d9c284a06aea2e40852f6674f03b63e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1995 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Rmdir(1) removes directory.
* If -p option is used, rmdir(1) tries to remove the directory
* and it's parent directories. It exits with code 0 if the WHOLE
* given path is removed and 2 if part of path remains.
* Results are printed except when -s is used.
*/
#include <stdio.h>
#include <libgen.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <locale.h>
int
{
char *prog;
unsigned int pathlen;
errflg = 0;
/* set effective uid, euid, to be same as real */
/* uid, ruid. Rmdir(2) checks search & write */
/* permissions for euid, but for compatibility */
/* the check must be done using ruid. */
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
char buf[80];
exit(1);
}
switch (c) {
case 'p':
pflag++;
break;
case 's':
sflag++;
break;
case '?':
errflg++;
break;
}
prog);
exit(2);
}
errno = 0;
while (argc--) {
/*
* -p option. Remove directory and parents.
* Prints results of removing
*/
if (pflag) {
exit(2);
}
/*
* rmdirp removes directory and parents
* rc != 0 implies only part of path removed
*/
switch (rc) {
case -1:
"Directory not empty");
else
break;
case -2:
break;
case -3:
"Can not remove current directory");
break;
}
" \"%s\": %s not removed; %s\n"),
}
continue;
}
/* No -p option. Remove only one directory */
switch (errno) {
case EEXIST:
break;
case ENOTDIR:
break;
case ENOENT:
break;
case EACCES:
"Search or write permission needed");
break;
case EBUSY:
"Directory is a mount point or in use");
break;
case EROFS:
break;
case EIO:
"I/O error accessing file system");
break;
case EINVAL:
"Can't remove current directory or ..");
break;
case EFAULT:
default:
break;
}
gettext("%s: directory \"%s\": %s\n"),
continue;
}
}
return (errno ? 2 : 0);
}