cours/C primitive open.md
oscar.plaisant@icloud.com a2ee0fa5ca from github to this gitea
2023-10-23 23:09:51 +02:00

29 lines
754 B
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
alias: [ "open()", "open" ]
---
up:: [[C primitives système]]
title:: "ouvrir (éventuellement créer) un fichier"
#informatique
---
```C
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);
```
Soit `pathname` le nom du fichier à ouvrir, `open` renvoie le [[file descriptor]] qui correspond au fichier (un `int`).
- `open` créée une nouvelle description
- Le paramètre `flags` doit inclure l'un des _mode d'accès_ suivants :
- `O_RDONLY` : ouverture en lecture seule
- `O_WRONLY` : ouverture en écriture seule
- `O_RDWR` : ouverture en lecture-écriture