Skip to content

Commit 369b792

Browse files
committed
feat: add POSIX and GNU source definitions for improved portability
1 parent def6b62 commit 369b792

10 files changed

Lines changed: 49 additions & 3 deletions

File tree

src/core/executor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define _POSIX_C_SOURCE 200809L
22
#define _GNU_SOURCE
3+
34
#include <nutshell/core.h>
45
#include <nutshell/utils.h>
56
#include <sys/wait.h>

src/core/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
14
#include <nutshell/core.h>
25
#include <nutshell/utils.h>
36
#include <nutshell/theme.h>

src/core/parser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
14
#include <nutshell/core.h>
25
#include <ctype.h>
36
#include <string.h>

src/pkg/integrity.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
14
#include <nutshell/pkg.h>
25
#include <openssl/evp.h> // Use EVP interface instead of direct SHA256
36
#include <stdio.h>

src/pkg/nutpkg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define _POSIX_C_SOURCE 200809L
22
#define _GNU_SOURCE
3+
34
#include <nutshell/pkg.h>
45
#include <curl/curl.h>
56
// Try to find jansson.h in various locations

src/pkg/packager.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
14
#include <nutshell/core.h>
25
#include <nutshell/pkg.h>
36
#include <nutshell/utils.h>

src/pkg/registry.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
14
#include <nutshell/core.h>
25
#include <stdio.h>
36
#include <string.h>

src/utils/helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
14
#include <nutshell/utils.h>
25
#include <nutshell/core.h>
36
#include <ctype.h>

src/utils/security.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// src/utils/security.c
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
24
#include <nutshell/utils.h>
35
#include <nutshell/pkg.h>
46
#include <stdio.h>

src/utils/theme.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#define _GNU_SOURCE
3+
14
#include <nutshell/theme.h>
25
#include <jansson.h>
36
#include <stdio.h>
47
#include <stdlib.h>
58
#include <string.h>
69
#include <dirent.h>
710
#include <unistd.h>
11+
#include <sys/stat.h> // Add this include for struct stat, stat() function, and S_ISREG macro
812

913
// Add this helper macro at the top of the file
1014
#define THEME_DEBUG(fmt, ...) \
@@ -934,7 +938,17 @@ int theme_command(int argc, char **argv) {
934938
dir = opendir(themes_dir);
935939
if (dir) {
936940
while ((ent = readdir(dir)) != NULL) {
937-
if (ent->d_type == DT_REG && strstr(ent->d_name, ".json")) {
941+
// Skip . and .. entries
942+
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
943+
continue;
944+
945+
// Build the full path
946+
char full_path[512];
947+
struct stat st;
948+
snprintf(full_path, sizeof(full_path), "%s/%s", themes_dir, ent->d_name);
949+
950+
// Check if it's a regular file with .json extension
951+
if (stat(full_path, &st) == 0 && S_ISREG(st.st_mode) && strstr(ent->d_name, ".json")) {
938952
// Remove .json extension
939953
char theme_name[128];
940954
strncpy(theme_name, ent->d_name, sizeof(theme_name));
@@ -957,7 +971,17 @@ int theme_command(int argc, char **argv) {
957971
dir = opendir("./themes");
958972
if (dir) {
959973
while ((ent = readdir(dir)) != NULL) {
960-
if (ent->d_type == DT_REG && strstr(ent->d_name, ".json")) {
974+
// Skip . and .. entries
975+
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
976+
continue;
977+
978+
// Build the full path
979+
char full_path[512];
980+
struct stat st;
981+
snprintf(full_path, sizeof(full_path), "./themes/%s", ent->d_name);
982+
983+
// Check if it's a regular file with .json extension
984+
if (stat(full_path, &st) == 0 && S_ISREG(st.st_mode) && strstr(ent->d_name, ".json")) {
961985
// Remove .json extension
962986
char theme_name[128];
963987
strncpy(theme_name, ent->d_name, sizeof(theme_name));

0 commit comments

Comments
 (0)