forked from Bananymous/banan-os
				
			Userspace: add basic 'touch' command
This commit is contained in:
		
							parent
							
								
									f65e5f4190
								
							
						
					
					
						commit
						8cd91f5a6a
					
				| 
						 | 
					@ -11,6 +11,7 @@ set(USERSPACE_PROJECTS
 | 
				
			||||||
	Shell
 | 
						Shell
 | 
				
			||||||
	tee
 | 
						tee
 | 
				
			||||||
	test
 | 
						test
 | 
				
			||||||
 | 
						touch
 | 
				
			||||||
	u8sum
 | 
						u8sum
 | 
				
			||||||
	yes
 | 
						yes
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					cmake_minimum_required(VERSION 3.26)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					project(touch CXX)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set(SOURCES
 | 
				
			||||||
 | 
						main.cpp
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					add_executable(touch ${SOURCES})
 | 
				
			||||||
 | 
					target_compile_options(touch PUBLIC -O2 -g)
 | 
				
			||||||
 | 
					target_link_libraries(touch PUBLIC libc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					add_custom_target(touch-install
 | 
				
			||||||
 | 
						COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/touch ${BANAN_BIN}/
 | 
				
			||||||
 | 
						DEPENDS touch
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char** argv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						for (int i = 1; i < argc; i++)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							int fd = open(argv[i], O_WRONLY | O_CREAT, 0644);
 | 
				
			||||||
 | 
							if (fd == -1)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (errno != EEXISTS)
 | 
				
			||||||
 | 
									perror(argv[i]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								close(fd);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue