1 //===-- Linux implementation of mkdir -------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/sys/stat/mkdir.h" 10 11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function. 12 #include "src/__support/common.h" 13 14 #include <errno.h> 15 #include <sys/stat.h> 16 #include <sys/syscall.h> // For syscall numbers. 17 18 namespace __llvm_libc { 19 20 LLVM_LIBC_FUNCTION(int, mkdir, (const char *path, mode_t mode)) { 21 #ifdef SYS_mkdir 22 long ret = __llvm_libc::syscall(SYS_mkdir, path, mode); 23 #elif defined(SYS_unlinkat) 24 long ret = __llvm_libc::syscall(SYS_mkdirat, AT_FDCWD, path, mode); 25 #else 26 #error "mkdir and mkdirat syscalls not available." 27 #endif 28 29 if (ret < 0) { 30 errno = -ret; 31 return -1; 32 } 33 return 0; 34 } 35 36 } // namespace __llvm_libc 37