modified to fit into GNO base build

This commit is contained in:
gdr
1997-10-30 02:33:49 +00:00
parent 24b9cda931
commit b9c3d5d27d
7 changed files with 179 additions and 146 deletions

12
bin/rmdir/Makefile Normal file
View File

@@ -0,0 +1,12 @@
#
# $Id: Makefile,v 1.1 1997/10/30 02:33:48 gdr Exp $
#
PROG = rmdir
# Add -D__STACK_CHECK__ to CFLAGS to get stack usage information
CFLAGS += -I/src/gno/lib/libcontrib
LDFLAGS += -l/src/gno/lib/libcontrib/libcontrib
STACK = 768
.INCLUDE: /src/gno/prog.mk

View File

@@ -1,23 +0,0 @@
# Makefile for rmdir(1) and rmdir(3) v1.0
#
# Devin Reade, <gdr@myrias.ab.ca> November 1994.
#
# Define:
# SHELL_COMD if you want to compile the shell command version.
# In this case, do a 'make rmdir'. If you want just
# the rmdir(3) library routine, don't define
# SHELL_COMD and do a 'make rmdir.o'
#
# CHECK_STACK if you want to determine stack usage. If you select
# This option, you must also specify the stack library,
# nominally -l/usr/lib/stack.
CFLAGS = -w -O -DSHELL_COMD -v -s768
LDFLAGS = -v
all: rmdir
install:
cp -f rmdir /bin
cp -f rmdir.1 /usr/man/man1
cp -f rmdir.2 /usr/man/man2

View File

@@ -1,11 +1,17 @@
.TH RMDIR 1 "Commands and Applications" "28 November 1994" "Version 1.0" .\"
.\" Devin Reade, 1994
.\"
.\" $Id: rmdir.1,v 1.2 1997/10/30 02:33:49 gdr Exp $
.\"
.TH RMDIR 1 "17 October 1997" GNO "Commands and Applications"
.SH NAME .SH NAME
rmdir \- remove (delete) a directory rmdir \- remove (delete) a directory
.SH SYNOPSIS .SH SYNOPSIS
.BR rmdir .BR rmdir
[ [
.IR dir " ..." .BR -p
] ]
.IR dir " ..."
.SH DESCRIPTION .SH DESCRIPTION
.BR rmdir .BR rmdir
will delete all the listed directories. will delete all the listed directories.
@@ -15,17 +21,32 @@ will print an error and skip the file if
is not a directory, is non-empty, or if the user does not is not a directory, is non-empty, or if the user does not
have permission to delete it. have permission to delete it.
.LP .LP
This program contains material from the ORCA/C run\-time libraries, If the
Copyright 1987\-1994 Byte Works Inc. Used with permission. .BR -p
.SH "EXIT STATUS" flag is given, then
.BR rmdir .BR rmdir
will have an exit status of zero on success, -1 on failure. will attempt to recursively delete all empty directories in the pathname
.IR dir ,
not including the volume name (if given).
.SH BUGS .SH BUGS
It is possible to delete the current directory of It is possible to delete the current directory of
.B rmdir .B rmdir
or another process. or another process.
.SH VERSION
This manual page documents
.BR rmdir
version 1.1.
.SH STANDARDS
The
.BR rmdir
utility corresponds to POSIX 1003.2.
.SH AUTHOR .SH AUTHOR
Devin Reade, <gdr@myrias.ab.ca> Devin Reade, <gdr@myrias.ab.ca>
.LP
This program contains material from the ORCA/C run\-time libraries,
Copyright 1987\-1997 Byte Works Inc. Used with permission.
.SH "SEE ALSO" .SH "SEE ALSO"
.BR cp (1), .BR cp (1),
.BR rm (1). .BR rm (1),
.BR rmdir (1),
.BR rmdir (2).

View File

@@ -1,32 +0,0 @@
.TH RMDIR 2 "System Calls" "28 November 1994" "Version 1.0"
.SH NAME
rmdir \- remove (delete) a directory
.SH SYNOPSIS
int \fBrmdir\fR (const char *\fIpath\fR);
.SH DESCRIPTION
.BR rmdir
will remove the directory named by
.I path
if the directory is empty, if it is not a mount point, and if the calling
process has write permission in the parent directory. The directory is
considered empty when it contains only
.B .
and
.B ..
entries.
.SH "RETURN VALUE"
0 if successful, -1 and sets
.B errno
otherwise.
.SH BUGS
Since
.BR rmdir
is not yet implemented as a system call but as a library call, it is
possible to delete a directory which is being used by a process, including
that of
.BR rmdir .
.SH AUTHOR
Devin Reade, <gdr@myrias.ab.ca>
.SH "SEE ALSO"
.BR mkdir (2),
.BR unlink (2).

View File

@@ -1,99 +1,136 @@
/* /*
* rmdir - remove directory * rmdir - remove directory
* *
* A quick and dirty utility for Gno. This will delete all empty * ChangeLog:
* directories given as arguments. It will skip non-directory files * v1.1 - incorporated into GNO base distribution
* directories that aren't empty. * - added -p flag for POSIX conformance
* - moved rmdir(2) implementation to libc
* v1.0 - initial revision
* *
* If you don't compile with #define SHELL_COMD, then you just get the * Version 1.1 by Devin Reade <gdr@myrias.ab.ca>
* rmdir(2) system call.
*
* Version 1.0 by Devin Reade <gdr@myrias.ab.ca>
*/ */
#include <gsos.h> #include <types.h>
#include <orca.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <string.h>
#include <unistd.h>
#include <err.h>
#include <gno/gno.h>
#define DIRECTORY 0x0F #include "contrib.h"
extern GSString255Ptr __C2GSMALLOC(char *); #ifdef __STACK_CHECK__
extern int _mapErr(int); static void
extern char *strerror(int errnum); printStack (void) {
extern void begin_stack_check(void); fprintf(stderr, "stack usage: %d bytes\n", _endStackCheck());
extern int end_stack_check(void);
typedef struct DestroyRecGS {
Word pCount;
GSString255Ptr pathname;
} DestroyRecGS, *DestroyRecPtrGS;
int rmdir (const char *path) {
DestroyRecGS drec;
FileInfoRecGS frec;
int result;
/* make a GSString copy of path */
frec.pCount=3;
if ((frec.pathname = __C2GSMALLOC(path)) == NULL) {
errno = ENOMEM;
return -1;
}
/* check to ensure that it's a directory */
GetFileInfoGS(&frec);
if ((result = toolerror())!=0) {
errno = _mapErr(result);
free(frec.pathname);
return -1;
}
if (frec.fileType != DIRECTORY) {
errno = ENOTDIR;
free(frec.pathname);
return -1;
}
/* it's a directory; try to delete it */
drec.pCount=1;
drec.pathname = frec.pathname;
DestroyGS(&drec);
if ((result = toolerror())!=0) {
errno = _mapErr(result);
free(frec.pathname);
return -1;
}
/* it's been deleted. Clean up and return */
free(frec.pathname);
return 0;
} }
#ifdef SHELL_COMD
int main(int argc, char **argv) {
int i, result;
#ifdef CHECK_STACK
begin_stack_check();
#endif
result = 0;
for (i=1; i<argc; i++) { /* loop over all filenames */
if (rmdir(argv[i])!=0) {
fprintf(stderr,"%s: %s: %s. File skipped.\n",argv[0],argv[i],
strerror(errno));
result = 1;
}
}
#ifdef CHECK_STACK
fprintf(stderr,"stack usage: %d bytes\n",end_stack_check());
#endif #endif
return result; static void
usage (void) {
fprintf(stderr, "usage: rmdir [-p] directory ...\n");
exit(1);
} }
#endif /* SHELL_COMD */ const char *nodup = "couldn't duplicate %s";
int
main(int argc, char **argv) {
int c, result, pflag;
char delim, *path, *root, *p, *q;
#ifdef __STACK_CHECK__
_beginStackCheck();
atexit(printStack);
#endif
pflag = 0;
while ((c = getopt (argc, argv, "p")) != EOF) {
switch (c) {
case 'p':
pflag = 1;
break;
default:
usage();
}
}
if ((argc - optind) == 0) {
usage();
}
result = 0;
/* loop over all filenames */
for (; optind<argc; optind++) {
path = argv[optind];
if (pflag == 0) {
/*
* Just do the last directory component, and
* skip the mess below
*/
if (rmdir(path)!=0) {
warn("%s skipped", path);
result++;
}
} else {
/* get the full pathname */
if ((path = LC_ExpandPath (path)) == NULL) {
warn("couldn't expand %s", argv[optind]);
continue;
}
if ((q = strdup(path)) == NULL) {
err(1, nodup, path);
}
path = q;
/* what is the volume component? */
q = (*path == ':') ? path+1 : path;
q = strchr(q, ':');
if (q != NULL) {
*q = '\0';
}
if (*path == ':') {
if ((root = strdup(path)) == NULL) {
err(1, nodup, path);
}
} else {
root = NULL;
}
if (q != NULL) {
*q = ':';
}
for(;;) {
if (*path == '\0') {
/* deleted all the directories */
break;
}
if ((root != NULL) && !strcmp(root, path)) {
/* don't try to delete the volume */
break;
}
if (rmdir(path)!=0) {
warn("%s skipped", path);
result++;
break;
}
p = path + strlen(path) - 1;
while (p >= path) {
if (*p == ':') {
*p = '\0';
break;
} else {
*p-- = '\0';
}
}
}
}
}
return result;
}

18
bin/rmdir/rmdir.rez Normal file
View File

@@ -0,0 +1,18 @@
/*
* $Id: rmdir.rez,v 1.1 1997/10/30 02:33:49 gdr Exp $
*/
#include "Types.Rez"
resource rVersion (0x1, purgeable3, nocrossbank) {
{ 1, 1, 0, /* version 1.1.0 */
release, /* development|alpha|beta|final|release */
0 /* non-final release number */
},
verUS,
"rmdir",
"remove (empty) directory\n"
"Devin Reade <gdr@eddore.myrias.com>\n"
"Canada"
};