cours/C primitive open.md
Oscar Plaisant 602a41e7f8 update
2024-12-25 22:30:24 +01:00

29 lines
756 B
Markdown
Raw Permalink 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"
#s/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