Skip to content

Commit

Permalink
support solaris
Browse files Browse the repository at this point in the history
  • Loading branch information
matyalatte committed Jun 1, 2024
1 parent 7dc03fa commit dc32473
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 14 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ Most of the functions are here.
[c-env-utils: include/env_utils.h File Reference](https://matyalatte.github.io/c-env-utils/env__utils_8h.html)

c-env-utils only supports utf8 strings.
You should use `env_utils_windows.h` if you want to use utf16 strings on Windows.
You should use `env_utils_windows.h` if you want to use utf16 strings on Windows.
[c-env-utils: include/env_utils_windows.h File Reference](https://matyalatte.github.io/c-env-utils/env__utils__windows_8h.html)

## Platforms

c-env-utils supports most of the desktop operating systems.

- Windows
- macOS
- Linux
- BSD
- Haiku
- Solaris
- Other unix variants (maybe)

## Example

```c
Expand All @@ -35,7 +47,7 @@ int main(void) {
printf("User: %s\n", username);
envuFree(username);

// Get an environment variable
// An environment variable
char *paths = envuGetEnv("PATH");
printf("PATH: %s\n", paths);
envuFree(paths);
Expand Down
10 changes: 8 additions & 2 deletions src/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,13 @@ static struct passwd *getpwuid_safe(char **buf) {
if (*buf == NULL)
return NULL;

#ifdef __sun
// Solaris has a little bit different APIs
result = getpwuid_r(getuid(), &pwd, *buf, bufsize);
#else
int ret = getpwuid_r(getuid(), &pwd, *buf, bufsize, &result);
if (ret != 0) return NULL;
#endif
return result;
}

Expand Down Expand Up @@ -260,10 +265,11 @@ char *envuGetUsername() {
return str;
}

// Darwin, Linux, FreeBSD, OpenBSD, NetBSD, Haiku, etc.
// Darwin, Linux, FreeBSD, OpenBSD, NetBSD, Haiku, SunOS, etc.
char *envuGetOS() {
struct utsname buf = { 0 };
if (uname(&buf) != 0) {
// Note: uname(&buf) can be positive on Solaris
if (uname(&buf) == -1) {
return AllocStrWithConst("");
}
return AllocStrWithConst(buf.sysname);
Expand Down

0 comments on commit dc32473

Please sign in to comment.