mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 04:02:44 +00:00 
			
		
		
		
	 1682f0b760
			
		
	
	
		1682f0b760
		
	
	
	
	
		
			
			SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
		
			
				
	
	
		
			51 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <Kernel/Debug.h>
 | |
| #include <Kernel/FileSystem/FileDescription.h>
 | |
| #include <Kernel/Process.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| KResultOr<int> Process::sys$fcntl(int fd, int cmd, u32 arg)
 | |
| {
 | |
|     REQUIRE_PROMISE(stdio);
 | |
|     dbgln_if(IO_DEBUG, "sys$fcntl: fd={}, cmd={}, arg={}", fd, cmd, arg);
 | |
|     auto description = file_description(fd);
 | |
|     if (!description)
 | |
|         return EBADF;
 | |
|     // NOTE: The FD flags are not shared between FileDescription objects.
 | |
|     //       This means that dup() doesn't copy the FD_CLOEXEC flag!
 | |
|     switch (cmd) {
 | |
|     case F_DUPFD: {
 | |
|         int arg_fd = (int)arg;
 | |
|         if (arg_fd < 0)
 | |
|             return EINVAL;
 | |
|         int new_fd = alloc_fd(arg_fd);
 | |
|         if (new_fd < 0)
 | |
|             return new_fd;
 | |
|         m_fds[new_fd].set(*description);
 | |
|         return new_fd;
 | |
|     }
 | |
|     case F_GETFD:
 | |
|         return m_fds[fd].flags();
 | |
|     case F_SETFD:
 | |
|         m_fds[fd].set_flags(arg);
 | |
|         break;
 | |
|     case F_GETFL:
 | |
|         return description->file_flags();
 | |
|     case F_SETFL:
 | |
|         description->set_file_flags(arg);
 | |
|         break;
 | |
|     case F_ISTTY:
 | |
|         return description->is_tty();
 | |
|     default:
 | |
|         return EINVAL;
 | |
|     }
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| }
 |