forked from nakidai/mycfetch
1
0
Fork 0

Some changes in code

- Define about POSIX
- Return 69 if no art with specified name found
Nakidai 2024-08-23 10:01:43 +03:00
parent 48a0b477ee
commit 412e71d684
Signed by: nakidai
GPG Key ID: 18AD605FDA13FE5A
1 changed files with 10 additions and 2 deletions

View File

@ -1,8 +1,11 @@
#define _POSIX_C_SOURCE 200112L
#include <stdio.h> #include <stdio.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
#include "config.h" #include "config.h"
#include "defs.h" #include "defs.h"
@ -29,10 +32,15 @@ void getuptime(char *buffer, int max_length)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char **art = arts[0].art, *name = argv[1]; char **art = arts[0].art, *name = argv[1];
int ret = 0;
if (name) if (name)
{
bool found = false;
for (int i = 0; i < sizeof(arts) / sizeof(*arts); ++i) for (int i = 0; i < sizeof(arts) / sizeof(*arts); ++i)
if (!strcmp(arts[i].name, name)) if (!strcmp(arts[i].name, name))
{ art = arts[i].art; break; } { art = arts[i].art; found = true; break; }
if (!found) ret = 69;
}
struct utsname uname_buf; struct utsname uname_buf;
char hostname[max_hostname_length]; char hostname[max_hostname_length];
@ -54,5 +62,5 @@ int main(int argc, char **argv)
art[2], uname_buf.sysname, uname_buf.release, art[2], uname_buf.sysname, uname_buf.release,
art[3], uptime art[3], uptime
); );
return 0; return ret;
} }