From a1e9154b9643ec726087b9b0c2c0c4b8ac9c225b Mon Sep 17 00:00:00 2001 From: gdr Date: Sun, 28 Jan 1996 00:51:56 +0000 Subject: [PATCH] version 1.0 of rmdir for GNO --- bin/rmdir/makefile.mk | 23 ++++++++++ bin/rmdir/rmdir.1 | 31 +++++++++++++ bin/rmdir/rmdir.2 | 32 +++++++++++++ bin/rmdir/rmdir.DESCRIBE | 8 ++++ bin/rmdir/rmdir.c | 99 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 bin/rmdir/makefile.mk create mode 100644 bin/rmdir/rmdir.1 create mode 100644 bin/rmdir/rmdir.2 create mode 100644 bin/rmdir/rmdir.DESCRIBE create mode 100644 bin/rmdir/rmdir.c diff --git a/bin/rmdir/makefile.mk b/bin/rmdir/makefile.mk new file mode 100644 index 0000000..4670508 --- /dev/null +++ b/bin/rmdir/makefile.mk @@ -0,0 +1,23 @@ +# 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 new file mode 100644 index 0000000..75adc7f --- /dev/null +++ b/bin/rmdir/rmdir.1 @@ -0,0 +1,31 @@ +.TH RMDIR 1 "Commands and Applications" "28 November 1994" "Version 1.0" +.SH NAME +rmdir \- remove (delete) a directory +.SH SYNOPSIS +.BR rmdir +[ +.IR dir " ..." +] +.SH DESCRIPTION +.BR rmdir +will delete all the listed directories. +.BR rmdir +will print an error and skip the file if +.I dir +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" +.BR rmdir +will have an exit status of zero on success, -1 on failure. +.SH BUGS +It is possible to delete the current directory of +.B rmdir +or another process. +.SH AUTHOR +Devin Reade, +.SH "SEE ALSO" +.BR cp (1), +.BR rm (1). diff --git a/bin/rmdir/rmdir.2 b/bin/rmdir/rmdir.2 new file mode 100644 index 0000000..9160f2b --- /dev/null +++ b/bin/rmdir/rmdir.2 @@ -0,0 +1,32 @@ +.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.DESCRIBE b/bin/rmdir/rmdir.DESCRIBE new file mode 100644 index 0000000..2a2edeb --- /dev/null +++ b/bin/rmdir/rmdir.DESCRIBE @@ -0,0 +1,8 @@ +Name: rmdir +Version: 1.0 (28 Nov 94) +Author: Devin Reade. +Contact: +Where: /bin +FTP: cco.caltech.edu, grind.isca.uiowa.edu + + Remove empty directories. diff --git a/bin/rmdir/rmdir.c b/bin/rmdir/rmdir.c new file mode 100644 index 0000000..f089088 --- /dev/null +++ b/bin/rmdir/rmdir.c @@ -0,0 +1,99 @@ +/* + * 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. + * + * If you don't compile with #define SHELL_COMD, then you just get the + * rmdir(2) system call. + * + * Version 1.0 by Devin Reade + */ + +#include +#include +#include +#include +#include + +#define DIRECTORY 0x0F + +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 SHELL_COMD + +int main(int argc, char **argv) { + int i, result; + +#ifdef CHECK_STACK + begin_stack_check(); +#endif + + result = 0; + for (i=1; i