// files.c # include "alfa.h" // Aggiunta di un testo // al file di nome A che // deve gia' esistere. void Aggiungifile (Char A, Char Testo) {int fk; fk=open(A,O_WRONLY|O_APPEND); write(fk,Testo,strlen(Testo)); close(fk);} // Lettura del file di nome A // nell'indirizzo B. void Leggifile (Char A, Char B) {int fk; int n; fk=open(A,O_RDONLY); if (fk<0) {*B=0; return;} n=Lunghezzafile(A); read(fk,B,n); close(fk); B[n]=0;} // Scrittura di un testo // nel file di nome A. void Scrivifile (Char A, Char Testo) {int fk; fk=open(A,O_WRONLY|O_CREAT| O_TRUNC|O_SYNC,S_IRUSR| S_IWUSR|S_IRGRP|S_IROTH); write(fk,Testo,strlen(Testo)); close(fk);} // Lunghezza del file di nome A. // Il risultato e' -1, se il file non // esiste o non e' un file regolare. int Lunghezzafile (Char A) {struct stat att; int e; e=stat(A,&att); if (e<0) return -1; if (att.st_mode && S_IFREG) return att.st_size; return -1;}