add chown
This commit is contained in:
38
rm.c
38
rm.c
@@ -1,10 +1,7 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "util.h"
|
||||
|
||||
@@ -34,36 +31,11 @@ main(int argc, char *argv[])
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void rm(const char *path)
|
||||
void
|
||||
rm(const char *path)
|
||||
{
|
||||
if(remove(path) == 0)
|
||||
return;
|
||||
if(errno == ENOTEMPTY && rflag) {
|
||||
char *buf;
|
||||
long size;
|
||||
struct dirent *d;
|
||||
DIR *dp;
|
||||
|
||||
if((size = pathconf(".", _PC_PATH_MAX)) < 0)
|
||||
size = BUFSIZ;
|
||||
if(!(buf = malloc(size)))
|
||||
eprintf("malloc:");
|
||||
if(!getcwd(buf, size))
|
||||
eprintf("getcwd:");
|
||||
if(!(dp = opendir(path)))
|
||||
eprintf("opendir %s:", path);
|
||||
if(chdir(path) != 0)
|
||||
eprintf("chdir %s:", path);
|
||||
while((d = readdir(dp)))
|
||||
if(strcmp(d->d_name, ".") && strcmp(d->d_name, ".."))
|
||||
rm(d->d_name);
|
||||
|
||||
closedir(dp);
|
||||
if(chdir(buf) != 0)
|
||||
eprintf("chdir %s:", buf);
|
||||
if(remove(path) == 0)
|
||||
return;
|
||||
}
|
||||
if(!fflag)
|
||||
if(rflag)
|
||||
recurse(path, rm);
|
||||
if(remove(path) != 0 && !fflag)
|
||||
eprintf("remove %s:", path);
|
||||
}
|
||||
|
Reference in New Issue
Block a user