in effetti c'è...solo che è in asm...ok usiamo quello che è + performante :sexpulp:
---
mi da segfault quando faccio il free di tmpbuffercodice:#include <gcrypt.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #define TMPBUFFER_SIZE 1024 int main(int argc, char **argv) { FILE *fd; struct stat file_info; char * buffer; char * tmpbuffer; int res, count=0; // Controllo i parametri passati if (argc < 2) { fprintf(stderr, "Usage: %s <file>\n", *argv); return 1; } // Leggo le informazioni sul file res = stat(argv[1], &file_info); if(res < 0) { fprintf(stderr, "Unable to stat file %s\n", argv[1]); return 1; } // Apro il file fd = fopen(argv[1], "r"); if (fd == NULL) { fprintf(stderr, "Couldn't open file!\n"); return 1; } // Imposto il buffer per il file buffer = malloc(file_info.st_size+1); if (buffer == NULL) { fprintf(stderr, "No memory avaiable!\n"); return 1; } // Imposto il buffer per i blocchi di memoria temporanea tmpbuffer = malloc(TMPBUFFER_SIZE+1); if (tmpbuffer == NULL) { fprintf(stderr, "No memory avaiable!\n"); free(buffer); return 1; } while((res=fread(tmpbuffer, sizeof(char), TMPBUFFER_SIZE, fd)) > 0) { /* while(*tmpbuffer) { *buffer = *tmpbuffer; buffer++; tmpbuffer++; } count += res; */ strcat(buffer, tmpbuffer); } free(tmpbuffer); printf("START\n%s\nEND\n", buffer); fclose(fd); // Elimino i buffer di memoria printf("1\n"); free (buffer); printf("1\n"); }
che faccio?![]()


Rispondi quotando