`basename`: add basename.

master
Drake 3 years ago
parent 72ab287432
commit c966b2921b
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 pwd
PROGS := whoami arch ls pwd basename
endif
make:
mkdir -p bin

@ -0,0 +1,51 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <pwd.h>
#include <libgen.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;
char *upname;
if (argc == 1) {
printf("supply missing operand.");
return 1;
} else {
for (int i = 1; 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"
"basename - prints the last component of the path\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;
} else {
upname = arg;
break;
}
}
}
wd = basename(upname);
printf(wd);
}
Loading…
Cancel
Save