AltraMayor / f3

F3 - Fight Flash Fraud
https://fight-flash-fraud.readthedocs.io/en/stable/
GNU General Public License v3.0
2.4k stars 137 forks source link

Portable argument parsing #130

Open MartinHusemann opened 4 years ago

MartinHusemann commented 4 years ago

Would a pull request that replaces the glibc specific argp functions with plain posix functions be accepted?

Alternatively, a pull request that #ifdefs them and provides alternatives for systems not implementing them (so Linux would use argp, but others getopt/strtol and what have you)?

The former would be a lot cleaner and not obfuscate the code as much.

AltraMayor commented 4 years ago

Which systems are you concerned about? Is argp the only issue to port F3 to these systems?

If we decide to go down this route, would there be any change in the way the parameters are used?

MartinHusemann commented 4 years ago

I am using NetBSD and did not do a full port yet as I was trying to find out whats the minimal change and argp kills compilation right away. NetBSD should be close enough to FreeBSD and libusb is supported, so I don't expect many other obstacles.

Completly replacing argp basically means moving the code inside the parse_opt() callback into the caller of argp_parse(), which is replaced by a loop around getopt(3) or getopt_long(3).

AltraMayor commented 4 years ago

Are you trying to port only f3write and f3read? Or are you planning to port the other tools (e.g. f3probe)? I'm asking because f3write and f3read do not use libusb. The other tools are more demanding to port.

MartinHusemann commented 4 years ago

Yeah, I'm aware the former two are easy and the others harder - was going to see how far I get, but definitively want to try f3probe too.

AltraMayor commented 4 years ago

If you want, we can try a pull request to patch only f3write and f3read. Thus, we leave the other tools for when you have a chance to get them working. This should also simplify the review of this first pull request. If you are going to write this pull request, please remember to update the documentation as needed.

ghost commented 4 years ago

I'm also interested in this. On FreeBSD f3probe is not installed, but f3write and f3read are. It looks like f3probe uses linux/fs.h which is why.

VA1DER commented 1 year ago

I want to use this on armv7l and aarch64 systems using MUSL as the libc. This is really hard when you use glibc-isms. Please progress this issue.

yetanothergeek commented 1 year ago

I was able to cross-compile on x86_64-GNU for i486-musl by using this library:

https://github.com/ericonr/argp-standalone

It was a little tricky getting the library built and installed; the autotools didn't work for me so I just ran the commands manually but it's not too complicated and it worked. I can post more details if you need them.

VA1DER commented 1 year ago

I was able to use libuargp - that said, it is still really inconvenient. Using non-standard extensions only found in one implementation of a library is never a good idea.