1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:17:46 +00:00

Base: Write some initial man pages

It ain't much, but it's honest work!
This commit is contained in:
Sergey Bugaev 2019-09-21 00:47:00 +03:00 committed by Andreas Kling
parent 36eea6c04b
commit fed96f455d
8 changed files with 256 additions and 0 deletions

View file

@ -0,0 +1,24 @@
## Name
access - check if a file is accessible
## Synopsis
```**c++
#include <unistd.h>
int access(const char* path, int mode);
```
## Description
Check if a file at the given *path* exists and is accessible to the current user for the given *mode*.
Valid flags for *mode* are:
* `F_OK` to check if the file is accessible at all,
* `R_OK` to check if the file can be read,
* `W_OK` to check if the file can be written to,
* `X_OK` to check if the file can be executed as a program.
## Return value
If the file is indeed accessible for the specified *mode*, `access()` returns 0. Otherwise, it returns -1 and sets `errno` to describe the error.

View file

@ -0,0 +1,20 @@
## Name
mkdir - create a directory
## Synopsis
```**c++
#include <sys/stat.h>
int mkdir(const char* path, mode_t mode);
```
## Description
Create a new empty directory at the given *path* using the given *mode*.
## Return value
If the directory was created successfully, `mkdir()` returns 0. Otherwise,
it returns -1 and sets `errno` to describe the error.

View file

@ -0,0 +1,66 @@
## Name
pipe, pipe2 - create a pipe
## Synposis
```**c++
#include <unistd.h>
int pipe(int pipefd[2]);
int pipe2(int pipefd[2], int flags);
```
## Description
`pipe()` creates a new pipe, an anonymous FIFO channel. It returns two new file descriptors in `pipefd`.
Any data written to the `pipefd[1]` can then be read from `pipefd[0]`. When `pipefd[1]` is closed, reads
from `pipefd[0]` will return EOF.
`pipe2()` behaves the same as `pipe()`, but it additionally accepts the following *flags*:
* `O_CLOEXEC`: Automatically close the file descriptors created by this call, as if by `close()` call, when performing an `exec()`.
## Examples
The following program creates a pipe, then forks, the child then
writes some data to the pipe which the parent reads:
```c++
#include <AK/Assertions.h>
#include <stdio.h>
#incldue <unistd.h>
int main()
{
// Create the pipe.
int pipefd[2];
int rc = pipe(pipefd);
ASSERT(rc == 0);
pid_t pid = fork();
ASSERT(pid >= 0);
if (pid == 0) {
// Close the reading end of the pipe.
close(pipefd[0]);
// Write a message to the writing end of the pipe.
static const char greeting[] = "Hello friends!";
int nwritten = write(pipefd[1], greeting, sizeof(greeting));
ASSERT(nwritten == sizeof(greeting));
exit(0);
} else {
// Close the writing end of the pipe.
// If we don't do this, we'll never
// get an EOF.
close(pipefd[1]);
// Read the message from the reading end of the pipe.
char buffer[100];
int nread = read(pipefd[0], buffer, sizeof(buffer));
ASSERT(nread > 0);
// Try to read again. We should get an EOF this time.
nread = read(pipefd[0], buffer + nread, sizeof(buffer) - nread);
ASSERT(nread == 0);
}
}
```