gcht101hello/code20240722a.html 20240722
Sorce Code:MKCP205lsc
hello

// MKCP205lsc   20240722
// description: ls command, using system call on LINUX
// board: Milk-V DUO 256MB 
// MPU:RISC-V CPU 1 x C906@1GHz + 1 x C906@700MHz
// SD card: DUOV1.1.1.img 
// os  cat /etc/os-release NAME=Buildroot VERSION=20240528-2053
// device: 
// language: C, cross compile riscv64-unknown-linux-musl-gcc 
// IDE: VScode using wsl ubuntu on windows11
// duo-example/MKCP205ls
//    | makefile
//    | lsc.c 
//$ cd duo-examples
//$ source envsetup.sh  >> SDK environment is read
//$ cd MKCP205lsc
//$ make
//--------------------------------------  
// target folder mkdir MKCP205lsc
//               mkdir MKCP205lsc/text  
//$ scp -O lsc root@192.168.42.1:/root/MKCP205lsc
//$ ssh root@192.168.42.1 
//# cd MKCP205lsc
//# ./lsc text
//# result
//# 41592 ..
//# 41595 text.txt
//# 41594 .
//---------------------------------------------
#include< stdio.h >
#include< stdlib.h >
#include< sys/types.h >
#include< dirent.h >

void doLs(char *path);
int main(int argc, char *argv[]){
    if (argc < 2) {
        fprintf(stderr, "%s: no arguments\n", argv[0]);
        exit(1);
    }
    for (int i = 1; i < argc; i++) doLs(argv[i]);
}
//--------------------------------------------------
void doLs(char *path){
    struct dirent *entry;  
    // ino_t          d_ino;       /* inode*/
    // off_t          d_off;       /*  */
    // unsigned short d_reclen;    /* record length */
    // unsigned char  d_type;      /* file type */
    // char           d_name[256]; /* file name*/
    
    DIR *dir = opendir(path);  /* Open the directory */
    while (entry = readdir(dir)) {  /* read directory */
        printf("%ld %s\n",entry->d_ino, entry->d_name);
    }
    closedir(dir);         /* Close the directory stream */
}