logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

strcmp.3p (3729B)


  1. '\" et
  2. .TH STRCMP "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. strcmp
  12. \(em compare two strings
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <string.h>
  17. .P
  18. int strcmp(const char *\fIs1\fP, const char *\fIs2\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The functionality described on this reference page is aligned with the
  22. ISO\ C standard. Any conflict between the requirements described here and the
  23. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  24. .P
  25. The
  26. \fIstrcmp\fR()
  27. function shall compare the string pointed to by
  28. .IR s1
  29. to the string pointed to by
  30. .IR s2 .
  31. .P
  32. The sign of a non-zero return value shall be determined by the sign of
  33. the difference between the values of the first pair of bytes (both
  34. interpreted as type
  35. .BR "unsigned char" )
  36. that differ in the strings being compared.
  37. .SH "RETURN VALUE"
  38. Upon completion,
  39. \fIstrcmp\fR()
  40. shall return an integer greater than, equal to, or less than 0, if the
  41. string pointed to by
  42. .IR s1
  43. is greater than, equal to, or less than the string pointed to by
  44. .IR s2 ,
  45. respectively.
  46. .SH ERRORS
  47. No errors are defined.
  48. .LP
  49. .IR "The following sections are informative."
  50. .SH EXAMPLES
  51. .SS "Checking a Password Entry"
  52. .P
  53. The following example compares the information read from standard input
  54. to the value of the name of the user entry. If the
  55. \fIstrcmp\fR()
  56. function returns 0 (indicating a match), a further check will be made
  57. to see if the user entered the proper old password. The
  58. \fIcrypt\fR()
  59. function shall encrypt the old password entered by the user, using
  60. the value of the encrypted password in the
  61. .BR passwd
  62. structure as the salt. If this value matches the value of the encrypted
  63. .BR passwd
  64. in the structure, the entered password
  65. .IR oldpasswd
  66. is the correct user's password. Finally, the program encrypts the new
  67. password so that it can store the information in the
  68. .BR passwd
  69. structure.
  70. .sp
  71. .RS 4
  72. .nf
  73. #include <string.h>
  74. #include <unistd.h>
  75. #include <stdio.h>
  76. \&...
  77. int valid_change;
  78. struct passwd *p;
  79. char user[100];
  80. char oldpasswd[100];
  81. char newpasswd[100];
  82. char savepasswd[100];
  83. \&...
  84. if (strcmp(p->pw_name, user) == 0) {
  85. if (strcmp(p->pw_passwd, crypt(oldpasswd, p->pw_passwd)) == 0) {
  86. strcpy(savepasswd, crypt(newpasswd, user));
  87. p->pw_passwd = savepasswd;
  88. valid_change = 1;
  89. }
  90. else {
  91. fprintf(stderr, "Old password is not valid\en");
  92. }
  93. }
  94. \&...
  95. .fi
  96. .P
  97. .RE
  98. .SH "APPLICATION USAGE"
  99. None.
  100. .SH RATIONALE
  101. None.
  102. .SH "FUTURE DIRECTIONS"
  103. None.
  104. .SH "SEE ALSO"
  105. .IR "\fIstrncmp\fR\^(\|)"
  106. .P
  107. The Base Definitions volume of POSIX.1\(hy2017,
  108. .IR "\fB<string.h>\fP"
  109. .\"
  110. .SH COPYRIGHT
  111. Portions of this text are reprinted and reproduced in electronic form
  112. from IEEE Std 1003.1-2017, Standard for Information Technology
  113. -- Portable Operating System Interface (POSIX), The Open Group Base
  114. Specifications Issue 7, 2018 Edition,
  115. Copyright (C) 2018 by the Institute of
  116. Electrical and Electronics Engineers, Inc and The Open Group.
  117. In the event of any discrepancy between this version and the original IEEE and
  118. The Open Group Standard, the original IEEE and The Open Group Standard
  119. is the referee document. The original Standard can be obtained online at
  120. http://www.opengroup.org/unix/online.html .
  121. .PP
  122. Any typographical or formatting errors that appear
  123. in this page are most likely
  124. to have been introduced during the conversion of the source files to
  125. man page format. To report such errors, see
  126. https://www.kernel.org/doc/man-pages/reporting_bugs.html .