Add removeat(3) and split remove(3) into its own file.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-01-06 19:04:28 +01:00
parent deeedf9e5d
commit 500d853f77
5 changed files with 66 additions and 11 deletions

View File

@ -187,6 +187,8 @@ raise.o \
rand.o \
readdirents.o \
read.o \
removeat.o \
remove.o \
rmdir.o \
sbrk.o \
scanf.o \

View File

@ -207,14 +207,3 @@ FILE* fopen(const char* path, const char* mode)
if ( !fp ) { close(fd); return NULL; }
return fp;
}
int remove(const char* pathname)
{
int result = unlink(pathname);
if ( result && errno == EISDIR )
{
// TODO: rmdir is unimplemented.
// result = rmdir(pathname);
}
return result;
}

View File

@ -102,6 +102,7 @@ extern int printf(const char* restrict format, ...);
extern int putc(int c, FILE* stream);
extern int putchar(int c);
extern int puts(const char* str);
extern int removeat(int dirrfd, const char* path);
extern int remove(const char* path);
extern int rename(const char* oldname, const char* newname);
extern void rewind(FILE* stream);

31
libc/remove.cpp Normal file
View File

@ -0,0 +1,31 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
remove.cpp
Remove a file or directory.
*******************************************************************************/
#include <fcntl.h>
#include <stdio.h>
extern "C" int remove(const char* path)
{
return removeat(AT_FDCWD, path);
}

32
libc/removeat.cpp Normal file
View File

@ -0,0 +1,32 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
removeat.cpp
Remove a file or directory.
*******************************************************************************/
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
extern "C" int removeat(int dirfd, const char* path)
{
return unlinkat(dirfd, path, AT_REMOVEDIR | AT_REMOVEFILE);
}