source: trunk/kernel/ksh/cat.c @ 208

Last change on this file since 208 was 1, checked in by alain, 8 years ago

First import

File size: 1.6 KB
Line 
1/*
2        This file is part of MutekP.
3       
4        MutekP is free software; you can redistribute it and/or modify it
5        under the terms of the GNU General Public License as published by
6        the Free Software Foundation; either version 2 of the License, or
7        (at your option) any later version.
8       
9        MutekP is distributed in the hope that it will be useful, but
10        WITHOUT ANY WARRANTY; without even the implied warranty of
11        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12        General Public License for more details.
13       
14        You should have received a copy of the GNU General Public License
15        along with MutekP; if not, write to the Free Software Foundation,
16        Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17       
18        UPMC / LIP6 / SOC (c) 2008
19        Copyright Ghassan Almaless <ghassan.almaless@gmail.com>
20*/
21
22#include <stdint.h>
23#include <string.h>
24#include <sys-vfs.h>
25#include <kminiShell.h>
26 
27error_t cat_func(void *param)
28{
29#if 1
30        struct ku_obj ku_buff;
31        error_t err;
32        ssize_t size;
33        uint32_t argc;
34        uint32_t i;
35        struct vfs_file_s file;
36        ms_args_t *args;
37        uint_t count;
38
39        args  = (ms_args_t*) param;
40        argc = args->argc;
41        err = 0;
42       
43        for(i=1; i< argc; i++)
44        {
45               
46                KK_BUFF(ku_buff, args->argv[i]);
47                if((err=vfs_open(ms_n_cwd, &ku_buff,VFS_O_RDONLY,0, &file)))
48                        return err;
49               
50                KK_SZ_BUFF(ku_buff, buffer, BUFFER_SIZE);
51                while((size = vfs_read(&file, &ku_buff)) > 0)
52                { 
53                        ksh_write(buffer, size);
54                        //if((ch=getChar()) == 'q') break;
55                }
56               
57                err = vfs_close(&file, &count);
58         
59                if(err)
60                        printk(WARNING, "WARNING: %s: failed to close file at iteration %d, err %d\n", __FUNCTION__, i, err);
61
62               
63                if(size < 0) return size;
64        }
65
66        return 0;
67#else
68        return ENOSYS;
69#endif
70}
71
Note: See TracBrowser for help on using the repository browser.