1
0

new functionality

This commit is contained in:
dtb 2023-12-19 00:13:59 -07:00
parent c8728b536d
commit 34a4c48a06
2 changed files with 26 additions and 11 deletions

View File

@ -2,33 +2,46 @@
.SH NAME
streq \(en compare strings
strcmp \(en compare strings
.SH SYNOPSIS
streq
strcmp
.RM [ string ]
.RB [ strings... ]
.SH DESCRIPTION
Streq checks whether the given strings are the same.
Streq exits successfully if the strings are identical and unsuccessfully if not.
Strcmp checks whether the given strings are the same.
Strcmp exits successfully if the strings are identical. Otherwise, strcmp exits
with the value 1 if an earlier string has a greater byte value than a later
string (e.g.
.R strcmp b a
)
and 255 if an earlier string has a lesser byte value (e.g.
.R strcmp a b
).
.SH DIAGNOSTICS
Streq will print an error message and exit unsuccessfully with a status described in sysexits(3) if used incorrectly (given less than two operands).
Strcmp will print an error message and exit unsuccessfully with a status
described in sysexits(3) if used incorrectly (given less than two operands).
.SH UNICODE
Streq will exit unsuccessfully if the given strings are not identical;
Unicode strings may need to normalized if the intent is to check visual similarity and not byte similarity.
Strcmp will exit unsuccessfully if the given strings are not identical;
Unicode strings may need to normalized if the intent is to check visual
similarity and not byte similarity.
.SH STANDARDS
Streq is not described in POSIX.1-2017.
Streq's function may be performed on a purely POSIX system with test(1).
Strcmp is not described in POSIX.1-2017.
Strcmp's function may be performed on a purely POSIX system with test(1).
.SH COPYRIGHT
Public domain.
.SH SEE ALSO
strcmp(3), test(1)

View File

@ -3,7 +3,7 @@
# include <sysexits.h> /* EX_USAGE */
#endif
static char *program_name = "streq";
static char *program_name = "strcmp";
int main(int argc, char *argv[]){
int i;
@ -16,8 +16,10 @@ int main(int argc, char *argv[]){
for(; *argv[1] != '\0'; ++argv[1])
for(i = 2; i < argc; ++i)
if(*argv[i-1] != *argv[i]++)
if(*argv[i-1] > *argv[i])
return 1;
else if(*argv[i-1] < *argv[i]++)
return -1; /* actually 255 */
return 0;
}