14abfe47eSSiva Chandra Reddy //===-- Implementation of creat -------------------------------------------===// 24abfe47eSSiva Chandra Reddy // 34abfe47eSSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 44abfe47eSSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information. 54abfe47eSSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 64abfe47eSSiva Chandra Reddy // 74abfe47eSSiva Chandra Reddy //===----------------------------------------------------------------------===// 84abfe47eSSiva Chandra Reddy 94abfe47eSSiva Chandra Reddy #include "src/fcntl/creat.h" 104abfe47eSSiva Chandra Reddy 114abfe47eSSiva Chandra Reddy #include "src/__support/OSUtil/syscall.h" // For internal syscall function. 124abfe47eSSiva Chandra Reddy #include "src/__support/common.h" 135ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 14d49b993fSSiva Chandra Reddy #include "src/errno/libc_errno.h" 154abfe47eSSiva Chandra Reddy 16*abc49cc1SJob Henandez Lara #include "hdr/fcntl_macros.h" 174abfe47eSSiva Chandra Reddy #include <sys/syscall.h> // For syscall numbers. 184abfe47eSSiva Chandra Reddy 195ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 204abfe47eSSiva Chandra Reddy 214abfe47eSSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, creat, (const char *path, int mode_flags)) { 220e91c48dSSiva Chandra #ifdef SYS_open 23b6bc9d72SGuillaume Chatelet int fd = LIBC_NAMESPACE::syscall_impl<int>( 24f0a3954eSMichael Jones SYS_open, path, O_CREAT | O_WRONLY | O_TRUNC, mode_flags); 250e91c48dSSiva Chandra #else 26b6bc9d72SGuillaume Chatelet int fd = LIBC_NAMESPACE::syscall_impl<int>( 27f0a3954eSMichael Jones SYS_openat, AT_FDCWD, path, O_CREAT | O_WRONLY | O_TRUNC, mode_flags); 280e91c48dSSiva Chandra #endif 290e91c48dSSiva Chandra 304abfe47eSSiva Chandra Reddy if (fd > 0) 314abfe47eSSiva Chandra Reddy return fd; 324abfe47eSSiva Chandra Reddy 33d49b993fSSiva Chandra Reddy libc_errno = -fd; 344abfe47eSSiva Chandra Reddy return -1; 354abfe47eSSiva Chandra Reddy } 364abfe47eSSiva Chandra Reddy 375ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 38