Ejemplo uso de llamadas al sistema para modificar el sistema de archivos

De Wiki de Sistemas Operativos
Saltar a: navegación, buscar

<syntax lang="c">

  1. include <stdio.h>
  2. include <stdlib.h>
  3. include <string.h>
  4. include <sys/types.h>
  5. include <sys/stat.h>
  6. include <fcntl.h>

int main(void) { char buf[1024] = {}; int fd, numbytes;

fd = open("fichero.txt", O_RDONLY); if (fd < 0) { perror("open"); exit(EXIT_FAILURE); }

numbytes = read(fd, buf, sizeof(buf)); while (numbytes > 0) { write(1, buf, strlen(buf)); numbytes = read(fd, buf, sizeof(buf)); }

close(fd); mkdir("prueba", 0755);

exit(EXIT_SUCCESS); } </syntax>