| 
									
										
										
										
											2022-10-27 00:25:40 -05:00
										 |  |  | #include "Common.h"
 | 
					
						
							| 
									
										
										
										
											2022-10-29 05:14:23 -05:00
										 |  |  | #include <pwd.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-27 00:25:40 -05:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-29 05:14:23 -05:00
										 |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-27 00:25:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 05:14:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Gets home directory location of user
 | 
					
						
							|  |  |  | const char* GetHomeDir(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *homeDir = (getpwuid(getuid()))->pw_dir; | 
					
						
							|  |  |  | 	return homeDir; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Copies a range of an old command object to new command object
 | 
					
						
							|  |  |  | void CopyCommandStruct(CommandStruct* oldCommand, CommandStruct* newCommand, int start, int end) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     newCommand->argc = end - start; | 
					
						
							|  |  |  |     for (int i = 0; i < newCommand->argc; i++) | 
					
						
							|  |  |  |         newCommand->argv[i] = oldCommand->argv[i + start]; | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Resets entire command object
 | 
					
						
							| 
									
										
										
										
											2022-10-27 00:25:40 -05:00
										 |  |  | void ResetCommandStruct(CommandStruct* command) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     for (int i = 0; i < command->argc; i++) | 
					
						
							| 
									
										
										
										
											2022-10-28 16:14:53 -05:00
										 |  |  |         command->argv[i] = NULL; | 
					
						
							| 
									
										
										
										
											2022-10-27 00:25:40 -05:00
										 |  |  |     command->argc = 0; | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | } |