Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving runtime OS check to compiletime for better performance and size #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions deps/os.c/os.c

This file was deleted.

21 changes: 0 additions & 21 deletions deps/os.c/os.h

This file was deleted.

21 changes: 0 additions & 21 deletions deps/os.c/package.json

This file was deleted.

31 changes: 10 additions & 21 deletions opener.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <string.h>
#include <stdlib.h>

#include "os.h"

char *
create_cmd(const char * cmd, const char * link) {
char * url = malloc(strlen(cmd) + strlen(link) + 1);
Expand All @@ -22,29 +20,20 @@ create_cmd(const char * cmd, const char * link) {

int
opener(const char *url) {

const char *platform = operating_system();
const char *cmd = NULL;

// Hanlde macOS
if (!strcmp(platform, "macOS")) {
cmd = "open";

// Handle Windows
} else if (!strcmp(platform, "win32") || !strcmp(platform, "win64")) {
cmd = "start";

// Handle Linux, Unix, etc
} else if (!strcmp(platform, "unix")
|| !strcmp(platform, "linux")
|| !strcmp(platform, "freeBSD")
|| !strcmp(platform, "other")) {
cmd = "xdg-open";
}
#ifdef _WIN32
#define cmd "open"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, the open command won't work.

#elif _WIN64
#define cmd "open"
#elif __APPLE__ || __MACH__
#define cmd "open"
#else
#define cmd "xdg-open"
#endif

char *script = create_cmd(cmd, url);

system(script);
free(script);
return 0;
}
}