forked from Bananymous/banan-os
				
			LibC: Implement truncate
This commit is contained in:
		
							parent
							
								
									b75970958e
								
							
						
					
					
						commit
						31bcad2535
					
				|  | @ -150,7 +150,7 @@ namespace Kernel | ||||||
| 		BAN::ErrorOr<long> sys_seek(int fd, off_t offset, int whence); | 		BAN::ErrorOr<long> sys_seek(int fd, off_t offset, int whence); | ||||||
| 		BAN::ErrorOr<long> sys_tell(int fd); | 		BAN::ErrorOr<long> sys_tell(int fd); | ||||||
| 
 | 
 | ||||||
| 		BAN::ErrorOr<long> sys_truncate(int fd, off_t length); | 		BAN::ErrorOr<long> sys_ftruncate(int fd, off_t length); | ||||||
| 
 | 
 | ||||||
| 		BAN::ErrorOr<long> sys_fsync(int fd); | 		BAN::ErrorOr<long> sys_fsync(int fd); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1856,7 +1856,7 @@ namespace Kernel | ||||||
| 		return TRY(m_open_file_descriptors.tell(fd)); | 		return TRY(m_open_file_descriptors.tell(fd)); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	BAN::ErrorOr<long> Process::sys_truncate(int fd, off_t length) | 	BAN::ErrorOr<long> Process::sys_ftruncate(int fd, off_t length) | ||||||
| 	{ | 	{ | ||||||
| 		TRY(m_open_file_descriptors.truncate(fd, length)); | 		TRY(m_open_file_descriptors.truncate(fd, length)); | ||||||
| 		return 0; | 		return 0; | ||||||
|  |  | ||||||
|  | @ -74,7 +74,7 @@ __BEGIN_DECLS | ||||||
| 	O(SYS_LISTEN,			listen)			\ | 	O(SYS_LISTEN,			listen)			\ | ||||||
| 	O(SYS_PSELECT,			pselect)		\ | 	O(SYS_PSELECT,			pselect)		\ | ||||||
| 	O(SYS_PPOLL,			ppoll)			\ | 	O(SYS_PPOLL,			ppoll)			\ | ||||||
| 	O(SYS_TRUNCATE,			truncate)		\ | 	O(SYS_FTRUNCATE,		ftruncate)		\ | ||||||
| 	O(SYS_SMO_CREATE,		smo_create)		\ | 	O(SYS_SMO_CREATE,		smo_create)		\ | ||||||
| 	O(SYS_SMO_DELETE,		smo_delete)		\ | 	O(SYS_SMO_DELETE,		smo_delete)		\ | ||||||
| 	O(SYS_SMO_MAP,			smo_map)		\ | 	O(SYS_SMO_MAP,			smo_map)		\ | ||||||
|  |  | ||||||
|  | @ -157,9 +157,19 @@ off_t lseek(int fildes, off_t offset, int whence) | ||||||
| 	return syscall(SYS_SEEK, fildes, offset, whence); | 	return syscall(SYS_SEEK, fildes, offset, whence); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | int truncate(const char* path, off_t length) | ||||||
|  | { | ||||||
|  | 	const int fd = open(path, O_WRONLY); | ||||||
|  | 	if (fd == -1) | ||||||
|  | 		return -1; | ||||||
|  | 	int ret = ftruncate(fd, length); | ||||||
|  | 	close(fd); | ||||||
|  | 	return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int ftruncate(int fildes, off_t length) | int ftruncate(int fildes, off_t length) | ||||||
| { | { | ||||||
| 	return syscall(SYS_TRUNCATE, fildes, length); | 	return syscall(SYS_FTRUNCATE, fildes, length); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int fsync(int fildes) | int fsync(int fildes) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue