0

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);
}
NoNoob
  • 63
  • 9

1 Answers1

2

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).

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • So i need to compile it to .obj first ?? And then what?Please help – NoNoob Feb 21 '18 at 17:05
  • No, to an executable, not just an object file – Gabe Sechan Feb 21 '18 at 17:06
  • Ok,But then how to make that .exe file run in terminal emulator? – NoNoob Feb 21 '18 at 17:08
  • Windows uses .exe files. Linux uses elf format executables. Making it an exe won't help. As for running it- same way you would any other Linux executable. Chmod it to executable, then you can invoke it from the command line – Gabe Sechan Feb 21 '18 at 17:27
  • 1
    Here it is as step by step. https://stackoverflow.com/questions/35231168/how-to-build-an-executable-for-android-shell – NoNoob Feb 21 '18 at 17:36