123456789101112131415161718192021222324252627282930 |
- #include <malloc.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- int main(int argc, char **argv)
- {
- /* Apre il file con il nome con cui e' stato invocato questo programma */
- int f = open(argv[0], O_RDONLY);
- struct stat s;
- int *buf;
- if (f == -1) {
- fprintf(stderr, "Errore apertura file\n");
- return 1;
- }
- if (fstat(f, &s) == -1) {
- fprintf(stderr, "Errore fstat\n");
- return 2;
- }
- if (!(buf = malloc(s.st_size))) {
- fprintf(stderr, "Errore malloc\n");
- return 3;
- }
- read(f, buf, s.st_size);
- free(buf);
- close(f);
- return 0;
- }
|