diff --git a/bin/rmdir/Makefile b/bin/rmdir/Makefile new file mode 100644 index 0000000..9cb4878 --- /dev/null +++ b/bin/rmdir/Makefile @@ -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 diff --git a/bin/rmdir/makefile.mk b/bin/rmdir/makefile.mk deleted file mode 100644 index 4670508..0000000 --- a/bin/rmdir/makefile.mk +++ /dev/null @@ -1,23 +0,0 @@ -# Makefile for rmdir(1) and rmdir(3) v1.0 -# -# Devin Reade, 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 diff --git a/bin/rmdir/rmdir.1 b/bin/rmdir/rmdir.1 index 75adc7f..a508e01 100644 --- a/bin/rmdir/rmdir.1 +++ b/bin/rmdir/rmdir.1 @@ -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 rmdir \- remove (delete) a directory .SH SYNOPSIS .BR rmdir [ -.IR dir " ..." +.BR -p ] +.IR dir " ..." .SH DESCRIPTION .BR rmdir 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 have permission to delete it. .LP -This program contains material from the ORCA/C run\-time libraries, -Copyright 1987\-1994 Byte Works Inc. Used with permission. -.SH "EXIT STATUS" +If the +.BR -p +flag is given, then .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 It is possible to delete the current directory of .B rmdir 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 Devin Reade, +.LP +This program contains material from the ORCA/C run\-time libraries, +Copyright 1987\-1997 Byte Works Inc. Used with permission. .SH "SEE ALSO" .BR cp (1), -.BR rm (1). +.BR rm (1), +.BR rmdir (1), +.BR rmdir (2). diff --git a/bin/rmdir/rmdir.2 b/bin/rmdir/rmdir.2 deleted file mode 100644 index 9160f2b..0000000 --- a/bin/rmdir/rmdir.2 +++ /dev/null @@ -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, -.SH "SEE ALSO" -.BR mkdir (2), -.BR unlink (2). diff --git a/bin/rmdir/rmdir.c b/bin/rmdir/rmdir.c index f089088..3780552 100644 --- a/bin/rmdir/rmdir.c +++ b/bin/rmdir/rmdir.c @@ -1,99 +1,136 @@ /* * rmdir - remove directory * - * A quick and dirty utility for Gno. This will delete all empty - * directories given as arguments. It will skip non-directory files - * directories that aren't empty. + * ChangeLog: + * v1.1 - incorporated into GNO base distribution + * - 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 - * rmdir(2) system call. - * - * Version 1.0 by Devin Reade + * Version 1.1 by Devin Reade */ -#include -#include +#include #include #include -#include +#include +#include +#include +#include -#define DIRECTORY 0x0F +#include "contrib.h" -extern GSString255Ptr __C2GSMALLOC(char *); -extern int _mapErr(int); -extern char *strerror(int errnum); -extern void begin_stack_check(void); -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 __STACK_CHECK__ +static void +printStack (void) { + fprintf(stderr, "stack usage: %d bytes\n", _endStackCheck()); } - -#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= path) { + if (*p == ':') { + *p = '\0'; + break; + } else { + *p-- = '\0'; + } + } + } + } + } + return result; +} diff --git a/bin/rmdir/rmdir.DESCRIBE b/bin/rmdir/rmdir.desc similarity index 100% rename from bin/rmdir/rmdir.DESCRIBE rename to bin/rmdir/rmdir.desc diff --git a/bin/rmdir/rmdir.rez b/bin/rmdir/rmdir.rez new file mode 100644 index 0000000..b02f69e --- /dev/null +++ b/bin/rmdir/rmdir.rez @@ -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 \n" + "Canada" +};