/*
Trash empty
To finish the trash trilogy, here's a program which empties the trash (most
of the code for this one is in the procedure). While programming this,
I very nearly deleted everything on my computer (forgot to skip ..
when
recursively deleting!), but fortunately another bug in the code stopped that
from happening.
Now it probably won't delete everything on your computer!
Today's procedure is rmallindir
.
*/
#include "procs-2019-10-05.c"
int main(void) {
extern char *getenv(const char *name);
char *home = getenv("HOME");
char *trash = sbrk(strlen(home) + strlen("/.trash") + 1);
long i;
for (i = 0; home[i]; i++) {
trash[i] = home[i];
}
trash[i++] = '/';
trash[i++] = '.';
trash[i++] = 't';
trash[i++] = 'r';
trash[i++] = 'a';
trash[i++] = 's';
trash[i++] = 'h';
trash[i++] = 0;
if (!rmallindir(trash)) {
const char *err = "An error occured while emptying the trash.";
write(stdout, err, (size_t)strlen(err));
return exitfailure;
}
return 0;
}