new functionality
This commit is contained in:
parent
c8728b536d
commit
34a4c48a06
@ -2,33 +2,46 @@
|
|||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
|
|
||||||
streq \(en compare strings
|
strcmp \(en compare strings
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
|
||||||
streq
|
strcmp
|
||||||
.RM [ string ]
|
.RM [ string ]
|
||||||
.RB [ strings... ]
|
.RB [ strings... ]
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
|
|
||||||
Streq checks whether the given strings are the same.
|
Strcmp checks whether the given strings are the same.
|
||||||
Streq exits successfully if the strings are identical and unsuccessfully if not.
|
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
|
.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
|
.SH UNICODE
|
||||||
|
|
||||||
Streq will exit unsuccessfully if the given strings are not identical;
|
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.
|
Unicode strings may need to normalized if the intent is to check visual
|
||||||
|
similarity and not byte similarity.
|
||||||
|
|
||||||
.SH STANDARDS
|
.SH STANDARDS
|
||||||
|
|
||||||
Streq is not described in POSIX.1-2017.
|
Strcmp is not described in POSIX.1-2017.
|
||||||
Streq's function may be performed on a purely POSIX system with test(1).
|
Strcmp's function may be performed on a purely POSIX system with test(1).
|
||||||
|
|
||||||
.SH COPYRIGHT
|
.SH COPYRIGHT
|
||||||
|
|
||||||
Public domain.
|
Public domain.
|
||||||
|
|
||||||
|
.SH SEE ALSO
|
||||||
|
|
||||||
|
strcmp(3), test(1)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# include <sysexits.h> /* EX_USAGE */
|
# include <sysexits.h> /* EX_USAGE */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *program_name = "streq";
|
static char *program_name = "strcmp";
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
int i;
|
int i;
|
||||||
@ -16,8 +16,10 @@ int main(int argc, char *argv[]){
|
|||||||
|
|
||||||
for(; *argv[1] != '\0'; ++argv[1])
|
for(; *argv[1] != '\0'; ++argv[1])
|
||||||
for(i = 2; i < argc; ++i)
|
for(i = 2; i < argc; ++i)
|
||||||
if(*argv[i-1] != *argv[i]++)
|
if(*argv[i-1] > *argv[i])
|
||||||
return 1;
|
return 1;
|
||||||
|
else if(*argv[i-1] < *argv[i]++)
|
||||||
|
return -1; /* actually 255 */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user