ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
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 112 of file version.c.

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

Referenced by update_check_load_cache(), and update_check_perform().

◆ version_parse()

semantic_version_t version_parse ( const char *  version_string)

Definition at line 49 of file version.c.

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

Referenced by update_check_load_cache(), and update_check_perform().