pish/src/Common.c

33 lines
808 B
C
Raw Permalink Normal View History

#include "Common.h"
#include <pwd.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
// 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
void ResetCommandStruct(CommandStruct* command)
{
for (int i = 0; i < command->argc; i++)
command->argv[i] = NULL;
command->argc = 0;
return;
}