I want to write my own ls command,so that i could safely parse it.
I have written the following code in c. But how to make this .c file run in terminal emulator for android.? Do i need to simply put it in /system/bin directory?
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main(int argc, char* argv[])
{
DIR *mydir;
struct dirent *myfile;
struct stat mystat;
char buf[512];
mydir = opendir(argv[1]);
while((myfile = readdir(mydir)) != NULL)
{
sprintf(buf, "%s/%s", argv[1], myfile->d_name);
stat(buf, &mystat);
printf("%zu",mystat.st_size);
printf(" %s\n", myfile->d_name);
}
closedir(mydir);
}
No. Why would you think that would work? C is a compiled language, not interpreted. You'd need to compile it for ARM linux first. (I'm assuming ARM, as most devices are- your mileage may vary, and you may need to compile for the correct version of ARM).