Merge branch 'master' of ssh://Aleaxander@repo.or.cz/srv/git/fstk
[fstk.git] / cat.c
blobdeed02a85eb06fd62b4fbe73895d4192b683b287
1 /*
2 * Simple cat implemention.
4 * Copyright (C) 2009 Liu Aleaxander -- All rights reserved. This file
5 * may be redistributed under the terms of the GNU Public License.
6 */
8 #include <stdio.h>
9 #include <string.h>
10 #include "fstk.h"
11 #include "fstklib.h"
12 #include "file.h"
13 #include <unistd.h>
15 void fstk_cat(struct fstk *fs, int argc, char *argv[])
17 char buf[2048] = {0,};
18 int bytes_read;
19 int i = 1;
20 struct file *file;
22 for (; i < argc; i++) {
23 file = fstk_open(fs, argv[i]);
24 if (!file) {
25 printf("cat: can't access %s: "
26 "No such file or directory\n", argv[i]);
27 continue;
29 if (file->inode->mode == DIR_TYPE) {
30 printf("cat: %s: is a directory\n", argv[i]);
31 fstk_close(file);
32 continue;
35 while ((bytes_read = fstk_read(file, buf, 2048)) >= 0) {
36 write(1, buf, bytes_read);
38 printf("\n");
39 fstk_close(file);