Merge pull request 'add comments' (#3) from comments into master

Reviewed-on: #3
This commit is contained in:
Chris Cromer 2021-06-19 23:10:53 -04:00
commit 41a701e97d
3 changed files with 23 additions and 0 deletions

View File

@ -21,12 +21,20 @@
#include <sys/types.h>
#include <unistd.h>
/**
* Get the logged in user's username.
* @return Returns the logged in user's username.
*/
char *get_user() {
struct passwd *pass;
pass = getpwuid(getuid());
return pass->pw_name;
}
/**
* Get the current working directory of the shell.
* @return Returns the current working directory.
*/
char *get_working_directory() {
char *cwd = NULL;
cwd = getcwd(NULL, PATH_MAX);
@ -39,6 +47,9 @@ char *get_working_directory() {
}
}
/**
* Print the console line before the user input.
*/
void print_input_line() {
char *name = get_user();
char *cwd = get_working_directory();

View File

@ -19,10 +19,17 @@
#include <string.h>
#include "console_line.h"
/**
* Remove new line from the end of a string.
* @param line The string to remove the new line from.
*/
void remove_new_line(char* line) {
line[strcspn(line, "\n")] = 0;
}
/**
* This is the loop that checks for user input and acts on it.
*/
void loop() {
size_t buffer_size = 0;
char *line = NULL;

View File

@ -16,6 +16,11 @@
#include <stdlib.h>
#include "loop.h"
/**
* The main entry point to the program.
* @param argc The number of arguments passed.
* @return Returns 0 on success or an error code on failure.
*/
int main(int argc, char **argv) {
loop();
return EXIT_SUCCESS;