Changeset 608 for trunk/user/ksh


Ignore:
Timestamp:
Dec 3, 2018, 12:24:13 PM (5 years ago)
Author:
alain
Message:

Introduce cat, rm, cp commands in ksh.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/ksh/ksh.c

    r596 r608  
    5656#define MAIN_DEBUG          0
    5757#define CMD_LOAD_DEBUG      0
    58 #define CMD_CAT_DEBUG       1
     58#define CMD_CAT_DEBUG       0
    5959
    6060//////////////////////////////////////////////////////////////////////////////////////////
     
    226226        int    size;          // source file size
    227227        int    bytes;         // number of transfered bytes
    228         char   buf[1024];
     228        char   buf[4096];
    229229        stat_t st;
    230230
     
    293293        while (bytes < size)
    294294        {
    295                 int rlen = ((size - bytes) < 1024) ? (size - bytes) : 1024;
    296                 int wlen;
    297                 int ret;
     295                int len = ((size - bytes) < 4096) ? (size - bytes) : 4096;
    298296
    299297                // read the source
    300                 ret = read( src_fd , buf , rlen );
    301                 if (ret == -1)
     298                if ( read( src_fd , buf , len ) != len )
    302299        {
    303300                        printf("  error: cannot read from file %s\n", srcpath);
     
    305302                }
    306303
    307                 rlen = (int)ret;
    308 
    309304                // write to the destination
    310                 ret = write( dst_fd , buf , rlen );
    311                 if (ret == -1)
     305                if ( write( dst_fd , buf , len ) != len )
    312306        {
    313307                        printf("  error: cannot write to file %s\n", dstpath);
     
    315309                }
    316310
    317                 wlen = (int)ret;
    318 
    319                 // check
    320                 if (wlen != rlen)
    321         {
    322                         printf("  error: cannot write on device\n");
    323                         goto exit;
    324                 }
    325 
    326                 bytes += rlen;
     311                bytes += len;
    327312        }
    328313
     
    848833            pathname = argv[1];
    849834
    850         printf("  error: not implemented yet\n");
     835        if ( unlink( pathname ) )
     836        {
     837                    printf("  error: unable to remove %s\n", pathname );
     838            }
    851839    }
    852840
Note: See TracChangeset for help on using the changeset viewer.