Skip to content

Commit 28a3aae

Browse files
committed
Add xy_os_family
1 parent 75c1401 commit 28a3aae

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

lib/xy.h

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Contributors : juzeon <[email protected]>
99
* |
1010
* Created On : <2023-08-28>
11-
* Last Modified : <2024-12-14>
11+
* Last Modified : <2025-06-20>
1212
*
1313
* xy: 襄阳、咸阳
1414
* Corss-Platform C utilities for CLI applications in Ruby flavor
@@ -17,8 +17,10 @@
1717
#ifndef XY_H
1818
#define XY_H
1919

20-
#define _XY_Version "v0.1.4.4-2024/12/14"
21-
#define _XY_Maintain_URL "https://gitee.com/RubyMetric/chsrc/blob/main/include/xy.h"
20+
#define _XY_Version "v0.1.5.0-2025/06/20"
21+
#define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/main/lib/xy.h"
22+
#define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/main/lib/xy.h"
23+
2224

2325
#include <assert.h>
2426
#include <stdarg.h>
@@ -646,6 +648,41 @@ xy_run (const char *cmd, unsigned long n)
646648
}
647649

648650

651+
652+
653+
/******************************************************
654+
* cross OS
655+
******************************************************/
656+
657+
/**
658+
* 该函数同 just 中的 os_family(),只区分 windows, unix
659+
*
660+
* @return 返回 "windows" 或 "unix"
661+
*/
662+
#define xy_os_family _xy_os_family ()
663+
static char *
664+
_xy_os_family ()
665+
{
666+
if (xy_on_windows)
667+
return "windows";
668+
else
669+
return "unix";
670+
}
671+
672+
673+
/**
674+
* 该函数返回所在 os family 的对应字符串
675+
*/
676+
static const char *
677+
xy_os_depend_str (const char *str_for_win, const char *str_for_unix)
678+
{
679+
if (xy_on_windows)
680+
return str_for_win;
681+
else
682+
return str_for_unix;
683+
}
684+
685+
649686
#define xy_os_home _xy_os_home ()
650687
static char *
651688
_xy_os_home ()

test/xy.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Contributors : Nil Null <[email protected]>
77
* |
88
* Created On : <2023-08-30>
9-
* Last Modified : <2025-06-19>
9+
* Last Modified : <2025-06-20>
1010
*
1111
* Test xy.h
1212
* ------------------------------------------------------------*/
@@ -17,6 +17,9 @@ int
1717
main (int argc, char const *argv[])
1818
{
1919
xy_useutf8 ();
20+
21+
puts (xy_os_depend_str ("Hello, Windows!", "Hello, Unix!"));
22+
2023
puti (3);
2124
double dbl = 3.1415;
2225
putf (dbl);

0 commit comments

Comments
 (0)