rmdir.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu/***********************************************************************
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* *
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance* This software is part of the ast package *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* Copyright (c) 1985-2011 AT&T Intellectual Property *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* and is licensed under the *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* Eclipse Public License, Version 1.0 *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* by AT&T Intellectual Property *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* A copy of the License is available at *
c038fcf2030a6cfac7a261dee48a9eb29edb78eaFelix Gabriel Mance* http://www.eclipse.org/org/documents/epl-v10.html *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance* *
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance* Information and Software Systems Research *
c038fcf2030a6cfac7a261dee48a9eb29edb78eaFelix Gabriel Mance* AT&T Research *
c038fcf2030a6cfac7a261dee48a9eb29edb78eaFelix Gabriel Mance* Florham Park NJ *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* Glenn Fowler <gsf@research.att.com> *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* David Korn <dgk@research.att.com> *
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu* Phong Vo <kpv@research.att.com> *
ed1b8e97e72b2e3e92edaf2eb22a4b5373d705f1Felix Gabriel Mance* *
5180a08007989fd364622fc9bc01f82141643f7bFelix Gabriel Mance***********************************************************************/
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu#pragma prototyped
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance
c038fcf2030a6cfac7a261dee48a9eb29edb78eaFelix Gabriel Mance#include <ast.h>
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu#if _lib_rmdir
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel ManceNoN(rmdir)
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance#else
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance#include <ls.h>
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance#include <error.h>
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Mance
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Manceint
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mancermdir(const char* path)
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance{
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance register int n;
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance struct stat st;
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance char* av[3];
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance static char* cmd[] = { "/bin/rmdir", "/usr/5bin/rmdir", 0 };
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu if (stat(path, &st) < 0) return(-1);
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu if (!S_ISDIR(st.st_mode))
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance {
ccb84c1cb43fb0ed70c5bf2d364e671820473ed5Francisc Nicolae Bungiu errno = ENOTDIR;
dda7065c0c0f383558d7d4e8072969c8c41a8ed7Francisc Nicolae Bungiu return(-1);
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance }
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance av[0] = "rmdir";
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance av[1] = path;
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance av[2] = 0;
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance for (n = 0; n < elementsof(cmd); n++)
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance if (procclose(procopen(cmd[n], av, NiL, NiL, 0)) != -1)
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance break;
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance n = errno;
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance if (access(path, F_OK) < 0)
734257b9ea9fcaa18d4e3627f54f5295a99aa1f7Felix Gabriel Mance {
31a5ba51cd6d24e28a23abf64ce4043a45eabbefFelix Gabriel Mance errno = n;
8e1b180fc839e96d7a4f1f63dfc563c75139c683Francisc Nicolae Bungiu return(0);
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance }
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance errno = EPERM;
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance return(-1);
c4076ff1721f8901a30e4b7aa004479ecb2631e0Felix Gabriel Mance}
dda7065c0c0f383558d7d4e8072969c8c41a8ed7Francisc Nicolae Bungiu
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance#endif
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance