How to implement crypt() and wordexp.h in Android Posix

197 Views Asked by At

I know that these 2 functionalities are not provided by Bionics libc implementation. I do need these for a C++ to Android port. How can I solve this problem? I dont know where to start here.

I get these error messages:

error: unknown type name 'wordexp_t' error: use of undeclared identifier 'crypt'

Any ideas?

1

There are 1 best solutions below

0
On

A full BSD UNIX does provide that type and that function. However, there are good reasons why they aren't provided on Android.

wordexp_t is for shell-style word expansions.

crypt() is for UNIX password encryption. This is not any kind of general-purpose encryption; it is for taking an entered password, creating a hash (because that's what this kind of encryption does) and then seeing if the resulting string matches the user's password hash in the UNIX password file.

Android, of course, does not have a user login system, nor does it have a command line (unless you add one, or use ADB, neither of which is normal for Android app users).

So the uses of this type and this call are in code within your library that is not relevant to Android. Discoveries like this are commonplace when you port software to a very different platform.

Solving this problem properly requires finding out and understanding what the missing type and function are being used for in your source code. When you understand their purpose, you'll be able to figure out if they are needed on Android, in which case they'll need to be replaced with something else.

Then you need to revise the source of the library so that it uses them on the platforms where they exist, and something else gets used on Android. It's generally best to refactor the code, so that (for example), you end up with a source file that contains platform-specific code for word expansion, and another one with platform-specific code for password access.

The good news is that this structure will serve you well if and when you need to port the same code to iOS.