mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:12:44 +00:00 
			
		
		
		
	 7c87891c06
			
		
	
	
		7c87891c06
		
	
	
	
	
		
			
			Instead of copying a Vector everytime we need to enumerate a Process' file descriptions, we can just temporarily lock so it won't change.
		
			
				
	
	
		
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <Kernel/FileSystem/FileDescription.h>
 | |
| #include <Kernel/Process.h>
 | |
| #include <Kernel/TTY/MasterPTY.h>
 | |
| #include <Kernel/TTY/TTY.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| KResultOr<FlatPtr> Process::sys$ttyname(int fd, Userspace<char*> buffer, size_t size)
 | |
| {
 | |
|     REQUIRE_PROMISE(tty);
 | |
|     auto description = fds().file_description(fd);
 | |
|     if (!description)
 | |
|         return EBADF;
 | |
|     if (!description->is_tty())
 | |
|         return ENOTTY;
 | |
|     auto tty_name = description->tty()->tty_name();
 | |
|     if (size < tty_name.length() + 1)
 | |
|         return ERANGE;
 | |
|     if (!copy_to_user(buffer, tty_name.characters(), tty_name.length() + 1))
 | |
|         return EFAULT;
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| KResultOr<FlatPtr> Process::sys$ptsname(int fd, Userspace<char*> buffer, size_t size)
 | |
| {
 | |
|     REQUIRE_PROMISE(tty);
 | |
|     auto description = fds().file_description(fd);
 | |
|     if (!description)
 | |
|         return EBADF;
 | |
|     auto* master_pty = description->master_pty();
 | |
|     if (!master_pty)
 | |
|         return ENOTTY;
 | |
|     auto pts_name = master_pty->pts_name();
 | |
|     if (size < pts_name.length() + 1)
 | |
|         return ERANGE;
 | |
|     if (!copy_to_user(buffer, pts_name.characters(), pts_name.length() + 1))
 | |
|         return EFAULT;
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| }
 |