mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	Kernel+LibC: Implement the openat() syscall
POSIX's openat() is very similar to open(), except you also provide a file descriptor referring to a directory from which relative paths should be resolved. Passing it the magical fd number AT_FDCWD means "resolve from current directory" (which is indeed also what open() normally does.) This fixes libarchive's bsdtar, since it was trying to do something extremely wrong in the absence of openat() support. The issue has recently been fixed upstream in libarchive: https://github.com/libarchive/libarchive/issues/1239 However, we should have openat() support anyway, so I went ahead and implemented it. :^) Fixes #748.
This commit is contained in:
		
							parent
							
								
									4f27745136
								
							
						
					
					
						commit
						18348cebf1
					
				
					 6 changed files with 80 additions and 7 deletions
				
			
		|  | @ -189,6 +189,17 @@ int open_with_path_length(const char* path, size_t path_length, int options, mod | |||
|     __RETURN_WITH_ERRNO(rc, rc, -1); | ||||
| } | ||||
| 
 | ||||
| int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t mode) | ||||
| { | ||||
|     if (path_length > INT32_MAX) { | ||||
|         errno = EINVAL; | ||||
|         return -1; | ||||
|     } | ||||
|     Syscall::SC_openat_params params { dirfd, path, (int)path_length, options, mode }; | ||||
|     int rc = syscall(SC_openat, ¶ms); | ||||
|     __RETURN_WITH_ERRNO(rc, rc, -1); | ||||
| } | ||||
| 
 | ||||
| int open(const char* path, int options, ...) | ||||
| { | ||||
|     va_list ap; | ||||
|  | @ -198,6 +209,15 @@ int open(const char* path, int options, ...) | |||
|     return open_with_path_length(path, strlen(path), options, mode); | ||||
| } | ||||
| 
 | ||||
| int openat(int dirfd, const char* path, int options, ...) | ||||
| { | ||||
|     va_list ap; | ||||
|     va_start(ap, options); | ||||
|     auto mode = (mode_t)va_arg(ap, unsigned); | ||||
|     va_end(ap); | ||||
|     return openat_with_path_length(dirfd, path, strlen(path), options, mode); | ||||
| } | ||||
| 
 | ||||
| ssize_t read(int fd, void* buf, size_t count) | ||||
| { | ||||
|     int rc = syscall(SC_read, fd, buf, count); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling