Skip to content

Commit

Permalink
luxfetch: stub for a neofetch-like app
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 6, 2024
1 parent ba488aa commit 9858e83
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ all:
@make -C ls
@echo "\x1B[0;1;35m make\x1B[0m utilities/cat"
@make -C cat
@echo "\x1B[0;1;35m make\x1B[0m utilities/luxfetch"
@make -C luxfetch

install:
@mkdir -p out
Expand All @@ -30,6 +32,8 @@ install:
@make install -C ls
@echo "\x1B[0;1;35m make\x1B[0m install utilities/cat"
@make install -C cat
@echo "\x1B[0;1;35m make\x1B[0m install utilities/luxfetch"
@make install -C luxfetch

clean:
@echo "\x1B[0;1;35m make\x1B[0m clean utilities/hello"
Expand All @@ -45,4 +49,6 @@ clean:
@echo "\x1B[0;1;35m make\x1B[0m clean utilities/ls"
@make clean -C ls
@echo "\x1B[0;1;35m make\x1B[0m clean utilities/cat"
@make clean -C cat
@make clean -C cat
@echo "\x1B[0;1;35m make\x1B[0m clean utilities/luxfetch"
@make clean -C luxfetch
23 changes: 23 additions & 0 deletions luxfetch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PLATFORM=x86_64-lux
CCFLAGS=-Wall -c -O3
LDFLAGS=-llux
CC=x86_64-lux-gcc
LD=x86_64-lux-gcc
SRC:=$(shell find . -type f -name "*.c")
OBJ:=$(SRC:.c=.o)

all: luxfetch

%.o: %.c
@echo "\x1B[0;1;32m cc \x1B[0m $<"
@$(CC) $(CCFLAGS) -o $@ $<

luxfetch: $(OBJ)
@echo "\x1B[0;1;93m ld \x1B[0m luxfetch"
@$(LD) $(OBJ) -o luxfetch $(LDFLAGS)

install: luxfetch
@cp luxfetch ../out/

clean:
@rm -f luxfetch $(OBJ)
42 changes: 42 additions & 0 deletions luxfetch/luxfetch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* luxOS - a unix-like operating system
* Omar Elghoul, 2024
*
* luxfetch: neofetch clone for luxOS
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define COLOR "\e[0;94m"
#define RESET "\e[0m"

int main(void) {
// get kernel info
FILE *f = fopen("/proc/kernel", "r");
if(!f) {
fprintf(stderr, "unable to open /proc/kernel for reading\n");
return -1;
}

fseek(f, 0, SEEK_END);
long size = ftell(f);
fseek(f, 0, SEEK_SET);

char *kernel = calloc(1, size+1);
if(!kernel) {
fprintf(stderr, "failed to allocate memory\n");
fclose(f);
return -1;
}

if(fread(kernel, 1, size, f) != size) {
fprintf(stderr, "failed to read from /proc/kernel\n");
fclose(f);
return -1;
}

printf("%s\n", kernel);
return 0;
}

0 comments on commit 9858e83

Please sign in to comment.