2022-01-31 17:32:07 +00:00
|
|
|
//===-- Linux implementation of mkdir -------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "src/sys/stat/mkdir.h"
|
|
|
|
|
|
|
|
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
|
|
|
#include "src/__support/common.h"
|
|
|
|
|
2023-03-01 17:41:02 +00:00
|
|
|
#include "src/errno/libc_errno.h"
|
2022-01-31 22:17:44 -08:00
|
|
|
#include <fcntl.h>
|
2022-01-31 17:32:07 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/syscall.h> // For syscall numbers.
|
|
|
|
|
|
|
|
namespace __llvm_libc {
|
|
|
|
|
|
|
|
LLVM_LIBC_FUNCTION(int, mkdir, (const char *path, mode_t mode)) {
|
|
|
|
#ifdef SYS_mkdir
|
2023-08-02 16:30:26 -07:00
|
|
|
int ret = __llvm_libc::syscall_impl<int>(SYS_mkdir, path, mode);
|
2022-02-08 17:09:12 +00:00
|
|
|
#elif defined(SYS_mkdirat)
|
2023-08-02 16:30:26 -07:00
|
|
|
int ret = __llvm_libc::syscall_impl<int>(SYS_mkdirat, AT_FDCWD, path, mode);
|
2022-01-31 17:32:07 +00:00
|
|
|
#else
|
|
|
|
#error "mkdir and mkdirat syscalls not available."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2023-03-01 17:41:02 +00:00
|
|
|
libc_errno = -ret;
|
2022-01-31 17:32:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __llvm_libc
|