Initial commit

Currently includes a (feature-complete?) version of `whoami` and `id`.
master
Drake 3 years ago
commit db9061fbbf
No known key found for this signature in database
GPG Key ID: 9B83455BD94F12A3

@ -0,0 +1,33 @@
ifndef CC
CC =
endif
ifndef IP
IP := 192.168.1.10
#use my tv's ip if not passed to makefile
endif
target := $(shell ${CC} -dumpmachine)
ifeq (${target}, arm-webos-linux-gnueabi)
$(info Setting compiler include flags for webOS...)
ifndef CC_FLAGS
#guess we gotta define this if it no exist, but imagine not needing custom cxx flags
CC_FLAGS :=
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
endif
make:
mkdir -p bin
for prog in ${PROGS}; do ${CC} -o bin/$$prog -Ilib ${CC_FLAGS} src/$$prog.c; done
tv:
scp hbpm root@${IP}:/media/internal/bin
verbose:
mkdir -p bin
for prog in ${PROGS}; do ${CC} -v -o bin/$$prog ${CC_FLAGS} src/$$prog.c; done
clean:
@rm -rf bin
help:
@echo 'make' - Build normal version
@echo 'make verbose' - Build normal version with verbose compilation for debugging
@echo 'make help' - Display this help message

Binary file not shown.

Binary file not shown.

@ -0,0 +1,43 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <sys/utsname.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) {
uid_t userid = geteuid();
char * username = getpwuid(userid)->pw_name;
if (argc == 1) {
struct utsname e;
uname(&e);
printf(e.machine);
return 0;
} 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)\n"
"arch - prints the current machine's architecture\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program (WIP)";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf("6.9.69\n");
return 0;
}
}
}
}

@ -0,0 +1,44 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.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) {
uid_t userid = geteuid();
char * username = getpwuid(userid)->pw_name;
if (argc == 1) {
printf(username);
return 0;
} 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)\n"
"whoami - prints the working user's username (unless --uid is specified)\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program (WIP)\n"
" --uid: print the users numeric UID, instead of username";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf("6.9.69\n");
return 0;
} else if (!strcmp(arg, "--uid")) {
printf("%lu\n", (unsigned long int)userid);
return 0;
}
}
}
}
Loading…
Cancel
Save