mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-14 07:30:21 +00:00
Implement DELFILE for (empty) directories on the {unix} device (#409)
If the argument to DELFILE represents a directory on the {unix} device
either directly or through resolving to a full pathname via the connected
host/directory, and the directory is empty, then the directory will be deleted
and the deleted directory name will be returned. Will error if the
directory is not empty, and return NIL if the argument does not name a directory
or file.
This commit is contained in:
parent
b005501427
commit
90b967c8d3
17
src/ufs.c
17
src/ufs.c
@ -244,6 +244,7 @@ LispPTR UFS_getfilename(LispPTR *args)
|
||||
LispPTR UFS_deletefile(LispPTR *args)
|
||||
{
|
||||
char file[MAXPATHLEN], fbuf[MAXPATHLEN];
|
||||
struct stat sbuf;
|
||||
register int len, rval;
|
||||
|
||||
ERRSETJMP(NIL);
|
||||
@ -260,11 +261,21 @@ LispPTR UFS_deletefile(LispPTR *args)
|
||||
#else
|
||||
if (unixpathname(fbuf, file, 0, 0) == 0) return (NIL);
|
||||
#endif /* DOS */
|
||||
|
||||
/* check if we're operating on directory or file */
|
||||
TIMEOUT(rval = stat(file, &sbuf));
|
||||
if (rval == -1) {
|
||||
*Lisp_errno = errno;
|
||||
return (NIL);
|
||||
}
|
||||
/*
|
||||
* On UNIX device, all we have to do is just to unlink the file.
|
||||
* On UNIX device, all we have to do is just to unlink the file
|
||||
* or directory
|
||||
*/
|
||||
TIMEOUT(rval = unlink(file));
|
||||
if ((sbuf.st_mode & S_IFMT) == S_IFDIR) {
|
||||
TIMEOUT(rval = rmdir(file));
|
||||
} else {
|
||||
TIMEOUT(rval = unlink(file));
|
||||
}
|
||||
if (rval == -1) {
|
||||
*Lisp_errno = errno;
|
||||
return (NIL);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user