version 1.0 of rmdir for GNO

This commit is contained in:
gdr 1996-01-28 00:51:56 +00:00
parent 73ce022151
commit a1e9154b96
5 changed files with 193 additions and 0 deletions

23
bin/rmdir/makefile.mk Normal file
View File

@ -0,0 +1,23 @@
# 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

31
bin/rmdir/rmdir.1 Normal file
View File

@ -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, <gdr@myrias.ab.ca>
.SH "SEE ALSO"
.BR cp (1),
.BR rm (1).

32
bin/rmdir/rmdir.2 Normal file
View File

@ -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, <gdr@myrias.ab.ca>
.SH "SEE ALSO"
.BR mkdir (2),
.BR unlink (2).

8
bin/rmdir/rmdir.DESCRIBE Normal file
View File

@ -0,0 +1,8 @@
Name: rmdir
Version: 1.0 (28 Nov 94)
Author: Devin Reade.
Contact: <gdr@myrias.ab.ca>
Where: /bin
FTP: cco.caltech.edu, grind.isca.uiowa.edu
Remove empty directories.

99
bin/rmdir/rmdir.c Normal file
View File

@ -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 <gdr@myrias.ab.ca>
*/
#include <gsos.h>
#include <orca.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#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<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
return result;
}
#endif /* SHELL_COMD */