ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
version.c File Reference

🏷️ Binary-embedded version information in custom ELF/Mach-O sections for runtime inspection More...

Go to the source code of this file.

Functions

semantic_version_t version_parse (const char *version_string)
int version_compare (semantic_version_t a, semantic_version_t b)

Detailed Description

🏷️ Binary-embedded version information in custom ELF/Mach-O sections for runtime inspection

Definition in file version.c.

Function Documentation

◆ version_compare()

int version_compare ( semantic_version_t a,
semantic_version_t b )

Definition at line 110 of file version.c.

110 {
111 // Compare major version
112 if (a.major < b.major) {
113 return -1;
114 }
115 if (a.major > b.major) {
116 return 1;
117 }
118
119 // Major versions equal, compare minor
120 if (a.minor < b.minor) {
121 return -1;
122 }
123 if (a.minor > b.minor) {
124 return 1;
125 }
126
127 // Minor versions equal, compare patch
128 if (a.patch < b.patch) {
129 return -1;
130 }
131 if (a.patch > b.patch) {
132 return 1;
133 }
134
135 // All components equal
136 return 0;
137}

Referenced by update_check_load_cache(), and update_check_perform().

◆ version_parse()

semantic_version_t version_parse ( const char * version_string)

Definition at line 47 of file version.c.

47 {
48 semantic_version_t result = {0, 0, 0, false};
49
50 if (!version_string || version_string[0] == '\0') {
51 return result;
52 }
53
54 const char *p = version_string;
55
56 // Optionally skip 'v' prefix if present
57 if (p[0] == 'v' || p[0] == 'V') {
58 p++; // Skip 'v'
59 }
60
61 // Parse major version
62 char *endptr = NULL;
63 errno = 0; // Reset errno before strtol
64 long major = strtol(p, &endptr, 10);
65 if (errno == ERANGE || endptr == p || major < 0 || major > INT_MAX) {
66 return result; // Invalid major version or overflow
67 }
68 result.major = (int)major;
69 p = endptr;
70
71 // Version must have all three components (major.minor.patch)
72 if (*p != '.') {
73 return result; // Invalid: missing minor version
74 }
75 p++; // Skip dot
76
77 // Parse minor version
78 errno = 0; // Reset errno before strtol
79 long minor = strtol(p, &endptr, 10);
80 if (errno == ERANGE || endptr == p || minor < 0 || minor > INT_MAX) {
81 return result; // Invalid minor version or overflow
82 }
83 result.minor = (int)minor;
84 p = endptr;
85
86 // Version must have patch component
87 if (*p != '.') {
88 return result; // Invalid: missing patch version
89 }
90 p++; // Skip dot
91
92 // Parse patch version
93 errno = 0; // Reset errno before strtol
94 long patch = strtol(p, &endptr, 10);
95 if (errno == ERANGE || endptr == p || patch < 0 || patch > INT_MAX) {
96 return result; // Invalid patch version or overflow
97 }
98 result.patch = (int)patch;
99 p = endptr;
100
101 // Reject prerelease tags (e.g., "v1.2.3-beta") - must end after patch number
102 if (*p != '\0') {
103 return result; // Invalid: has extra characters after version
104 }
105
106 result.valid = true;
107 return result;
108}

Referenced by update_check_load_cache(), and update_check_perform().