Add removeat(3) and split remove(3) into its own file.
This commit is contained in:
parent
deeedf9e5d
commit
500d853f77
|
@ -187,6 +187,8 @@ raise.o \
|
||||||
rand.o \
|
rand.o \
|
||||||
readdirents.o \
|
readdirents.o \
|
||||||
read.o \
|
read.o \
|
||||||
|
removeat.o \
|
||||||
|
remove.o \
|
||||||
rmdir.o \
|
rmdir.o \
|
||||||
sbrk.o \
|
sbrk.o \
|
||||||
scanf.o \
|
scanf.o \
|
||||||
|
|
11
libc/fdio.c
11
libc/fdio.c
|
@ -207,14 +207,3 @@ FILE* fopen(const char* path, const char* mode)
|
||||||
if ( !fp ) { close(fd); return NULL; }
|
if ( !fp ) { close(fd); return NULL; }
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int remove(const char* pathname)
|
|
||||||
{
|
|
||||||
int result = unlink(pathname);
|
|
||||||
if ( result && errno == EISDIR )
|
|
||||||
{
|
|
||||||
// TODO: rmdir is unimplemented.
|
|
||||||
// result = rmdir(pathname);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ extern int printf(const char* restrict format, ...);
|
||||||
extern int putc(int c, FILE* stream);
|
extern int putc(int c, FILE* stream);
|
||||||
extern int putchar(int c);
|
extern int putchar(int c);
|
||||||
extern int puts(const char* str);
|
extern int puts(const char* str);
|
||||||
|
extern int removeat(int dirrfd, const char* path);
|
||||||
extern int remove(const char* path);
|
extern int remove(const char* path);
|
||||||
extern int rename(const char* oldname, const char* newname);
|
extern int rename(const char* oldname, const char* newname);
|
||||||
extern void rewind(FILE* stream);
|
extern void rewind(FILE* stream);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue