With basically all of the work with text encoding now being done in terms of 10646 / Unicode, "character set" isn't used much any more, except where it was standardized early, such as in MIME formats, html charset, and the C++ and C standards. Where the term "character set" is used today it tends to mean the subset of characters from 10646 that is in use, although repertoire is the official term of art, and encoding specifies the numerical values used for those characters.
auto loc = newlocale(LC_CTYPE_MASK, "", 0)
auto name = nl_langinfo_l(CODESET, loc);
at least on a modern-ish posix system I think would work for getting the environmentally requested encoding scheme. This is probably better than proposals to attempt to figure out what the output is expecting, which can be terribly complicated given pipes, tees. remote shells, X, and so on, at least in unix-y environments.
For literal encodings, we want to be able to recover the encoding scheme used for the translation unit, which often varies within a program. Which is also a source of errors, but is what it is. It's neither the CODESET of the "C" locale, nor of the "" locale. It would be nice to have a standard name for the thing, which is currently bundled into execution character set.