`pwd`: add pwd

master
Drake 3 years ago
parent 2bd11f8548
commit e6dd8663d6
No known key found for this signature in database
GPG Key ID: 9B83455BD94F12A3

@ -15,7 +15,7 @@ endif
CC_FLAGS := ${CC_FLAGS} -I/opt/webos-sdk-x86_64/1.0.g/sysroots/armv7a-neon-webos-linux-gnueabi/usr/include --sysroot=/opt/webos-sdk-x86_64/1.0.g/sysroots/armv7a-neon-webos-linux-gnueabi
endif
ifndef PROGS
PROGS := whoami arch ls
PROGS := whoami arch ls pwd
endif
make:
mkdir -p bin

@ -0,0 +1,44 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <pwd.h>
#include "version.h"
/*
whoami - prints the working user's username (unless --uid is specified)
Available arguments:
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
*/
int main(int argc, char** argv) {
char wd[PATH_MAX];
getcwd(wd, sizeof(wd));
if (argc == 1) {
printf(wd);
} else {
for (int i = 0; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"pwd - prints the current working directory\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
}
}
}
}
Loading…
Cancel
Save