Diferencia entre revisiones de «Ejemplo uso de llamadas al sistema para modificar el sistema de archivos»
De Wiki de Sistemas Operativos
Línea 1: | Línea 1: | ||
− | < | + | <syntaxhighlight lang="c"> |
#include <stdio.h> | #include <stdio.h> | ||
#include <stdlib.h> | #include <stdlib.h> | ||
Línea 29: | Línea 29: | ||
exit(EXIT_SUCCESS); | exit(EXIT_SUCCESS); | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
Revisión actual del 16:07 11 oct 2019
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#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);
}