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

qsort.3p (3998B)


  1. '\" et
  2. .TH QSORT "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. qsort
  12. \(em sort a table of data
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <stdlib.h>
  17. .P
  18. void qsort(void *\fIbase\fP, size_t \fInel\fP, size_t \fIwidth\fP,
  19. int (*\fIcompar\fP)(const void *, const void *));
  20. .fi
  21. .SH DESCRIPTION
  22. The functionality described on this reference page is aligned with the
  23. ISO\ C standard. Any conflict between the requirements described here and the
  24. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  25. .P
  26. The
  27. \fIqsort\fR()
  28. function shall sort an array of
  29. .IR nel
  30. objects, the initial element of which is pointed to by
  31. .IR base .
  32. The size of each object, in bytes, is specified by the
  33. .IR width
  34. argument. If the
  35. .IR nel
  36. argument has the value zero, the comparison function pointed to by
  37. .IR compar
  38. shall not be called and no rearrangement shall take place.
  39. .P
  40. The application shall ensure that the comparison function pointed to by
  41. .IR compar
  42. does not alter the contents of the array. The implementation may
  43. reorder elements of the array between calls to the comparison function,
  44. but shall not alter the contents of any individual element.
  45. .P
  46. When the same objects (consisting of width bytes, irrespective of their
  47. current positions in the array) are passed more than once to the
  48. comparison function, the results shall be consistent with one another.
  49. That is, they shall define a total ordering on the array.
  50. .P
  51. The contents of the array shall be sorted in ascending order according
  52. to a comparison function. The
  53. .IR compar
  54. argument is a pointer to the comparison function, which is called with
  55. two arguments that point to the elements being compared. The
  56. application shall ensure that the function returns an integer less
  57. than, equal to, or greater than 0, if the first argument is considered
  58. respectively less than, equal to, or greater than the second. If two
  59. members compare as equal, their order in the sorted array is
  60. unspecified.
  61. .SH "RETURN VALUE"
  62. The
  63. \fIqsort\fR()
  64. function shall not return a value.
  65. .SH ERRORS
  66. No errors are defined.
  67. .LP
  68. .IR "The following sections are informative."
  69. .SH EXAMPLES
  70. None.
  71. .SH "APPLICATION USAGE"
  72. The comparison function need not compare every byte, so arbitrary data
  73. may be contained in the elements in addition to the values being
  74. compared.
  75. .SH RATIONALE
  76. The requirement that each argument (hereafter referred to as
  77. .IR p)
  78. to the comparison function is a pointer to elements of the array
  79. implies that for every call, for each argument separately, all of the
  80. following expressions are non-zero:
  81. .sp
  82. .RS 4
  83. .nf
  84. ((char *)p - (char *)base) % width == 0
  85. (char *)p >= (char *)base
  86. (char *)p < (char *)base + nel * width
  87. .fi
  88. .P
  89. .RE
  90. .SH "FUTURE DIRECTIONS"
  91. None.
  92. .SH "SEE ALSO"
  93. .IR "\fIalphasort\fR\^(\|)"
  94. .P
  95. The Base Definitions volume of POSIX.1\(hy2017,
  96. .IR "\fB<stdlib.h>\fP"
  97. .\"
  98. .SH COPYRIGHT
  99. Portions of this text are reprinted and reproduced in electronic form
  100. from IEEE Std 1003.1-2017, Standard for Information Technology
  101. -- Portable Operating System Interface (POSIX), The Open Group Base
  102. Specifications Issue 7, 2018 Edition,
  103. Copyright (C) 2018 by the Institute of
  104. Electrical and Electronics Engineers, Inc and The Open Group.
  105. In the event of any discrepancy between this version and the original IEEE and
  106. The Open Group Standard, the original IEEE and The Open Group Standard
  107. is the referee document. The original Standard can be obtained online at
  108. http://www.opengroup.org/unix/online.html .
  109. .PP
  110. Any typographical or formatting errors that appear
  111. in this page are most likely
  112. to have been introduced during the conversion of the source files to
  113. man page format. To report such errors, see
  114. https://www.kernel.org/doc/man-pages/reporting_bugs.html .