root/src/system/libroot/posix/stdio/remove.c
/*
 * Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de.
 * Distributed under the terms of the MIT License.
 */


#include <stdio.h>

#include <errno.h>

#include <errno_private.h>
#include <syscalls.h>


int
remove(const char* path)
{
        // TODO: find a better way that does not require two syscalls for directories
        int status = _kern_unlink(AT_FDCWD, path);
        if (status == B_IS_A_DIRECTORY)
                status = _kern_remove_dir(AT_FDCWD, path);

        if (status != B_OK) {
                __set_errno(status);
                return -1;
        }

        return status;
}