Statistiques
| Branche: | Révision :

root / cat.c @ 132932cd7f245a2592cf4c99d1a64a50febadf01

Historique | Voir | Annoter | Télécharger (1005 octet)

1
/*
2
 * Copyright (c) 2005 by Romuald DELAVERGNE
3
 * It can be redistributed under the terms of the GNU General Public License.
4
*/
5
#include <stdlib.h>
6
#include <stdio.h>
7
#include <fcntl.h>
8
#include <io.h>
9
#include <dir.h>
10
11
void
12
exitOnError(char *msg) {
13
        perror(msg);
14
        exit(1);
15
}
16
17
int
18
main(int argc, char *argv[]) {
19
        void *buf;
20
        int handle, n, done;
21
        struct ffblk ffblk;
22
        char *prog = argv[0];
23
24
        buf = malloc(BUFSIZ);
25
26
        if (argc == 1) {
27
                printf("%s: too few parameters !\n", prog);
28
                printf("concatenate files and print on the standard output\n");
29
                printf("usage: %s FILE [FILE...]\n", prog);
30
                exit(0);
31
        }
32
33
        while (--argc > 0) {
34
                done = findfirst(*++argv, &ffblk, 0);
35
                while (!done) {
36
                        if ((handle = _open(ffblk.ff_name, O_RDONLY|O_BINARY)) == -1) exitOnError(prog);
37
                        while (!eof(handle))
38
                                if ((n = _read(handle, buf, BUFSIZ)) == -1 || _write(1, buf, n) == -1)
39
                                        exitOnError(prog);
40
                        _close(handle);
41
                        done = findnext(&ffblk);
42
                }
43
        }
44
        return 0;
45
}