I need to "emulate" the pg_dump code because the password prompt. Years ago I write a program (for the QnX environment) that catched some prompt and emulates the standard input. I don't like to do that again.
pg_dump can use an environment variable "PGPASSWORD" upon execution (actually, all libpq programs can). You could have a wrapper that sets the environment variable and then executes pg_dump, this would get you around that prompt. Similarly, you could use the .pgpass file.
Sorry, I was not exact. I don't need nor like to change pg_dump. Rather, based on pg_dump code, I need to develop a daemon which can receive a TCP message (from a privileged app) containing some elements: the database to dump, the user under which do that, and his password. (My apps are using that same data, of course, encripted to the common users).
I would just fork pg_dump to do the actual dump rather than try and incorporate its source code into your app.