1
0
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:
Nick Briggs 2022-03-18 18:20:35 -07:00 committed by GitHub
parent b005501427
commit 90b967c8d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);