Going on
This commit is contained in:
parent
51aadc0f50
commit
a66b7d7108
36
src/rm.c
36
src/rm.c
|
@ -2,6 +2,8 @@
|
|||
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -34,9 +36,37 @@ static int _rm_error(char * message, int ret)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int _rm_do(Prefs * prefs, char * file)
|
||||
/* FIXME */
|
||||
static int _rm_confirm(char * message)
|
||||
{
|
||||
int c;
|
||||
|
||||
if((c = fgetc(stdin)) == EOF)
|
||||
return _rm_error("stdin", 0);
|
||||
fflush(stdin);
|
||||
return c == 'y';
|
||||
}
|
||||
|
||||
static int _rm_do(Prefs * prefs, char * file)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if(lstat(file, &st) != 0)
|
||||
{
|
||||
if(!(*prefs & PREFS_f))
|
||||
_rm_error(file, 0);
|
||||
return 1;
|
||||
}
|
||||
if(S_ISDIR(st.st_mode))
|
||||
{
|
||||
if(!(*prefs & PREFS_R))
|
||||
{
|
||||
fprintf(stderr, "%s%s%s", "rm: ", file,
|
||||
": Is a directory\n");
|
||||
return 0;
|
||||
}
|
||||
/* FIXME */
|
||||
}
|
||||
/* FIXME */
|
||||
if(unlink(file) != 0)
|
||||
return _rm_error(file, 2);
|
||||
return 0;
|
||||
|
@ -84,5 +114,7 @@ int main(int argc, char * argv[])
|
|||
}
|
||||
if(optind == argc)
|
||||
return _usage();
|
||||
if(!(prefs & PREFS_f) && isatty(0))
|
||||
prefs |= PREFS_i;
|
||||
return _rm(&prefs, argc-optind, &argv[optind]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user