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

lseek.3p (5192B)


  1. '\" et
  2. .TH LSEEK "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. lseek
  12. \(em move the read/write file offset
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <unistd.h>
  17. .P
  18. off_t lseek(int \fIfildes\fP, off_t \fIoffset\fP, int \fIwhence\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fIlseek\fR()
  23. function shall set the file offset for the open file description
  24. associated with the file descriptor
  25. .IR fildes,
  26. as follows:
  27. .IP " *" 4
  28. If
  29. .IR whence
  30. is SEEK_SET, the file offset shall be set to
  31. .IR offset
  32. bytes.
  33. .IP " *" 4
  34. If
  35. .IR whence
  36. is SEEK_CUR, the file offset shall be set to its current location plus
  37. .IR offset .
  38. .IP " *" 4
  39. If
  40. .IR whence
  41. is SEEK_END, the file offset shall be set to the size of the file plus
  42. .IR offset .
  43. .P
  44. The symbolic constants SEEK_SET, SEEK_CUR, and SEEK_END
  45. are defined in
  46. .IR <unistd.h> .
  47. .P
  48. The behavior of
  49. \fIlseek\fR()
  50. on devices which are incapable of seeking is implementation-defined.
  51. The value of the file offset associated with such a device is
  52. undefined.
  53. .P
  54. The
  55. \fIlseek\fR()
  56. function shall allow the file offset to be set beyond the end of the
  57. existing data in the file. If data is later written at this point,
  58. subsequent reads of data in the gap shall return bytes with the value 0
  59. until data is actually written into the gap.
  60. .P
  61. The
  62. \fIlseek\fR()
  63. function shall not, by itself, extend the size of a file.
  64. .P
  65. If
  66. .IR fildes
  67. refers to a shared memory object, the result of the
  68. \fIlseek\fR()
  69. function is unspecified.
  70. .P
  71. If
  72. .IR fildes
  73. refers to a typed memory object, the result of the
  74. \fIlseek\fR()
  75. function is unspecified.
  76. .SH "RETURN VALUE"
  77. Upon successful completion, the resulting offset, as measured in bytes
  78. from the beginning of the file, shall be returned. Otherwise, \-1
  79. shall be returned,
  80. .IR errno
  81. shall be set to indicate the error, and the file offset shall remain
  82. unchanged.
  83. .SH ERRORS
  84. The
  85. \fIlseek\fR()
  86. function shall fail if:
  87. .TP
  88. .BR EBADF
  89. The
  90. .IR fildes
  91. argument is not an open file descriptor.
  92. .TP
  93. .BR EINVAL
  94. The
  95. .IR whence
  96. argument is not a proper value, or the resulting file offset would be
  97. negative for a regular file, block special file, or directory.
  98. .TP
  99. .BR EOVERFLOW
  100. The resulting file offset would be a value which cannot be represented
  101. correctly in an object of type
  102. .BR off_t .
  103. .TP
  104. .BR ESPIPE
  105. The
  106. .IR fildes
  107. argument is associated with a pipe, FIFO, or socket.
  108. .LP
  109. .IR "The following sections are informative."
  110. .SH EXAMPLES
  111. None.
  112. .SH "APPLICATION USAGE"
  113. None.
  114. .SH RATIONALE
  115. The ISO\ C standard includes the functions
  116. \fIfgetpos\fR()
  117. and
  118. \fIfsetpos\fR(),
  119. which work on very large files by use of a special positioning type.
  120. .P
  121. Although
  122. \fIlseek\fR()
  123. may position the file offset beyond the end of the file, this function
  124. does not itself extend the size of the file. While the only function
  125. in POSIX.1\(hy2008 that may directly extend the size of the file is
  126. \fIwrite\fR(),
  127. \fItruncate\fR(),
  128. and
  129. \fIftruncate\fR(),
  130. several functions originally derived from the ISO\ C standard, such as
  131. \fIfwrite\fR(),
  132. \fIfprintf\fR(),
  133. and so on, may do so (by causing calls on
  134. \fIwrite\fR()).
  135. .P
  136. An invalid file offset that would cause
  137. .BR [EINVAL]
  138. to be returned may be both implementation-defined and
  139. device-dependent (for example, memory may have few invalid values). A
  140. negative file offset may be valid for some devices in some
  141. implementations.
  142. .P
  143. The POSIX.1\(hy1990 standard did not specifically prohibit
  144. \fIlseek\fR()
  145. from returning a negative offset. Therefore, an application was
  146. required to clear
  147. .IR errno
  148. prior to the call and check
  149. .IR errno
  150. upon return to determine whether a return value of (\c
  151. .BR off_t )\-1
  152. is a negative offset or an indication of an error condition. The
  153. standard developers did not wish to require this action on the part of
  154. a conforming application, and chose to require that
  155. .IR errno
  156. be set to
  157. .BR [EINVAL]
  158. when the resulting file offset would be negative for a regular file,
  159. block special file, or directory.
  160. .SH "FUTURE DIRECTIONS"
  161. None.
  162. .SH "SEE ALSO"
  163. .IR "\fIopen\fR\^(\|)"
  164. .P
  165. The Base Definitions volume of POSIX.1\(hy2017,
  166. .IR "\fB<sys_types.h>\fP",
  167. .IR "\fB<unistd.h>\fP"
  168. .\"
  169. .SH COPYRIGHT
  170. Portions of this text are reprinted and reproduced in electronic form
  171. from IEEE Std 1003.1-2017, Standard for Information Technology
  172. -- Portable Operating System Interface (POSIX), The Open Group Base
  173. Specifications Issue 7, 2018 Edition,
  174. Copyright (C) 2018 by the Institute of
  175. Electrical and Electronics Engineers, Inc and The Open Group.
  176. In the event of any discrepancy between this version and the original IEEE and
  177. The Open Group Standard, the original IEEE and The Open Group Standard
  178. is the referee document. The original Standard can be obtained online at
  179. http://www.opengroup.org/unix/online.html .
  180. .PP
  181. Any typographical or formatting errors that appear
  182. in this page are most likely
  183. to have been introduced during the conversion of the source files to
  184. man page format. To report such errors, see
  185. https://www.kernel.org/doc/man-pages/reporting_bugs.html .