This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
os_cp:prog_filebasics_signals [2024/05/08 14:26] jkonczak [Reading & writing data] |
os_cp:prog_filebasics_signals [2025/05/14 18:20] (current) jkonczak |
||
---|---|---|---|
Line 6: | Line 6: | ||
source level. | source level. | ||
- | POSIX [[https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/contents.html|specifies]] | + | POSIX [[https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/contents.html|specifies]] |
what should be present in the [[https://en.cppreference.com/w/c/header|C standard libraries]] | what should be present in the [[https://en.cppreference.com/w/c/header|C standard libraries]] | ||
(e.g., ''stdio.h'' or ''stdlib.h''), and also specifies user-level API to the | (e.g., ''stdio.h'' or ''stdlib.h''), and also specifies user-level API to the | ||
Line 17: | Line 17: | ||
a number of basic constants and functions for interfacing the operating system. | a number of basic constants and functions for interfacing the operating system. | ||
\\ | \\ | ||
- | The ''[[https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html|fcntl.h]]'' | + | The ''[[https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fcntl.h.html|fcntl.h]]'' |
library defines constants and functions for __f__ile __c__o__nt__ro__l__. | library defines constants and functions for __f__ile __c__o__nt__ro__l__. | ||
==== Data types ==== | ==== Data types ==== | ||
- | POSIX [[https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html|defines]] | + | POSIX [[https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html|defines]] |
certain data types that are usually fancy names for certain integer types. | certain data types that are usually fancy names for certain integer types. | ||
Line 52: | Line 52: | ||
<small> | <small> | ||
All standard values of ''errno'' are documented | All standard values of ''errno'' are documented | ||
- | [[https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html|here]]. | + | [[https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/errno.h.html|here]]. |
</small> | </small> | ||
Line 60: | Line 60: | ||
* ''strerror_r'' that requires the programmer to provide a buffer for the message,<html> | * ''strerror_r'' that requires the programmer to provide a buffer for the message,<html> | ||
</html> and ''strerror_l'' that allows to specify locale(=language); both are <html> | </html> and ''strerror_l'' that allows to specify locale(=language); both are <html> | ||
- | </html> defined by [[https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html|POSIX]] <html> | + | </html> defined by [[https://pubs.opengroup.org/onlinepubs/9799919799/functions/strerror.html|POSIX]] <html> |
</html> and are thread-safe, | </html> and are thread-safe, | ||
* ''void perror(const char *//str//)'' a [[https://en.cppreference.com/w/c/io/perror|C standard]] <html> | * ''void perror(const char *//str//)'' a [[https://en.cppreference.com/w/c/io/perror|C standard]] <html> | ||
Line 93: | Line 93: | ||
To read or write data, POSIX defines: \\ | To read or write data, POSIX defines: \\ | ||
<html><span style="float:right"><small>Needs header:<br><code>unistd.h</code></small></span> | <html><span style="float:right"><small>Needs header:<br><code>unistd.h</code></small></span> | ||
- | <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html"></html> | + | <a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/read.html"></html> |
''ssize_t **read** (int //fildes//, void *//buf//, size_t //nbyte//)'' | ''ssize_t **read** (int //fildes//, void *//buf//, size_t //nbyte//)'' | ||
<html></a></html> | <html></a></html> | ||
\\ | \\ | ||
- | <html><a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html"></html> | + | <html><a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/write.html"></html> |
''ssize_t **write**(int //fildes//, const void *//buf//, size_t //nbyte//)'' | ''ssize_t **write**(int //fildes//, const void *//buf//, size_t //nbyte//)'' | ||
<html></a></html> | <html></a></html> | ||
Line 127: | Line 127: | ||
Reading/writing advances the position in the file. | Reading/writing advances the position in the file. | ||
\\ | \\ | ||
- | In some files (this include ordinary files), one may change the position within the file with: | + | In some files (among others in ordinary files), one may change the position within the file with: |
\\ | \\ | ||
<html><span style="float:right"><small>Needs header: <code>unistd.h</code></small></span> | <html><span style="float:right"><small>Needs header: <code>unistd.h</code></small></span> | ||
- | <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html"></html> | + | <a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/write.html"></html> |
''off_t **lseek**(int //fd//, off_t //offset//, int //whence//)''; | ''off_t **lseek**(int //fd//, off_t //offset//, int //whence//)''; | ||
<html></a></html> | <html></a></html> | ||
Line 196: | Line 196: | ||
To create or open a file, POSIX defines: \\ | To create or open a file, POSIX defines: \\ | ||
<html><span style="float:right"><small>Needs header:<br><code>fcntl.h</code></small></span> | <html><span style="float:right"><small>Needs header:<br><code>fcntl.h</code></small></span> | ||
- | <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html"></html> | + | <a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/open.html"></html> |
''int **open**(const char *//pathname//, int //flags//)'' \\ | ''int **open**(const char *//pathname//, int //flags//)'' \\ | ||
''int **open**(const char *//pathname//, int //flags//, mode_t //mode//)'' | ''int **open**(const char *//pathname//, int //flags//, mode_t //mode//)'' | ||
<html></a></html>\\ | <html></a></html>\\ | ||
- | and a <html><a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/creat.html"></html>''creat''<html></a></html> | + | and a <html><a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/creat.html"></html>''creat''<html></a></html> |
function that is a shorthand to ''open(//pathname//, O_WRONLY|O_CREAT|O_TRUNC, //mode//)''. | function that is a shorthand to ''open(//pathname//, O_WRONLY|O_CREAT|O_TRUNC, //mode//)''. | ||
Line 235: | Line 235: | ||
\\ | \\ | ||
<html><span style="float:right"><small>Needs header:<code>unistd.h</code></small></span> | <html><span style="float:right"><small>Needs header:<code>unistd.h</code></small></span> | ||
- | <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html"></html> | + | <a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/close.html"></html> |
''int **close**(int //filedes//)'' | ''int **close**(int //filedes//)'' | ||
<html></a></html> | <html></a></html> | ||
Line 267: | Line 267: | ||
Disclaimer: these materials contain the very basics of signals. | Disclaimer: these materials contain the very basics of signals. | ||
For comprehensive informations, see the | For comprehensive informations, see the | ||
- | [[https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04|POSIX standard]]. | + | [[https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_04|POSIX standard]]. |
==== Sending signals ==== | ==== Sending signals ==== | ||
Line 273: | Line 273: | ||
To send a signal, one can use the function | To send a signal, one can use the function | ||
<html><span style="float:right"><small>Needs header: <code>signal.h</code></small></span> | <html><span style="float:right"><small>Needs header: <code>signal.h</code></small></span> | ||
- | <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html"></html> | + | <a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html"></html> |
''int **kill**(pid_t //pid//, int //sig//)'' | ''int **kill**(pid_t //pid//, int //sig//)'' | ||
<html></a></html> | <html></a></html> | ||
Line 357: | Line 357: | ||
\\ | \\ | ||
<html><span style="float:right"><small>Needs header: <code>signal.h</code></small></span> | <html><span style="float:right"><small>Needs header: <code>signal.h</code></small></span> | ||
- | <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html"></html> | + | <a href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/signal.html"></html> |
''void (*<nowiki></nowiki>**signal**(int //sig//, void (*//func//)(int)))(int)'' | ''void (*<nowiki></nowiki>**signal**(int //sig//, void (*//func//)(int)))(int)'' | ||
<html></a></html> | <html></a></html> | ||
Line 434: | Line 434: | ||
\\ | \\ | ||
[[https://man7.org/linux/man-pages/man7/signal-safety.7.html|Linux manual]] and | [[https://man7.org/linux/man-pages/man7/signal-safety.7.html|Linux manual]] and | ||
- | [[https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03|POSIX standard]] | + | [[https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_04_03_03|POSIX standard]] |
provide a list of async-signal-safe functions. | provide a list of async-signal-safe functions. | ||