-
Notifications
You must be signed in to change notification settings - Fork 0
/
mi_escribir.c
43 lines (33 loc) · 926 Bytes
/
mi_escribir.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Autores:
- Marc Link Cladera
- Carlos Gálvez Mena
- Jesús Castillo Benito
*/
#include "directorios.h"
int main(int argc, char **args)
{
if (argc != 5)
{
fprintf(
stderr,
RED
"ERROR: invalid syntax. Usage: ./mi_escribir <disco> </ruta_fichero>"
"<texto> <offset>\n"
RESET
);
return FALLO;
}
// Mount the device.
if (bmount(args[1]) < 0) return FALLO;
unsigned int offset = (unsigned int) atoi(args[4]);
unsigned int nbytes = (unsigned int) strlen(args[3]);
printf("Text length: %d\n", nbytes);
char buffer[nbytes + 1];
strcpy(buffer, args[3]);
int writen_bytes;
if ((writen_bytes = mi_write(args[2], buffer, offset, nbytes)) == FALLO) return FALLO;
printf("Writen bytes: %d\n", writen_bytes);
if (bumount() < 0) return FALLO;
return 0;
}